Advertisement
Guest User

Untitled

a guest
Jul 10th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1. @Configuration
  2. @EnableAuthorizationServer
  3. public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
  4.     @Autowired
  5.     private AuthenticationManager authenticationManager;
  6.  
  7.     @Autowired
  8.     private UserService userDetailsService;
  9.  
  10.     @Autowired
  11.     private PasswordEncoder passwordEncoder;
  12.  
  13.     @Autowired
  14.     private DataSource dataSource;
  15.  
  16.     @Bean
  17.     public TokenStore tokenStore() {
  18.         return new JdbcTokenStore(dataSource);
  19.     }
  20.  
  21.     @Bean
  22.     public DefaultTokenServices tokenServices() {
  23.         DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
  24.         defaultTokenServices.setTokenStore(tokenStore());
  25.         defaultTokenServices.setSupportRefreshToken(true);
  26.         defaultTokenServices.setReuseRefreshToken(true);
  27.         return defaultTokenServices;
  28.     }
  29.  
  30.     @Bean
  31.     public OAuth2AccessDeniedHandler oauthAccessDeniedHandler() {
  32.         return new OAuth2AccessDeniedHandler();
  33.     }
  34.  
  35.     @Override
  36.     public void configure(AuthorizationServerSecurityConfigurer security) throws Exception {
  37.         security.allowFormAuthenticationForClients().tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()").passwordEncoder(passwordEncoder);
  38.     }
  39.  
  40.     @Override
  41.     public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  42.         clients.withClientDetails(new JdbcClientDetailsService(dataSource));
  43.     }
  44.     @Override
  45.     public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
  46.         endpoints.tokenServices(tokenServices()).authenticationManager(authenticationManager).userDetailsService(userDetailsService);
  47.     }
  48.    
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement