16
16
17
17
package org .springframework .security .config .annotation .web .configurers .oauth2 .client ;
18
18
19
+ import com .nimbusds .jose .JOSEObjectType ;
20
+ import com .nimbusds .jose .proc .DefaultJOSEObjectTypeVerifier ;
21
+ import com .nimbusds .jose .proc .JOSEObjectTypeVerifier ;
22
+ import com .nimbusds .jose .proc .SecurityContext ;
23
+
19
24
import org .springframework .security .authentication .AuthenticationProvider ;
20
25
import org .springframework .security .authentication .AuthenticationServiceException ;
21
26
import org .springframework .security .core .Authentication ;
30
35
import org .springframework .security .oauth2 .jwt .Jwt ;
31
36
import org .springframework .security .oauth2 .jwt .JwtDecoder ;
32
37
import org .springframework .security .oauth2 .jwt .JwtDecoderFactory ;
38
+ import org .springframework .security .oauth2 .jwt .NimbusJwtDecoder ;
33
39
import org .springframework .util .Assert ;
40
+ import org .springframework .util .StringUtils ;
34
41
35
42
/**
36
43
* An {@link AuthenticationProvider} that authenticates an OIDC Logout Token; namely
@@ -56,9 +63,26 @@ final class OidcBackChannelLogoutAuthenticationProvider implements Authenticatio
56
63
* Construct an {@link OidcBackChannelLogoutAuthenticationProvider}
57
64
*/
58
65
OidcBackChannelLogoutAuthenticationProvider () {
59
- OidcIdTokenDecoderFactory logoutTokenDecoderFactory = new OidcIdTokenDecoderFactory ();
60
- logoutTokenDecoderFactory .setJwtValidatorFactory (new DefaultOidcLogoutTokenValidatorFactory ());
61
- this .logoutTokenDecoderFactory = logoutTokenDecoderFactory ;
66
+ DefaultOidcLogoutTokenValidatorFactory jwtValidator = new DefaultOidcLogoutTokenValidatorFactory ();
67
+ this .logoutTokenDecoderFactory = (clientRegistration ) -> {
68
+ String jwkSetUri = clientRegistration .getProviderDetails ().getJwkSetUri ();
69
+ if (!StringUtils .hasText (jwkSetUri )) {
70
+ OAuth2Error oauth2Error = new OAuth2Error ("missing_signature_verifier" ,
71
+ "Failed to find a Signature Verifier for Client Registration: '"
72
+ + clientRegistration .getRegistrationId ()
73
+ + "'. Check to ensure you have configured the JwkSet URI." ,
74
+ null );
75
+ throw new OAuth2AuthenticationException (oauth2Error , oauth2Error .toString ());
76
+ }
77
+ JOSEObjectTypeVerifier <SecurityContext > typeVerifier = new DefaultJOSEObjectTypeVerifier <>(null ,
78
+ JOSEObjectType .JWT , new JOSEObjectType ("logout+jwt" ));
79
+ NimbusJwtDecoder decoder = NimbusJwtDecoder .withJwkSetUri (jwkSetUri )
80
+ .jwtProcessorCustomizer ((processor ) -> processor .setJWSTypeVerifier (typeVerifier ))
81
+ .build ();
82
+ decoder .setJwtValidator (jwtValidator .apply (clientRegistration ));
83
+ decoder .setClaimSetConverter (OidcIdTokenDecoderFactory .createDefaultClaimTypeConverter ());
84
+ return decoder ;
85
+ };
62
86
}
63
87
64
88
/**
0 commit comments