Guest User

Untitled

a guest
Dec 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. @Autowired
  2. private ClientServiceImpl clientServiceImpl;
  3.  
  4. @Autowired
  5. private DataSource dataSource;
  6.  
  7. @Autowired
  8. private TokenStore tokenStore;
  9.  
  10. @Autowired
  11. private JwtAccessTokenConverter jwtTokenEnhancer;
  12.  
  13. @Autowired
  14. private UserApprovalHandler userApprovalHandler;
  15.  
  16. @Autowired
  17. @Qualifier("authenticationManagerBean")
  18. private AuthenticationManager authenticationManager;
  19.  
  20. @Override
  21. public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  22. clients.jdbc(dataSource);
  23. }
  24.  
  25. @Override
  26. public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  27. endpoints.tokenStore(tokenStore).tokenEnhancer(jwtTokenEnhancer).userApprovalHandler(userApprovalHandler)
  28. .authenticationManager(authenticationManager)
  29. .userDetailsService(clientServiceImpl);
  30. }
  31.  
  32. @Override
  33. public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
  34. oauthServer.allowFormAuthenticationForClients();
  35. }
  36.  
  37. }
  38.  
  39. @Configuration
  40. @EnableResourceServer
  41. public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
  42.  
  43. private static final String RESOURCE_ID = "resource_id";
  44.  
  45. @Override
  46. public void configure(ResourceServerSecurityConfigurer resources) {
  47. resources.resourceId(RESOURCE_ID).stateless(false);
  48. }
  49.  
  50. @Override
  51. public void configure(HttpSecurity http) throws Exception {
  52.  
  53. http
  54. .anonymous().disable()
  55. .authorizeRequests()
  56. .antMatchers("/client/about").access("hasRole('CLIENT') or hasRole('ROLE_CLIENT')")
  57.  
  58. .and().exceptionHandling().accessDeniedHandler(new OAuth2AccessDeniedHandler());
  59. }
  60.  
  61. }
  62.  
  63. @Autowired
  64. private ClientDetailsService clientDetailsService;
  65.  
  66. @Autowired
  67. @Resource(name = "userService")
  68. private ClientServiceImpl clientServiceImpl;
  69.  
  70.  
  71. @Bean
  72. public PasswordEncoder passwordEncoder() {
  73. return new BCryptPasswordEncoder();
  74. }
  75.  
  76. @Override
  77. @Bean
  78. public AuthenticationManager authenticationManagerBean() throws Exception {
  79. return super.authenticationManagerBean();
  80. }
  81.  
  82. @Bean
  83. public TokenStore tokenStore() {
  84. return new JwtTokenStore(jwtTokenEnhancer());
  85. }
  86.  
  87. @Bean
  88. protected JwtAccessTokenConverter jwtTokenEnhancer() {
  89. JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  90. converter.setSigningKey("Demo-Key-1");
  91.  
  92. return converter;
  93. }
  94.  
  95. @Bean
  96. @Autowired
  97. public TokenStoreUserApprovalHandler userApprovalHandler(TokenStore tokenStore) {
  98. TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler();
  99. handler.setTokenStore(tokenStore);
  100. handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
  101. handler.setClientDetailsService(clientDetailsService);
  102. return handler;
  103. }
  104.  
  105. @Bean
  106. @Autowired
  107. public ApprovalStore approvalStore(TokenStore tokenStore) throws Exception {
  108. TokenApprovalStore store = new TokenApprovalStore();
  109. store.setTokenStore(tokenStore);
  110. return store;
  111. }
  112.  
  113. @Override
  114. protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  115. auth.userDetailsService(clientServiceImpl)
  116. .passwordEncoder(passwordEncoder());
  117. }
  118.  
  119.  
  120. @Override
  121. @Order(Ordered.HIGHEST_PRECEDENCE)
  122. protected void configure(HttpSecurity http) throws Exception {
  123. http
  124. .csrf().disable()
  125. .authorizeRequests()
  126. .antMatchers("/client/registration", "/oauth/token", "/client/login", "/actuator/health", "/actuator/info", "/swagger-ui").permitAll()
  127. .anyRequest().authenticated()// когда включаю это форма логина перестает работат;
  128. .and()
  129. .formLogin()
  130. .and()
  131. .httpBasic().disable();
  132. }
Add Comment
Please, Sign In to add comment