Skip to content

Commit 642172d

Browse files
committed
Add Resource Server XML Support
Fixes spring-projectsgh-5185
1 parent 4835098 commit 642172d

File tree

58 files changed

+3031
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3031
-2
lines changed

config/src/main/java/org/springframework/security/config/Elements.java

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public abstract class Elements {
7070
public static final String CORS = "cors";
7171
public static final String CSRF = "csrf";
7272

73+
public static final String OAUTH2_RESOURCE_SERVER = "oauth2-resource-server";
74+
public static final String JWT = "jwt";
75+
public static final String OPAQUE_TOKEN = "opaque-token";
76+
7377
public static final String WEBSOCKET_MESSAGE_BROKER = "websocket-message-broker";
7478
public static final String INTERCEPT_MESSAGE = "intercept-message";
7579

config/src/main/java/org/springframework/security/config/http/AuthenticationConfigBuilder.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868

6969
import static org.springframework.security.config.http.SecurityFilters.ANONYMOUS_FILTER;
7070
import static org.springframework.security.config.http.SecurityFilters.BASIC_AUTH_FILTER;
71+
import static org.springframework.security.config.http.SecurityFilters.BEARER_TOKEN_AUTH_FILTER;
7172
import static org.springframework.security.config.http.SecurityFilters.EXCEPTION_TRANSLATION_FILTER;
7273
import static org.springframework.security.config.http.SecurityFilters.FORM_LOGIN_FILTER;
7374
import static org.springframework.security.config.http.SecurityFilters.LOGIN_PAGE_FILTER;
@@ -139,6 +140,8 @@ final class AuthenticationConfigBuilder {
139140
private BeanMetadataElement mainEntryPoint;
140141
private BeanMetadataElement accessDeniedHandler;
141142

143+
private BeanDefinition bearerTokenAuthenticationFilter;
144+
142145
private BeanDefinition logoutFilter;
143146
@SuppressWarnings("rawtypes")
144147
private ManagedList logoutHandlers;
@@ -191,6 +194,7 @@ final class AuthenticationConfigBuilder {
191194
createAnonymousFilter();
192195
createRememberMeFilter(authenticationManager);
193196
createBasicFilter(authenticationManager);
197+
createBearerTokenAuthenticationFilter(authenticationManager);
194198
createFormLoginFilter(sessionStrategy, authenticationManager);
195199
createOAuth2LoginFilter(sessionStrategy, authenticationManager);
196200
createOAuth2ClientFilter(requestCache, authenticationManager);
@@ -504,6 +508,21 @@ void createBasicFilter(BeanReference authManager) {
504508
basicFilter = filterBuilder.getBeanDefinition();
505509
}
506510

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+
507526
void createX509Filter(BeanReference authManager) {
508527
Element x509Elt = DomUtils.getChildElementByTagName(httpElt, Elements.X509);
509528
RootBeanDefinition filter = null;
@@ -969,8 +988,12 @@ List<OrderDecorator> getFilters() {
969988
filters.add(new OrderDecorator(basicFilter, BASIC_AUTH_FILTER));
970989
}
971990

991+
if (bearerTokenAuthenticationFilter != null) {
992+
filters.add(new OrderDecorator(bearerTokenAuthenticationFilter, BEARER_TOKEN_AUTH_FILTER));
993+
}
994+
972995
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));
974997
filters.add(new OrderDecorator(authorizationCodeGrantFilter, OAUTH2_AUTHORIZATION_CODE_GRANT_FILTER));
975998
}
976999

0 commit comments

Comments
 (0)