@ -16,8 +16,6 @@
package org.springframework.security.oauth2.jwt ;
package org.springframework.security.oauth2.jwt ;
import java.net.URI ;
import java.util.Collections ;
import java.util.HashSet ;
import java.util.HashSet ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
@ -83,13 +81,11 @@ final class JwtDecoderProviderConfigurationUtils {
}
}
static Map < String , Object > getConfigurationForOidcIssuerLocation ( String oidcIssuerLocation ) {
static Map < String , Object > getConfigurationForOidcIssuerLocation ( String oidcIssuerLocation ) {
UriComponents uri = UriComponentsBuilder . fromUriString ( oidcIssuerLocation ) . build ( ) ;
return getConfiguration ( oidcIssuerLocation , rest , oidc ( oidcIssuerLocation ) ) ;
return getConfiguration ( oidcIssuerLocation , rest , oidc ( uri ) ) ;
}
}
static Map < String , Object > getConfigurationForIssuerLocation ( String issuer , RestOperations rest ) {
static Map < String , Object > getConfigurationForIssuerLocation ( String issuer , RestOperations rest ) {
UriComponents uri = UriComponentsBuilder . fromUriString ( issuer ) . build ( ) ;
return getConfiguration ( issuer , rest , oidc ( issuer ) , oidcRfc8414 ( issuer ) , oauth ( issuer ) ) ;
return getConfiguration ( issuer , rest , oidc ( uri ) , oidcRfc8414 ( uri ) , oauth ( uri ) ) ;
}
}
static Map < String , Object > getConfigurationForIssuerLocation ( String issuer ) {
static Map < String , Object > getConfigurationForIssuerLocation ( String issuer ) {
@ -161,11 +157,11 @@ final class JwtDecoderProviderConfigurationUtils {
return "(unavailable)" ;
return "(unavailable)" ;
}
}
private static Map < String , Object > getConfiguration ( String issuer , RestOperations rest , URI . . . uris ) {
private static Map < String , Object > getConfiguration ( String issuer , RestOperations rest , UriComponents . . . uris ) {
String errorMessage = "Unable to resolve the Configuration with the provided Issuer of " + "\"" + issuer + "\"" ;
String errorMessage = "Unable to resolve the Configuration with the provided Issuer of " + "\"" + issuer + "\"" ;
for ( URI uri : uris ) {
for ( UriComponents uri : uris ) {
try {
try {
RequestEntity < Void > request = RequestEntity . get ( uri ) . build ( ) ;
RequestEntity < Void > request = RequestEntity . get ( uri . toUriString ( ) ) . build ( ) ;
ResponseEntity < Map < String , Object > > response = rest . exchange ( request , STRING_OBJECT_MAP ) ;
ResponseEntity < Map < String , Object > > response = rest . exchange ( request , STRING_OBJECT_MAP ) ;
Map < String , Object > configuration = response . getBody ( ) ;
Map < String , Object > configuration = response . getBody ( ) ;
Assert . isTrue ( configuration . get ( "jwks_uri" ) ! = null , "The public JWK set URI must not be null" ) ;
Assert . isTrue ( configuration . get ( "jwks_uri" ) ! = null , "The public JWK set URI must not be null" ) ;
@ -185,27 +181,30 @@ final class JwtDecoderProviderConfigurationUtils {
throw new IllegalArgumentException ( errorMessage ) ;
throw new IllegalArgumentException ( errorMessage ) ;
}
}
private static URI oidc ( UriComponents issuer ) {
static UriComponents oidc ( String issuer ) {
UriComponents uri = UriComponentsBuilder . fromUriString ( issuer ) . build ( ) ;
// @formatter:off
// @formatter:off
return UriComponentsBuilder . newInstance ( ) . uriComponents ( iss ue r)
return UriComponentsBuilder . newInstance ( ) . uriComponents ( uri )
. replacePath ( iss ue r. getPath ( ) + OIDC_METADATA_PATH )
. replacePath ( uri . getPath ( ) + OIDC_METADATA_PATH )
. build ( Collections . emptyMap ( ) ) ;
. build ( ) ;
// @formatter:on
// @formatter:on
}
}
private static URI oidcRfc8414 ( UriComponents issuer ) {
static UriComponents oidcRfc8414 ( String issuer ) {
UriComponents uri = UriComponentsBuilder . fromUriString ( issuer ) . build ( ) ;
// @formatter:off
// @formatter:off
return UriComponentsBuilder . newInstance ( ) . uriComponents ( iss ue r)
return UriComponentsBuilder . newInstance ( ) . uriComponents ( uri )
. replacePath ( OIDC_METADATA_PATH + iss ue r. getPath ( ) )
. replacePath ( OIDC_METADATA_PATH + uri . getPath ( ) )
. build ( Collections . emptyMap ( ) ) ;
. build ( ) ;
// @formatter:on
// @formatter:on
}
}
private static URI oauth ( UriComponents issuer ) {
static UriComponents oauth ( String issuer ) {
UriComponents uri = UriComponentsBuilder . fromUriString ( issuer ) . build ( ) ;
// @formatter:off
// @formatter:off
return UriComponentsBuilder . newInstance ( ) . uriComponents ( iss ue r)
return UriComponentsBuilder . newInstance ( ) . uriComponents ( uri )
. replacePath ( OAUTH_METADATA_PATH + iss ue r. getPath ( ) )
. replacePath ( OAUTH_METADATA_PATH + uri . getPath ( ) )
. build ( Collections . emptyMap ( ) ) ;
. build ( ) ;
// @formatter:on
// @formatter:on
}
}