54
54
import org .springframework .beans .factory .config .BeanDefinition ;
55
55
import org .springframework .context .annotation .ClassPathScanningCandidateComponentProvider ;
56
56
import org .springframework .core .type .filter .AssignableTypeFilter ;
57
+ import org .springframework .security .access .AccessDeniedException ;
58
+ import org .springframework .security .access .AuthorizationServiceException ;
57
59
import org .springframework .security .access .intercept .RunAsUserToken ;
58
60
import org .springframework .security .authentication .AbstractAuthenticationToken ;
61
+ import org .springframework .security .authentication .AccountExpiredException ;
59
62
import org .springframework .security .authentication .AnonymousAuthenticationToken ;
63
+ import org .springframework .security .authentication .AuthenticationCredentialsNotFoundException ;
64
+ import org .springframework .security .authentication .AuthenticationServiceException ;
65
+ import org .springframework .security .authentication .BadCredentialsException ;
66
+ import org .springframework .security .authentication .CredentialsExpiredException ;
67
+ import org .springframework .security .authentication .DisabledException ;
68
+ import org .springframework .security .authentication .InsufficientAuthenticationException ;
69
+ import org .springframework .security .authentication .InternalAuthenticationServiceException ;
70
+ import org .springframework .security .authentication .LockedException ;
71
+ import org .springframework .security .authentication .ProviderNotFoundException ;
60
72
import org .springframework .security .authentication .RememberMeAuthenticationToken ;
61
73
import org .springframework .security .authentication .TestAuthentication ;
62
74
import org .springframework .security .authentication .TestingAuthenticationToken ;
63
75
import org .springframework .security .authentication .UsernamePasswordAuthenticationToken ;
64
76
import org .springframework .security .authentication .jaas .JaasAuthenticationToken ;
77
+ import org .springframework .security .authentication .ott .InvalidOneTimeTokenException ;
65
78
import org .springframework .security .authentication .ott .OneTimeTokenAuthenticationToken ;
79
+ import org .springframework .security .authentication .password .CompromisedPasswordException ;
66
80
import org .springframework .security .cas .authentication .CasAssertionAuthenticationToken ;
67
81
import org .springframework .security .cas .authentication .CasAuthenticationToken ;
68
82
import org .springframework .security .cas .authentication .CasServiceTicketAuthenticationToken ;
72
86
import org .springframework .security .core .session .ReactiveSessionInformation ;
73
87
import org .springframework .security .core .session .SessionInformation ;
74
88
import org .springframework .security .core .userdetails .UserDetails ;
89
+ import org .springframework .security .core .userdetails .UsernameNotFoundException ;
90
+ import org .springframework .security .ldap .ppolicy .PasswordPolicyErrorStatus ;
91
+ import org .springframework .security .ldap .ppolicy .PasswordPolicyException ;
75
92
import org .springframework .security .ldap .userdetails .LdapAuthority ;
93
+ import org .springframework .security .oauth2 .client .ClientAuthorizationException ;
94
+ import org .springframework .security .oauth2 .client .ClientAuthorizationRequiredException ;
76
95
import org .springframework .security .oauth2 .client .OAuth2AuthorizedClient ;
77
96
import org .springframework .security .oauth2 .client .authentication .OAuth2AuthenticationToken ;
78
97
import org .springframework .security .oauth2 .client .authentication .OAuth2AuthorizationCodeAuthenticationToken ;
88
107
import org .springframework .security .oauth2 .core .DefaultOAuth2AuthenticatedPrincipal ;
89
108
import org .springframework .security .oauth2 .core .OAuth2AccessToken ;
90
109
import org .springframework .security .oauth2 .core .OAuth2AuthenticatedPrincipal ;
110
+ import org .springframework .security .oauth2 .core .OAuth2AuthenticationException ;
111
+ import org .springframework .security .oauth2 .core .OAuth2AuthorizationException ;
91
112
import org .springframework .security .oauth2 .core .OAuth2DeviceCode ;
113
+ import org .springframework .security .oauth2 .core .OAuth2Error ;
92
114
import org .springframework .security .oauth2 .core .OAuth2RefreshToken ;
93
115
import org .springframework .security .oauth2 .core .OAuth2UserCode ;
94
116
import org .springframework .security .oauth2 .core .TestOAuth2AccessTokens ;
108
130
import org .springframework .security .oauth2 .core .user .DefaultOAuth2User ;
109
131
import org .springframework .security .oauth2 .core .user .OAuth2UserAuthority ;
110
132
import org .springframework .security .oauth2 .core .user .TestOAuth2Users ;
133
+ import org .springframework .security .oauth2 .jwt .BadJwtException ;
111
134
import org .springframework .security .oauth2 .jwt .Jwt ;
135
+ import org .springframework .security .oauth2 .jwt .JwtDecoderInitializationException ;
136
+ import org .springframework .security .oauth2 .jwt .JwtEncodingException ;
137
+ import org .springframework .security .oauth2 .jwt .JwtException ;
138
+ import org .springframework .security .oauth2 .jwt .JwtValidationException ;
112
139
import org .springframework .security .oauth2 .jwt .TestJwts ;
113
140
import org .springframework .security .oauth2 .server .resource .BearerTokenError ;
114
141
import org .springframework .security .oauth2 .server .resource .BearerTokenErrors ;
142
+ import org .springframework .security .oauth2 .server .resource .InvalidBearerTokenException ;
115
143
import org .springframework .security .oauth2 .server .resource .authentication .BearerTokenAuthentication ;
116
144
import org .springframework .security .oauth2 .server .resource .authentication .BearerTokenAuthenticationToken ;
117
145
import org .springframework .security .oauth2 .server .resource .authentication .JwtAuthenticationToken ;
146
+ import org .springframework .security .oauth2 .server .resource .introspection .BadOpaqueTokenException ;
118
147
import org .springframework .security .oauth2 .server .resource .introspection .OAuth2IntrospectionAuthenticatedPrincipal ;
148
+ import org .springframework .security .oauth2 .server .resource .introspection .OAuth2IntrospectionException ;
119
149
import org .springframework .security .saml2 .Saml2Exception ;
120
150
import org .springframework .security .saml2 .core .Saml2Error ;
121
151
import org .springframework .security .saml2 .provider .service .authentication .DefaultSaml2AuthenticatedPrincipal ;
138
168
import org .springframework .security .web .csrf .DefaultCsrfToken ;
139
169
import org .springframework .security .web .csrf .InvalidCsrfTokenException ;
140
170
import org .springframework .security .web .csrf .MissingCsrfTokenException ;
171
+ import org .springframework .security .web .firewall .RequestRejectedException ;
172
+ import org .springframework .security .web .server .firewall .ServerExchangeRejectedException ;
141
173
142
174
import static org .assertj .core .api .Assertions .assertThat ;
143
175
import static org .assertj .core .api .Assertions .fail ;
@@ -193,6 +225,12 @@ class SpringSecurityCoreVersionSerializableTests {
193
225
generatorByClassName .put (OidcUserAuthority .class ,
194
226
(r ) -> new OidcUserAuthority (TestOidcIdTokens .idToken ().build (),
195
227
new OidcUserInfo (Map .of ("claim" , "value" )), "claim" ));
228
+ generatorByClassName .put (OAuth2AuthenticationException .class ,
229
+ (r ) -> new OAuth2AuthenticationException (new OAuth2Error ("error" , "description" , "uri" ), "message" ,
230
+ new RuntimeException ()));
231
+ generatorByClassName .put (OAuth2AuthorizationException .class ,
232
+ (r ) -> new OAuth2AuthorizationException (new OAuth2Error ("error" , "description" , "uri" ), "message" ,
233
+ new RuntimeException ()));
196
234
197
235
// oauth2-client
198
236
ClientRegistration .Builder clientRegistrationBuilder = TestClientRegistrations .clientRegistration ();
@@ -231,6 +269,21 @@ class SpringSecurityCoreVersionSerializableTests {
231
269
return new DefaultOAuth2AuthenticatedPrincipal (principal .getName (), principal .getAttributes (),
232
270
(Collection <GrantedAuthority >) principal .getAuthorities ());
233
271
});
272
+ generatorByClassName .put (ClientAuthorizationException .class ,
273
+ (r ) -> new ClientAuthorizationException (new OAuth2Error ("error" , "description" , "uri" ), "id" , "message" ,
274
+ new RuntimeException ()));
275
+ generatorByClassName .put (ClientAuthorizationRequiredException .class ,
276
+ (r ) -> new ClientAuthorizationRequiredException ("id" ));
277
+
278
+ // oauth2-jose
279
+ generatorByClassName .put (BadJwtException .class , (r ) -> new BadJwtException ("token" , new RuntimeException ()));
280
+ generatorByClassName .put (JwtDecoderInitializationException .class ,
281
+ (r ) -> new JwtDecoderInitializationException ("message" , new RuntimeException ()));
282
+ generatorByClassName .put (JwtEncodingException .class ,
283
+ (r ) -> new JwtEncodingException ("message" , new RuntimeException ()));
284
+ generatorByClassName .put (JwtException .class , (r ) -> new JwtException ("message" , new RuntimeException ()));
285
+ generatorByClassName .put (JwtValidationException .class ,
286
+ (r ) -> new JwtValidationException ("message" , List .of (new OAuth2Error ("error" , "description" , "uri" ))));
234
287
235
288
// oauth2-jwt
236
289
generatorByClassName .put (Jwt .class , (r ) -> TestJwts .user ());
@@ -262,6 +315,12 @@ class SpringSecurityCoreVersionSerializableTests {
262
315
generatorByClassName .put (BearerTokenError .class , (r ) -> BearerTokenErrors .invalidToken ("invalid token" ));
263
316
generatorByClassName .put (OAuth2IntrospectionAuthenticatedPrincipal .class ,
264
317
(r ) -> TestOAuth2AuthenticatedPrincipals .active ());
318
+ generatorByClassName .put (InvalidBearerTokenException .class ,
319
+ (r ) -> new InvalidBearerTokenException ("description" , new RuntimeException ()));
320
+ generatorByClassName .put (BadOpaqueTokenException .class ,
321
+ (r ) -> new BadOpaqueTokenException ("message" , new RuntimeException ()));
322
+ generatorByClassName .put (OAuth2IntrospectionException .class ,
323
+ (r ) -> new OAuth2IntrospectionException ("message" , new RuntimeException ()));
265
324
266
325
// core
267
326
generatorByClassName .put (RunAsUserToken .class , (r ) -> {
@@ -287,7 +346,33 @@ class SpringSecurityCoreVersionSerializableTests {
287
346
});
288
347
generatorByClassName .put (OneTimeTokenAuthenticationToken .class ,
289
348
(r ) -> applyDetails (new OneTimeTokenAuthenticationToken ("username" , "token" )));
290
-
349
+ generatorByClassName .put (AccessDeniedException .class ,
350
+ (r ) -> new AccessDeniedException ("access denied" , new RuntimeException ()));
351
+ generatorByClassName .put (AuthorizationServiceException .class ,
352
+ (r ) -> new AuthorizationServiceException ("access denied" , new RuntimeException ()));
353
+ generatorByClassName .put (AccountExpiredException .class ,
354
+ (r ) -> new AccountExpiredException ("error" , new RuntimeException ()));
355
+ generatorByClassName .put (AuthenticationCredentialsNotFoundException .class ,
356
+ (r ) -> new AuthenticationCredentialsNotFoundException ("error" , new RuntimeException ()));
357
+ generatorByClassName .put (AuthenticationServiceException .class ,
358
+ (r ) -> new AuthenticationServiceException ("error" , new RuntimeException ()));
359
+ generatorByClassName .put (BadCredentialsException .class ,
360
+ (r ) -> new BadCredentialsException ("error" , new RuntimeException ()));
361
+ generatorByClassName .put (CredentialsExpiredException .class ,
362
+ (r ) -> new CredentialsExpiredException ("error" , new RuntimeException ()));
363
+ generatorByClassName .put (DisabledException .class ,
364
+ (r ) -> new DisabledException ("error" , new RuntimeException ()));
365
+ generatorByClassName .put (InsufficientAuthenticationException .class ,
366
+ (r ) -> new InsufficientAuthenticationException ("error" , new RuntimeException ()));
367
+ generatorByClassName .put (InternalAuthenticationServiceException .class ,
368
+ (r ) -> new InternalAuthenticationServiceException ("error" , new RuntimeException ()));
369
+ generatorByClassName .put (LockedException .class , (r ) -> new LockedException ("error" , new RuntimeException ()));
370
+ generatorByClassName .put (ProviderNotFoundException .class , (r ) -> new ProviderNotFoundException ("error" ));
371
+ generatorByClassName .put (InvalidOneTimeTokenException .class , (r ) -> new InvalidOneTimeTokenException ("error" ));
372
+ generatorByClassName .put (CompromisedPasswordException .class ,
373
+ (r ) -> new CompromisedPasswordException ("error" , new RuntimeException ()));
374
+ generatorByClassName .put (UsernameNotFoundException .class ,
375
+ (r ) -> new UsernameNotFoundException ("error" , new RuntimeException ()));
291
376
generatorByClassName .put (TestingAuthenticationToken .class ,
292
377
(r ) -> applyDetails (new TestingAuthenticationToken ("username" , "password" )));
293
378
@@ -312,6 +397,8 @@ class SpringSecurityCoreVersionSerializableTests {
312
397
// ldap
313
398
generatorByClassName .put (LdapAuthority .class ,
314
399
(r ) -> new LdapAuthority ("USER" , "username" , Map .of ("attribute" , List .of ("value1" , "value2" ))));
400
+ generatorByClassName .put (PasswordPolicyException .class ,
401
+ (r ) -> new PasswordPolicyException (PasswordPolicyErrorStatus .INSUFFICIENT_PASSWORD_QUALITY ));
315
402
316
403
// saml2-service-provider
317
404
generatorByClassName .put (Saml2AuthenticationException .class ,
@@ -358,7 +445,9 @@ class SpringSecurityCoreVersionSerializableTests {
358
445
generatorByClassName .put (org .springframework .security .web .server .csrf .DefaultCsrfToken .class ,
359
446
(r ) -> new org .springframework .security .web .server .csrf .DefaultCsrfToken ("header" , "parameter" ,
360
447
"token" ));
361
-
448
+ generatorByClassName .put (RequestRejectedException .class , (r ) -> new RequestRejectedException ("message" ));
449
+ generatorByClassName .put (ServerExchangeRejectedException .class ,
450
+ (r ) -> new ServerExchangeRejectedException ("message" ));
362
451
}
363
452
364
453
@ ParameterizedTest
0 commit comments