|
68 | 68 |
|
69 | 69 | import static org.springframework.security.config.http.SecurityFilters.ANONYMOUS_FILTER;
|
70 | 70 | import static org.springframework.security.config.http.SecurityFilters.BASIC_AUTH_FILTER;
|
| 71 | +import static org.springframework.security.config.http.SecurityFilters.BEARER_TOKEN_AUTH_FILTER; |
71 | 72 | import static org.springframework.security.config.http.SecurityFilters.EXCEPTION_TRANSLATION_FILTER;
|
72 | 73 | import static org.springframework.security.config.http.SecurityFilters.FORM_LOGIN_FILTER;
|
73 | 74 | import static org.springframework.security.config.http.SecurityFilters.LOGIN_PAGE_FILTER;
|
@@ -139,6 +140,8 @@ final class AuthenticationConfigBuilder {
|
139 | 140 | private BeanMetadataElement mainEntryPoint;
|
140 | 141 | private BeanMetadataElement accessDeniedHandler;
|
141 | 142 |
|
| 143 | + private BeanDefinition bearerTokenAuthenticationFilter; |
| 144 | + |
142 | 145 | private BeanDefinition logoutFilter;
|
143 | 146 | @SuppressWarnings("rawtypes")
|
144 | 147 | private ManagedList logoutHandlers;
|
@@ -191,6 +194,7 @@ final class AuthenticationConfigBuilder {
|
191 | 194 | createAnonymousFilter();
|
192 | 195 | createRememberMeFilter(authenticationManager);
|
193 | 196 | createBasicFilter(authenticationManager);
|
| 197 | + createBearerTokenAuthenticationFilter(authenticationManager); |
194 | 198 | createFormLoginFilter(sessionStrategy, authenticationManager);
|
195 | 199 | createOAuth2LoginFilter(sessionStrategy, authenticationManager);
|
196 | 200 | createOAuth2ClientFilter(requestCache, authenticationManager);
|
@@ -504,6 +508,21 @@ void createBasicFilter(BeanReference authManager) {
|
504 | 508 | basicFilter = filterBuilder.getBeanDefinition();
|
505 | 509 | }
|
506 | 510 |
|
| 511 | + void createBearerTokenAuthenticationFilter(BeanReference authManager) { |
| 512 | + Element resourceServerElt = DomUtils.getChildElementByTagName(httpElt, |
| 513 | + Elements.OAUTH2_RESOURCE_SERVER); |
| 514 | + |
| 515 | + if (resourceServerElt == null) { |
| 516 | + // No resource server, do nothing |
| 517 | + return; |
| 518 | + } |
| 519 | + |
| 520 | + OAuth2ResourceServerBeanDefinitionParser resourceServerBuilder = |
| 521 | + new OAuth2ResourceServerBeanDefinitionParser(authManager, authenticationProviders, |
| 522 | + defaultEntryPointMappings, defaultDeniedHandlerMappings, csrfIgnoreRequestMatchers); |
| 523 | + bearerTokenAuthenticationFilter = resourceServerBuilder.parse(resourceServerElt, pc); |
| 524 | + } |
| 525 | + |
507 | 526 | void createX509Filter(BeanReference authManager) {
|
508 | 527 | Element x509Elt = DomUtils.getChildElementByTagName(httpElt, Elements.X509);
|
509 | 528 | RootBeanDefinition filter = null;
|
@@ -969,8 +988,12 @@ List<OrderDecorator> getFilters() {
|
969 | 988 | filters.add(new OrderDecorator(basicFilter, BASIC_AUTH_FILTER));
|
970 | 989 | }
|
971 | 990 |
|
| 991 | + if (bearerTokenAuthenticationFilter != null) { |
| 992 | + filters.add(new OrderDecorator(bearerTokenAuthenticationFilter, BEARER_TOKEN_AUTH_FILTER)); |
| 993 | + } |
| 994 | + |
972 | 995 | if (authorizationCodeGrantFilter != null) {
|
973 |
| - filters.add(new OrderDecorator(authorizationRequestRedirectFilter, OAUTH2_AUTHORIZATION_REQUEST_FILTER.getOrder()+1)); |
| 996 | + filters.add(new OrderDecorator(authorizationRequestRedirectFilter, OAUTH2_AUTHORIZATION_REQUEST_FILTER.getOrder() + 1)); |
974 | 997 | filters.add(new OrderDecorator(authorizationCodeGrantFilter, OAUTH2_AUTHORIZATION_CODE_GRANT_FILTER));
|
975 | 998 | }
|
976 | 999 |
|
|
0 commit comments