@@ -31,12 +31,15 @@ public class UsernameNotFoundException extends AuthenticationException {
31
31
@ Serial
32
32
private static final long serialVersionUID = 1410688585992297006L ;
33
33
34
+ private final String name ;
35
+
34
36
/**
35
37
* Constructs a <code>UsernameNotFoundException</code> with the specified message.
36
38
* @param msg the detail message.
37
39
*/
38
40
public UsernameNotFoundException (String msg ) {
39
41
super (msg );
42
+ this .name = null ;
40
43
}
41
44
42
45
/**
@@ -47,6 +50,42 @@ public UsernameNotFoundException(String msg) {
47
50
*/
48
51
public UsernameNotFoundException (String msg , Throwable cause ) {
49
52
super (msg , cause );
53
+ this .name = null ;
54
+ }
55
+
56
+ private UsernameNotFoundException (String msg , String name , Throwable cause ) {
57
+ super (msg , cause );
58
+ this .name = name ;
59
+ }
60
+
61
+ /**
62
+ * Construct an exception based on a specific username
63
+ * @param username the invalid username
64
+ * @return the {@link UsernameNotFoundException}
65
+ * @since 7.0
66
+ */
67
+ public static UsernameNotFoundException fromUsername (String username ) {
68
+ return fromUsername (username , null );
69
+ }
70
+
71
+ /**
72
+ * Construct an exception based on a specific username
73
+ * @param username the invalid username
74
+ * @param cause any underlying cause
75
+ * @return the {@link UsernameNotFoundException}
76
+ * @since 7.0
77
+ */
78
+ public static UsernameNotFoundException fromUsername (String username , Throwable cause ) {
79
+ return new UsernameNotFoundException ("user not found" , username , cause );
80
+ }
81
+
82
+ /**
83
+ * Get the username that couldn't be found
84
+ * @return the username
85
+ * @since 7.0
86
+ */
87
+ public String getName () {
88
+ return this .name ;
50
89
}
51
90
52
91
}
0 commit comments