11/* 
2-  * Copyright 2002-2023  the original author or authors. 
2+  * Copyright 2002-2024  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
1616
1717package  org .springframework .security .config .web .server ;
1818
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 .JWKSecurityContext ;
1923import  reactor .core .publisher .Mono ;
2024
2125import  org .springframework .security .authentication .AuthenticationProvider ;
2226import  org .springframework .security .authentication .AuthenticationServiceException ;
2327import  org .springframework .security .authentication .ReactiveAuthenticationManager ;
2428import  org .springframework .security .core .Authentication ;
2529import  org .springframework .security .core .AuthenticationException ;
26- import  org .springframework .security .oauth2 .client .oidc .authentication .ReactiveOidcIdTokenDecoderFactory ;
30+ import  org .springframework .security .oauth2 .client .oidc .authentication .OidcIdTokenDecoderFactory ;
2731import  org .springframework .security .oauth2 .client .oidc .authentication .logout .OidcLogoutToken ;
2832import  org .springframework .security .oauth2 .client .registration .ClientRegistration ;
2933import  org .springframework .security .oauth2 .core .OAuth2AuthenticationException ;
3034import  org .springframework .security .oauth2 .core .OAuth2Error ;
3135import  org .springframework .security .oauth2 .core .OAuth2ErrorCodes ;
36+ import  org .springframework .security .oauth2 .core .converter .ClaimTypeConverter ;
3237import  org .springframework .security .oauth2 .jwt .BadJwtException ;
3338import  org .springframework .security .oauth2 .jwt .Jwt ;
3439import  org .springframework .security .oauth2 .jwt .JwtDecoder ;
3540import  org .springframework .security .oauth2 .jwt .JwtDecoderFactory ;
41+ import  org .springframework .security .oauth2 .jwt .NimbusReactiveJwtDecoder ;
3642import  org .springframework .security .oauth2 .jwt .ReactiveJwtDecoder ;
3743import  org .springframework .security .oauth2 .jwt .ReactiveJwtDecoderFactory ;
3844import  org .springframework .util .Assert ;
45+ import  org .springframework .util .StringUtils ;
3946
4047/** 
4148 * An {@link AuthenticationProvider} that authenticates an OIDC Logout Token; namely 
@@ -61,9 +68,27 @@ final class OidcBackChannelLogoutReactiveAuthenticationManager implements Reacti
6168	 * Construct an {@link OidcBackChannelLogoutReactiveAuthenticationManager} 
6269	 */ 
6370	OidcBackChannelLogoutReactiveAuthenticationManager () {
64- 		ReactiveOidcIdTokenDecoderFactory  logoutTokenDecoderFactory  = new  ReactiveOidcIdTokenDecoderFactory ();
65- 		logoutTokenDecoderFactory .setJwtValidatorFactory (new  DefaultOidcLogoutTokenValidatorFactory ());
66- 		this .logoutTokenDecoderFactory  = logoutTokenDecoderFactory ;
71+ 		DefaultOidcLogoutTokenValidatorFactory  jwtValidator  = new  DefaultOidcLogoutTokenValidatorFactory ();
72+ 		this .logoutTokenDecoderFactory  = (clientRegistration ) -> {
73+ 			String  jwkSetUri  = clientRegistration .getProviderDetails ().getJwkSetUri ();
74+ 			if  (!StringUtils .hasText (jwkSetUri )) {
75+ 				OAuth2Error  oauth2Error  = new  OAuth2Error ("missing_signature_verifier" ,
76+ 						"Failed to find a Signature Verifier for Client Registration: '" 
77+ 								+ clientRegistration .getRegistrationId ()
78+ 								+ "'. Check to ensure you have configured the JwkSet URI." ,
79+ 						null );
80+ 				throw  new  OAuth2AuthenticationException (oauth2Error , oauth2Error .toString ());
81+ 			}
82+ 			JOSEObjectTypeVerifier <JWKSecurityContext > typeVerifier  = new  DefaultJOSEObjectTypeVerifier <>(null ,
83+ 					JOSEObjectType .JWT , new  JOSEObjectType ("logout+jwt" ));
84+ 			NimbusReactiveJwtDecoder  decoder  = NimbusReactiveJwtDecoder .withJwkSetUri (jwkSetUri )
85+ 				.jwtProcessorCustomizer ((processor ) -> processor .setJWSTypeVerifier (typeVerifier ))
86+ 				.build ();
87+ 			decoder .setJwtValidator (jwtValidator .apply (clientRegistration ));
88+ 			decoder .setClaimSetConverter (
89+ 					new  ClaimTypeConverter (OidcIdTokenDecoderFactory .createDefaultClaimTypeConverters ()));
90+ 			return  decoder ;
91+ 		};
6792	}
6893
6994	/** 
0 commit comments