Skip to content

Commit

Permalink
Remove builder convenience method for ClientDetailsService
Browse files Browse the repository at this point in the history
The AuthorizationServerEndpointsConfigurer had a clientDetails() method
that was supposed to be for internal use (but unfortunately had to
be public so it can be called by a class in another package). Without
changing the packaging, the safest change at this point (even though
it's a public API) is to change the method signature and document it
to make it clear that it's not public.

Fixes spring-atticgh-336
  • Loading branch information
Dave Syer committed Dec 17, 2014
1 parent b86edc8 commit fad4785
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void init() {
throw new IllegalStateException("Cannot configure enpdoints", e);
}
}
endpoints.clientDetailsService(clientDetailsService);
endpoints.setClientDetailsService(clientDetailsService);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.CompositeTokenGranter;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
Expand Down Expand Up @@ -167,10 +169,10 @@ public AuthorizationServerEndpointsConfigurer accessTokenConverter(AccessTokenCo

public AuthorizationServerEndpointsConfigurer tokenServices(AuthorizationServerTokenServices tokenServices) {
this.tokenServices = tokenServices;
this.tokenServicesOverride = true;
this.tokenServicesOverride = true;
return this;
}

public boolean isTokenServicesOverride() {
return tokenServicesOverride;
}
Expand Down Expand Up @@ -229,9 +231,12 @@ public AuthorizationServerEndpointsConfigurer tokenGranter(TokenGranter tokenGra
return this;
}

public AuthorizationServerEndpointsConfigurer clientDetailsService(ClientDetailsService clientDetailsService) {
/**
* N.B. this method is not part of the public API. To set up a custom ClientDetailsService please use
* {@link AuthorizationServerConfigurerAdapter#configure(ClientDetailsServiceConfigurer)}.
*/
public void setClientDetailsService(ClientDetailsService clientDetailsService) {
this.clientDetailsService = clientDetailsService;
return this;
}

public AuthorizationServerEndpointsConfigurer requestFactory(OAuth2RequestFactory requestFactory) {
Expand Down Expand Up @@ -301,9 +306,9 @@ private AuthorizationServerTokenServices tokenServices() {
this.tokenServices = createDefaultTokenServices();
return tokenServices;
}

public AuthorizationServerTokenServices getDefaultAuthorizationServerTokenServices() {
if (defaultTokenServices !=null) {
if (defaultTokenServices != null) {
return defaultTokenServices;
}
this.defaultTokenServices = createDefaultTokenServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.springframework.security.oauth2.provider.approval.TokenApprovalStore;
import org.springframework.security.oauth2.provider.approval.UserApprovalHandler;
import org.springframework.security.oauth2.provider.client.ClientCredentialsTokenGranter;
import org.springframework.security.oauth2.provider.client.InMemoryClientDetailsService;
import org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
Expand Down Expand Up @@ -89,7 +90,8 @@ public static List<Object[]> parameters() {
new Object[] { null, new Class<?>[] { AuthorizationServerEncoder.class } },
new Object[] { null, new Class<?>[] { AuthorizationServerJwt.class } },
new Object[] { null, new Class<?>[] { AuthorizationServerWithTokenServices.class } },
new Object[] { null, new Class<?>[] { AuthorizationServerApproval.class } },
new Object[] { null, new Class<?>[] { AuthorizationServerApproval.class } },
new Object[] { null, new Class<?>[] { AuthorizationServerCustomClientDetails.class } },
new Object[] { BeanCreationException.class, new Class<?>[] { AuthorizationServerTypes.class } }
// @formatter:on
);
Expand Down Expand Up @@ -337,7 +339,7 @@ public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
.authorizedGrantTypes("client_credentials");
// @formatter:on
}

@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
oauthServer.passwordEncoder(new BCryptPasswordEncoder());
Expand Down Expand Up @@ -468,4 +470,25 @@ public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws E

}

@Configuration
@EnableWebMvcSecurity
@EnableAuthorizationServer
protected static class AuthorizationServerCustomClientDetails extends AuthorizationServerConfigurerAdapter
implements Runnable {

@Autowired
private ApplicationContext context;

@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.withClientDetails(new InMemoryClientDetailsService());
}

@Override
public void run() {
assertNotNull(context.getBean(ClientDetailsService.class));
}

}

}

0 comments on commit fad4785

Please sign in to comment.