Skip to content

Commit

Permalink
Add interceptors to AuthorizationServerEndpointsConfigurer
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Syer committed Jun 10, 2014
1 parent 20903ff commit 4145668
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.web.context.request.WebRequestInterceptor;
import org.springframework.web.servlet.HandlerInterceptor;

/**
* Configure the properties and enhanced functionality of the Authorization Server endpoints.
Expand Down Expand Up @@ -97,6 +99,8 @@ public final class AuthorizationServerEndpointsConfigurer {

private boolean approvalStoreDisabled;

private List<Object> interceptors = new ArrayList<Object>();

public AuthorizationServerTokenServices getTokenServices() {
return tokenServices;
}
Expand Down Expand Up @@ -176,6 +180,16 @@ public AuthorizationServerEndpointsConfigurer pathMapping(String defaultPath, St
return this;
}

public AuthorizationServerEndpointsConfigurer addInterceptor(HandlerInterceptor interceptor) {
this.interceptors.add(interceptor);
return this;
}

public AuthorizationServerEndpointsConfigurer addInterceptor(WebRequestInterceptor interceptor) {
this.interceptors.add(interceptor);
return this;
}

public AuthorizationServerEndpointsConfigurer authenticationManager(AuthenticationManager authenticationManager) {
this.authenticationManager = authenticationManager;
return this;
Expand Down Expand Up @@ -387,6 +401,7 @@ private FrameworkEndpointHandlerMapping frameworkEndpointHandlerMapping() {
if (frameworkEndpointHandlerMapping == null) {
frameworkEndpointHandlerMapping = new FrameworkEndpointHandlerMapping();
frameworkEndpointHandlerMapping.setMappings(patternMap);
frameworkEndpointHandlerMapping.setInterceptors(interceptors .toArray());
}
return frameworkEndpointHandlerMapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.springframework.security.oauth2.provider.OAuth2Request;

/**
* Basic key generator taking into account the client id, scope, reource ids and username (principal name) if they
* Basic key generator taking into account the client id, scope, resource ids and username (principal name) if they
* exist.
*
* @author Dave Syer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
* @author Dave Syer
Expand Down Expand Up @@ -133,7 +134,7 @@ protected static class AuthorizationServerUnconfigured {
protected static class AuthorizationServerVanilla extends AuthorizationServerConfigurerAdapter implements Runnable {
@Autowired
private AuthorizationEndpoint endpoint;

@Autowired
private ClientDetailsService clientDetailsService;

Expand All @@ -160,7 +161,8 @@ public void run() {
Map<String, Object> request = handler.getUserApprovalRequest(authorizationRequest,
new UsernamePasswordAuthenticationToken("user", "password"));
assertTrue(request.containsKey("scopes"));
assertTrue(clientDetailsService.loadClientByClientId("my-trusted-client").getAdditionalInformation().containsKey("foo"));
assertTrue(clientDetailsService.loadClientByClientId("my-trusted-client").getAdditionalInformation()
.containsKey("foo"));
}
}

Expand Down Expand Up @@ -251,7 +253,9 @@ public TokenApprovalStore approvalStore() {

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
endpoints.tokenStore(tokenStore).approvalStore(approvalStore()).userApprovalHandler(userApprovalHandler());
endpoints.tokenStore(tokenStore).approvalStore(approvalStore()).userApprovalHandler(userApprovalHandler())
.addInterceptor(new HandlerInterceptorAdapter() {
});
}

@Override
Expand Down

0 comments on commit 4145668

Please sign in to comment.