|
|
|
@ -16,6 +16,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.security.config.annotation.web.configurers.oauth2.client; |
|
|
|
package org.springframework.security.config.annotation.web.configurers.oauth2.client; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.nimbusds.jose.JOSEObjectType; |
|
|
|
|
|
|
|
import com.nimbusds.jose.proc.DefaultJOSEObjectTypeVerifier; |
|
|
|
|
|
|
|
import com.nimbusds.jose.proc.JOSEObjectTypeVerifier; |
|
|
|
|
|
|
|
import com.nimbusds.jose.proc.SecurityContext; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.security.authentication.AuthenticationProvider; |
|
|
|
import org.springframework.security.authentication.AuthenticationProvider; |
|
|
|
import org.springframework.security.authentication.AuthenticationServiceException; |
|
|
|
import org.springframework.security.authentication.AuthenticationServiceException; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
@ -30,7 +35,9 @@ import org.springframework.security.oauth2.jwt.BadJwtException; |
|
|
|
import org.springframework.security.oauth2.jwt.Jwt; |
|
|
|
import org.springframework.security.oauth2.jwt.Jwt; |
|
|
|
import org.springframework.security.oauth2.jwt.JwtDecoder; |
|
|
|
import org.springframework.security.oauth2.jwt.JwtDecoder; |
|
|
|
import org.springframework.security.oauth2.jwt.JwtDecoderFactory; |
|
|
|
import org.springframework.security.oauth2.jwt.JwtDecoderFactory; |
|
|
|
|
|
|
|
import org.springframework.security.oauth2.jwt.NimbusJwtDecoder; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* An {@link AuthenticationProvider} that authenticates an OIDC Logout Token; namely |
|
|
|
* An {@link AuthenticationProvider} that authenticates an OIDC Logout Token; namely |
|
|
|
@ -56,9 +63,26 @@ final class OidcBackChannelLogoutAuthenticationProvider implements Authenticatio |
|
|
|
* Construct an {@link OidcBackChannelLogoutAuthenticationProvider} |
|
|
|
* Construct an {@link OidcBackChannelLogoutAuthenticationProvider} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
OidcBackChannelLogoutAuthenticationProvider() { |
|
|
|
OidcBackChannelLogoutAuthenticationProvider() { |
|
|
|
OidcIdTokenDecoderFactory logoutTokenDecoderFactory = new OidcIdTokenDecoderFactory(); |
|
|
|
DefaultOidcLogoutTokenValidatorFactory jwtValidator = new DefaultOidcLogoutTokenValidatorFactory(); |
|
|
|
logoutTokenDecoderFactory.setJwtValidatorFactory(new DefaultOidcLogoutTokenValidatorFactory()); |
|
|
|
this.logoutTokenDecoderFactory = (clientRegistration) -> { |
|
|
|
this.logoutTokenDecoderFactory = logoutTokenDecoderFactory; |
|
|
|
String jwkSetUri = clientRegistration.getProviderDetails().getJwkSetUri(); |
|
|
|
|
|
|
|
if (!StringUtils.hasText(jwkSetUri)) { |
|
|
|
|
|
|
|
OAuth2Error oauth2Error = new OAuth2Error("missing_signature_verifier", |
|
|
|
|
|
|
|
"Failed to find a Signature Verifier for Client Registration: '" |
|
|
|
|
|
|
|
+ clientRegistration.getRegistrationId() |
|
|
|
|
|
|
|
+ "'. Check to ensure you have configured the JwkSet URI.", |
|
|
|
|
|
|
|
null); |
|
|
|
|
|
|
|
throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
JOSEObjectTypeVerifier<SecurityContext> typeVerifier = new DefaultJOSEObjectTypeVerifier<>(null, |
|
|
|
|
|
|
|
JOSEObjectType.JWT, new JOSEObjectType("logout+jwt")); |
|
|
|
|
|
|
|
NimbusJwtDecoder decoder = NimbusJwtDecoder.withJwkSetUri(jwkSetUri) |
|
|
|
|
|
|
|
.jwtProcessorCustomizer((processor) -> processor.setJWSTypeVerifier(typeVerifier)) |
|
|
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
decoder.setJwtValidator(jwtValidator.apply(clientRegistration)); |
|
|
|
|
|
|
|
decoder.setClaimSetConverter(OidcIdTokenDecoderFactory.createDefaultClaimTypeConverter()); |
|
|
|
|
|
|
|
return decoder; |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|