Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. @Configuration
  2. @EnableWebSecurity
  3. @EnableResourceServer
  4. public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
  5.  
  6. @Autowired
  7. public void configure(AuthenticationManagerBuilder auth) throws Exception {
  8. auth.inMemoryAuthentication()
  9. .withUser("admin").password("admin").roles("ROLE");
  10. }
  11.  
  12. @Override
  13. public void configure(HttpSecurity http) throws Exception {
  14. http.authorizeRequests()
  15. .antMatchers("/categorias").permitAll()
  16. .anyRequest().authenticated()
  17. .and()
  18. .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  19. .and()
  20. .csrf().disable();
  21. }
  22.  
  23. @Override
  24. public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
  25. resources.stateless(true);
  26. }
  27.  
  28. }
  29.  
  30. @Configuration
  31. @EnableAuthorizationServer
  32. public class AuthorizationServerConfig extends
  33. AuthorizationServerConfigurerAdapter {
  34.  
  35. @Autowired
  36. private AuthenticationManager authenticationManager;
  37.  
  38. @Override
  39. public void configure(ClientDetailsServiceConfigurer clients) throws
  40. Exception {
  41. clients.inMemory()
  42. .withClient("angular")
  43. .secret("@ngul@r0")
  44. .scopes("read", "write")
  45. .authorizedGrantTypes("password")
  46. .accessTokenValiditySeconds(1800);
  47. }
  48.  
  49. @Override
  50. public void configure(AuthorizationServerEndpointsConfigurer endpoints)
  51. throws Exception {
  52. endpoints
  53. .tokenStore(tokenStore())
  54. .accessTokenConverter(accessTokenConverter())
  55. .authenticationManager(authenticationManager);
  56. }
  57.  
  58. @Bean
  59. public JwtAccessTokenConverter accessTokenConverter() {
  60. JwtAccessTokenConverter accessTokenConverter = new
  61. JwtAccessTokenConverter();
  62. accessTokenConverter.setSigningKey("algaworks");
  63. return accessTokenConverter;
  64. }
  65.  
  66. @Bean
  67. public TokenStore tokenStore() {
  68. return new JwtTokenStore(accessTokenConverter());
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement