42
42
import org .springframework .security .oauth2 .server .authorization .authentication .OAuth2ClientAuthenticationProvider ;
43
43
import org .springframework .security .oauth2 .server .authorization .authentication .OAuth2ClientCredentialsAuthenticationProvider ;
44
44
import org .springframework .security .oauth2 .server .authorization .authentication .OAuth2RefreshTokenAuthenticationProvider ;
45
+ import org .springframework .security .oauth2 .server .authorization .authentication .OAuth2TokenIntrospectionAuthenticationProvider ;
45
46
import org .springframework .security .oauth2 .server .authorization .authentication .OAuth2TokenRevocationAuthenticationProvider ;
46
47
import org .springframework .security .oauth2 .server .authorization .client .RegisteredClientRepository ;
47
48
import org .springframework .security .oauth2 .server .authorization .config .ProviderSettings ;
50
51
import org .springframework .security .oauth2 .server .authorization .web .OAuth2AuthorizationEndpointFilter ;
51
52
import org .springframework .security .oauth2 .server .authorization .web .OAuth2ClientAuthenticationFilter ;
52
53
import org .springframework .security .oauth2 .server .authorization .web .OAuth2TokenEndpointFilter ;
54
+ import org .springframework .security .oauth2 .server .authorization .web .OAuth2TokenIntrospectionEndpointFilter ;
53
55
import org .springframework .security .oauth2 .server .authorization .web .OAuth2TokenRevocationEndpointFilter ;
54
56
import org .springframework .security .web .access .intercept .FilterSecurityInterceptor ;
55
57
import org .springframework .security .web .authentication .HttpStatusEntryPoint ;
65
67
*
66
68
* @author Joe Grandja
67
69
* @author Daniel Garnier-Moiroux
70
+ * @author Gerardo Roza
68
71
* @since 0.0.1
69
72
* @see AbstractHttpConfigurer
70
73
* @see RegisteredClientRepository
71
74
* @see OAuth2AuthorizationService
72
75
* @see OAuth2AuthorizationEndpointFilter
73
76
* @see OAuth2TokenEndpointFilter
77
+ * @see OAuth2TokenIntrospectionEndpointFilter
74
78
* @see OAuth2TokenRevocationEndpointFilter
75
79
* @see NimbusJwkSetEndpointFilter
76
80
* @see OidcProviderConfigurationEndpointFilter
@@ -81,12 +85,14 @@ public final class OAuth2AuthorizationServerConfigurer<B extends HttpSecurityBui
81
85
82
86
private RequestMatcher authorizationEndpointMatcher ;
83
87
private RequestMatcher tokenEndpointMatcher ;
88
+ private RequestMatcher tokenIntrospectionEndpointMatcher ;
84
89
private RequestMatcher tokenRevocationEndpointMatcher ;
85
90
private RequestMatcher jwkSetEndpointMatcher ;
86
91
private RequestMatcher oidcProviderConfigurationEndpointMatcher ;
87
92
private final RequestMatcher endpointsMatcher = (request ) ->
88
93
this .authorizationEndpointMatcher .matches (request ) ||
89
94
this .tokenEndpointMatcher .matches (request ) ||
95
+ this .tokenIntrospectionEndpointMatcher .matches (request ) ||
90
96
this .tokenRevocationEndpointMatcher .matches (request ) ||
91
97
this .jwkSetEndpointMatcher .matches (request ) ||
92
98
this .oidcProviderConfigurationEndpointMatcher .matches (request );
@@ -183,12 +189,18 @@ public void init(B builder) {
183
189
getAuthorizationService (builder ));
184
190
builder .authenticationProvider (postProcess (tokenRevocationAuthenticationProvider ));
185
191
192
+ OAuth2TokenIntrospectionAuthenticationProvider tokenIntrospectionAuthenticationProvider =
193
+ new OAuth2TokenIntrospectionAuthenticationProvider (
194
+ getAuthorizationService (builder ));
195
+ builder .authenticationProvider (postProcess (tokenIntrospectionAuthenticationProvider ));
196
+
186
197
ExceptionHandlingConfigurer <B > exceptionHandling = builder .getConfigurer (ExceptionHandlingConfigurer .class );
187
198
if (exceptionHandling != null ) {
188
199
exceptionHandling .defaultAuthenticationEntryPointFor (
189
200
new HttpStatusEntryPoint (HttpStatus .UNAUTHORIZED ),
190
201
new OrRequestMatcher (
191
202
this .tokenEndpointMatcher ,
203
+ this .tokenIntrospectionEndpointMatcher ,
192
204
this .tokenRevocationEndpointMatcher )
193
205
);
194
206
}
@@ -216,6 +228,7 @@ public void configure(B builder) {
216
228
authenticationManager ,
217
229
new OrRequestMatcher (
218
230
this .tokenEndpointMatcher ,
231
+ this .tokenIntrospectionEndpointMatcher ,
219
232
this .tokenRevocationEndpointMatcher ));
220
233
builder .addFilterAfter (postProcess (clientAuthenticationFilter ), AbstractPreAuthenticatedProcessingFilter .class );
221
234
@@ -237,6 +250,12 @@ public void configure(B builder) {
237
250
authenticationManager ,
238
251
providerSettings .tokenRevocationEndpoint ());
239
252
builder .addFilterAfter (postProcess (tokenRevocationEndpointFilter ), OAuth2TokenEndpointFilter .class );
253
+
254
+ OAuth2TokenIntrospectionEndpointFilter tokenIntrospectionEndpointFilter =
255
+ new OAuth2TokenIntrospectionEndpointFilter (
256
+ authenticationManager ,
257
+ providerSettings .tokenIntrospectionEndpoint ());
258
+ builder .addFilterAfter (postProcess (tokenIntrospectionEndpointFilter ), OAuth2TokenEndpointFilter .class );
240
259
}
241
260
242
261
private void initEndpointMatchers (ProviderSettings providerSettings ) {
@@ -249,6 +268,8 @@ private void initEndpointMatchers(ProviderSettings providerSettings) {
249
268
HttpMethod .POST .name ()));
250
269
this .tokenEndpointMatcher = new AntPathRequestMatcher (
251
270
providerSettings .tokenEndpoint (), HttpMethod .POST .name ());
271
+ this .tokenIntrospectionEndpointMatcher = new AntPathRequestMatcher (
272
+ providerSettings .tokenIntrospectionEndpoint (), HttpMethod .POST .name ());
252
273
this .tokenRevocationEndpointMatcher = new AntPathRequestMatcher (
253
274
providerSettings .tokenRevocationEndpoint (), HttpMethod .POST .name ());
254
275
this .jwkSetEndpointMatcher = new AntPathRequestMatcher (
0 commit comments