@@ -107,8 +107,7 @@ public void publishAuthenticationSuccess(Authentication authentication) {
107
107
108
108
public void publishAuthenticationFailure (AuthenticationException exception ,
109
109
Authentication authentication ) {
110
- Constructor <? extends AbstractAuthenticationEvent > constructor = exceptionMappings
111
- .get (exception .getClass ().getName ());
110
+ Constructor <? extends AbstractAuthenticationEvent > constructor = getEventConstructor (exception );
112
111
AbstractAuthenticationEvent event = null ;
113
112
114
113
if (constructor != null ) {
@@ -118,13 +117,6 @@ public void publishAuthenticationFailure(AuthenticationException exception,
118
117
catch (IllegalAccessException | InvocationTargetException | InstantiationException ignored ) {
119
118
}
120
119
}
121
- else if (defaultAuthenticationFailureEventConstructor != null ) {
122
- try {
123
- event = defaultAuthenticationFailureEventConstructor .newInstance (authentication , exception );
124
- }
125
- catch (IllegalAccessException | InvocationTargetException | InstantiationException ignored ) {
126
- }
127
- }
128
120
129
121
if (event != null ) {
130
122
if (applicationEventPublisher != null ) {
@@ -139,6 +131,12 @@ else if (defaultAuthenticationFailureEventConstructor != null) {
139
131
}
140
132
}
141
133
134
+ private Constructor <? extends AbstractAuthenticationEvent > getEventConstructor (AuthenticationException exception ) {
135
+ Constructor <? extends AbstractAuthenticationEvent > eventConstructor =
136
+ this .exceptionMappings .get (exception .getClass ().getName ());
137
+ return (eventConstructor == null ? this .defaultAuthenticationFailureEventConstructor : eventConstructor );
138
+ }
139
+
142
140
public void setApplicationEventPublisher (
143
141
ApplicationEventPublisher applicationEventPublisher ) {
144
142
this .applicationEventPublisher = applicationEventPublisher ;
@@ -181,7 +179,7 @@ public void setAdditionalExceptionMappings(Properties additionalExceptionMapping
181
179
public void setDefaultAuthenticationFailureEvent (
182
180
Class <? extends AbstractAuthenticationFailureEvent > defaultAuthenticationFailureEventClass ) {
183
181
Assert .notNull (defaultAuthenticationFailureEventClass ,
184
- "The defaultAuthenticationFailureEventClass must not be null" );
182
+ "defaultAuthenticationFailureEventClass must not be null" );
185
183
try {
186
184
this .defaultAuthenticationFailureEventConstructor = defaultAuthenticationFailureEventClass
187
185
.getConstructor (Authentication .class , AuthenticationException .class );
0 commit comments