31
31
import org .springframework .security .oauth2 .core .ClientAuthenticationMethod ;
32
32
import org .springframework .security .oauth2 .core .endpoint .OAuth2AuthorizationResponseType ;
33
33
import org .springframework .security .oauth2 .server .authorization .OAuth2AuthorizationServerMetadata ;
34
+ import org .springframework .security .oauth2 .server .authorization .context .AuthorizationServerContext ;
34
35
import org .springframework .security .oauth2 .server .authorization .context .AuthorizationServerContextHolder ;
35
36
import org .springframework .security .oauth2 .server .authorization .http .converter .OAuth2AuthorizationServerMetadataHttpMessageConverter ;
36
37
import org .springframework .security .oauth2 .server .authorization .settings .AuthorizationServerSettings ;
37
38
import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
38
39
import org .springframework .security .web .util .matcher .RequestMatcher ;
39
- import org .springframework .util .Assert ;
40
40
import org .springframework .web .filter .OncePerRequestFilter ;
41
41
import org .springframework .web .util .UriComponentsBuilder ;
42
42
@@ -55,20 +55,12 @@ public final class OAuth2AuthorizationServerMetadataEndpointFilter extends OnceP
55
55
*/
56
56
private static final String DEFAULT_OAUTH2_AUTHORIZATION_SERVER_METADATA_ENDPOINT_URI = "/.well-known/oauth-authorization-server" ;
57
57
58
- private final AuthorizationServerSettings authorizationServerSettings ;
59
- private final RequestMatcher requestMatcher ;
58
+ private final RequestMatcher requestMatcher = new AntPathRequestMatcher (
59
+ DEFAULT_OAUTH2_AUTHORIZATION_SERVER_METADATA_ENDPOINT_URI ,
60
+ HttpMethod .GET .name ());
60
61
private final OAuth2AuthorizationServerMetadataHttpMessageConverter authorizationServerMetadataHttpMessageConverter =
61
62
new OAuth2AuthorizationServerMetadataHttpMessageConverter ();
62
63
63
- public OAuth2AuthorizationServerMetadataEndpointFilter (AuthorizationServerSettings authorizationServerSettings ) {
64
- Assert .notNull (authorizationServerSettings , "authorizationServerSettings cannot be null" );
65
- this .authorizationServerSettings = authorizationServerSettings ;
66
- this .requestMatcher = new AntPathRequestMatcher (
67
- DEFAULT_OAUTH2_AUTHORIZATION_SERVER_METADATA_ENDPOINT_URI ,
68
- HttpMethod .GET .name ()
69
- );
70
- }
71
-
72
64
@ Override
73
65
protected void doFilterInternal (HttpServletRequest request , HttpServletResponse response , FilterChain filterChain )
74
66
throws ServletException , IOException {
@@ -78,21 +70,23 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
78
70
return ;
79
71
}
80
72
81
- String issuer = AuthorizationServerContextHolder .getContext ().getIssuer ();
73
+ AuthorizationServerContext authorizationServerContext = AuthorizationServerContextHolder .getContext ();
74
+ String issuer = authorizationServerContext .getIssuer ();
75
+ AuthorizationServerSettings authorizationServerSettings = authorizationServerContext .getAuthorizationServerSettings ();
82
76
83
77
OAuth2AuthorizationServerMetadata authorizationServerMetadata = OAuth2AuthorizationServerMetadata .builder ()
84
78
.issuer (issuer )
85
- .authorizationEndpoint (asUrl (issuer , this . authorizationServerSettings .getAuthorizationEndpoint ()))
86
- .tokenEndpoint (asUrl (issuer , this . authorizationServerSettings .getTokenEndpoint ()))
79
+ .authorizationEndpoint (asUrl (issuer , authorizationServerSettings .getAuthorizationEndpoint ()))
80
+ .tokenEndpoint (asUrl (issuer , authorizationServerSettings .getTokenEndpoint ()))
87
81
.tokenEndpointAuthenticationMethods (clientAuthenticationMethods ())
88
- .jwkSetUrl (asUrl (issuer , this . authorizationServerSettings .getJwkSetEndpoint ()))
82
+ .jwkSetUrl (asUrl (issuer , authorizationServerSettings .getJwkSetEndpoint ()))
89
83
.responseType (OAuth2AuthorizationResponseType .CODE .getValue ())
90
84
.grantType (AuthorizationGrantType .AUTHORIZATION_CODE .getValue ())
91
85
.grantType (AuthorizationGrantType .CLIENT_CREDENTIALS .getValue ())
92
86
.grantType (AuthorizationGrantType .REFRESH_TOKEN .getValue ())
93
- .tokenRevocationEndpoint (asUrl (issuer , this . authorizationServerSettings .getTokenRevocationEndpoint ()))
87
+ .tokenRevocationEndpoint (asUrl (issuer , authorizationServerSettings .getTokenRevocationEndpoint ()))
94
88
.tokenRevocationEndpointAuthenticationMethods (clientAuthenticationMethods ())
95
- .tokenIntrospectionEndpoint (asUrl (issuer , this . authorizationServerSettings .getTokenIntrospectionEndpoint ()))
89
+ .tokenIntrospectionEndpoint (asUrl (issuer , authorizationServerSettings .getTokenIntrospectionEndpoint ()))
96
90
.tokenIntrospectionEndpointAuthenticationMethods (clientAuthenticationMethods ())
97
91
.codeChallengeMethod ("S256" )
98
92
.build ();
0 commit comments