Skip to content

Commit 3ecbe0f

Browse files
amm0124jzheaux
authored andcommitted
Add authRequest field to AuthenticationException
Store the authentication request details in the `authRequest` field of `AuthenticationException` when an authentication exception occurs. Closes gh-16444 Signed-off-by: amm0124 <amm0124@naver.com>
1 parent d3332e1 commit 3ecbe0f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

core/src/main/java/org/springframework/security/core/AuthenticationException.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.security.core;
1818

19+
import java.io.Serial;
20+
1921
/**
2022
* Abstract superclass for all exceptions related to an {@link Authentication} object
2123
* being invalid for whatever reason.
@@ -24,6 +26,11 @@
2426
*/
2527
public abstract class AuthenticationException extends RuntimeException {
2628

29+
@Serial
30+
private static final long serialVersionUID = 2018827803361503060L;
31+
32+
private final Authentication authRequest;
33+
2734
/**
2835
* Constructs an {@code AuthenticationException} with the specified message and root
2936
* cause.
@@ -32,6 +39,7 @@ public abstract class AuthenticationException extends RuntimeException {
3239
*/
3340
public AuthenticationException(String msg, Throwable cause) {
3441
super(msg, cause);
42+
this.authRequest = null;
3543
}
3644

3745
/**
@@ -41,6 +49,12 @@ public AuthenticationException(String msg, Throwable cause) {
4149
*/
4250
public AuthenticationException(String msg) {
4351
super(msg);
52+
this.authRequest = null;
53+
}
54+
55+
public AuthenticationException(String msg, Authentication authRequest) {
56+
super(msg);
57+
this.authRequest = authRequest;
4458
}
4559

4660
}

0 commit comments

Comments
 (0)