Skip to content

Commit 5af5bba

Browse files
committed
Fix authRequest field to AuthenticationException via setter
Signed-off-by: amm0124 <amm0124@naver.com>
1 parent 872f77e commit 5af5bba

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.io.Serial;
2020

21+
import org.springframework.util.Assert;
22+
2123
/**
2224
* Abstract superclass for all exceptions related to an {@link Authentication} object
2325
* being invalid for whatever reason.
@@ -29,7 +31,15 @@ public abstract class AuthenticationException extends RuntimeException {
2931
@Serial
3032
private static final long serialVersionUID = 2018827803361503060L;
3133

32-
private final Authentication authRequest;
34+
/**
35+
* The {@link Authentication} object representing the failed authentication attempt.
36+
* <p>
37+
* This field captures the authentication request that was attempted but ultimately
38+
* failed, providing critical information for diagnosing the failure and facilitating
39+
* debugging. If set, the value must not be null.
40+
* </p>
41+
*/
42+
private Authentication authRequest;
3343

3444
/**
3545
* Constructs an {@code AuthenticationException} with the specified message and root
@@ -52,8 +62,29 @@ public AuthenticationException(String msg) {
5262
this.authRequest = null;
5363
}
5464

65+
/**
66+
* Constructs an {@code AuthenticationException} with the specified message and root
67+
* cause.
68+
* @param msg the detail message
69+
* @param authRequest details about the failed authentication request
70+
*/
5571
public AuthenticationException(String msg, Authentication authRequest) {
5672
super(msg);
73+
Assert.notNull(authRequest, "AuthRequest cannot be null");
74+
}
75+
76+
/**
77+
* Sets the {@link Authentication} object representing the failed authentication
78+
* attempt.
79+
* <p>
80+
* This method allows the injection of the authentication request that resulted in a
81+
* failure. The provided {@code authRequest} should not be null if set.
82+
* </p>
83+
* @param authRequest the authentication request associated with the failed
84+
* authentication attempt.
85+
*/
86+
public void setAuthRequest(Authentication authRequest) {
87+
Assert.notNull(authRequest, "AuthRequest cannot be null");
5788
this.authRequest = authRequest;
5889
}
5990

0 commit comments

Comments
 (0)