Created
February 22, 2015 15:32
-
-
Save marcoleong/111d7ae40cc15582cca9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ums.security; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
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.config.annotation.web.configuration.EnableAuthorizationServer; | |
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer; | |
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; | |
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; | |
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; | |
/** | |
* Created by leongmarco on 22/02/15. | |
*/ | |
@Configuration | |
@EnableAuthorizationServer | |
class OAuth2Config extends AuthorizationServerConfigurerAdapter { | |
@Autowired | |
private AuthenticationManager authenticationManager; | |
@Bean | |
public JwtAccessTokenConverter accessTokenConverter() { | |
return new JwtAccessTokenConverter(); | |
} | |
@Override | |
public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { | |
oauthServer.tokenKeyAccess("isAnonymous() || hasAuthority('ROLE_TRUSTED_CLIENT')").checkTokenAccess( | |
"hasAuthority('ROLE_TRUSTED_CLIENT')"); | |
} | |
@Override | |
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { | |
endpoints.authenticationManager(authenticationManager).accessTokenConverter(accessTokenConverter()); | |
} | |
@Override | |
public void configure(ClientDetailsServiceConfigurer clients) throws Exception { | |
// @formatter:off | |
clients.inMemory() | |
.withClient("my-client-with-secret") | |
.authorizedGrantTypes("password") | |
.authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT") | |
.scopes("read", "write") | |
.secret("secret"); | |
// @formatter:on | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment