Advertisement
Guest User

Untitled

a guest
Dec 20th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.09 KB | None | 0 0
  1. 17:47:08,668 DEBUG SessionManagementFilter:124 - Requested session ID Lna1JBtS5foU2qDaGONIzBcGgvt94FTSneANgG77 is invalid.
  2. 17:47:08,670 DEBUG FilterSecurityInterceptor:219 - Secure object: FilterInvocation: URL: /api/user/update; Attributes: [hasAnyRole('ROLE_ANONYMOUS, USER')]
  3. 17:47:08,671 DEBUG ExceptionTranslationFilter:164 - Authentication exception occurred; redirecting to authentication entry point
  4. org.springframework.security.authentication.AuthenticationCredentialsNotFoundException: An Authentication object was not found in the SecurityContext
  5. at org.springframework.security.access.intercept.AbstractSecurityInterceptor.credentialsNotFound(AbstractSecurityInterceptor.java:379)
  6. at org.springframework.security.access.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:223)
  7. at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:124)
  8. at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
  9. at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
  10. at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
  11.  
  12. @Configuration
  13. @EnableWebSecurity
  14. public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
  15.  
  16. @Autowired
  17. private ClientDetailsService clientDetailsService;
  18.  
  19. @Autowired
  20. private MyAuthenticationProvider myAuthenticationProvider;
  21.  
  22. @Autowired
  23. public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
  24. auth.authenticationProvider(myAuthenticationProvider);
  25. }
  26.  
  27. @Override
  28. protected void configure(HttpSecurity http) throws Exception {
  29. http
  30. .csrf().disable()
  31. .anonymous().disable()
  32. .authorizeRequests()
  33. .antMatchers("/oauth/token", "/api/signup").permitAll()
  34. .anyRequest().hasAnyRole("ANONYMOUS, USER");
  35. }
  36.  
  37. @Override
  38. public void configure(WebSecurity web) throws Exception {
  39. web.ignoring().antMatchers("/api/signup");
  40. }
  41.  
  42. @Override
  43. @Bean
  44. public AuthenticationManager authenticationManagerBean() throws Exception {
  45. return super.authenticationManagerBean();
  46. }
  47.  
  48. @Bean
  49. public TokenStore tokenStore() {
  50. return new InMemoryTokenStore();
  51. }
  52.  
  53. @Bean
  54. public TokenStoreUserApprovalHandler userApprovalHandler() {
  55. TokenStoreUserApprovalHandler handler = new TokenStoreUserApprovalHandler();
  56. handler.setTokenStore(tokenStore());
  57. handler.setRequestFactory(new DefaultOAuth2RequestFactory(clientDetailsService));
  58. handler.setClientDetailsService(clientDetailsService);
  59. return handler;
  60. }
  61.  
  62. @Bean
  63. public ApprovalStore approvalStore() throws Exception {
  64. TokenApprovalStore store = new TokenApprovalStore();
  65. store.setTokenStore(tokenStore());
  66. return store;
  67. }
  68.  
  69. }
  70.  
  71. @Configuration
  72. @EnableAuthorizationServer
  73. public class AuthorizationServerConfiguration extends AuthorizationServerConfigurerAdapter {
  74.  
  75. private static String REALM = "ABCDEF";
  76.  
  77. @Autowired
  78. private UserApprovalHandler userApprovalHandler;
  79.  
  80. @Autowired
  81. @Qualifier("authenticationManagerBean")
  82. private AuthenticationManager authenticationManager;
  83.  
  84. @Override
  85. public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  86. clients.inMemory().withClient("user").secret("secret")
  87. .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
  88. .authorities("ROLE_CLIENT", "ROLE_TRUSTED_CLIENT").scopes("read", "write", "trust") //
  89. .accessTokenValiditySeconds(60 * 60 * 24 * 1) // Access token is only valid for 1 days.
  90. .refreshTokenValiditySeconds(60 * 60 * 24 * 30); // Refresh token is only valid for 30 days.
  91. }
  92.  
  93. @Override
  94. public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
  95. TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
  96. tokenEnhancerChain.setTokenEnhancers(Arrays.asList(tokenEnhancer(), accessTokenConverter()));
  97. endpoints.tokenEnhancer(tokenEnhancer()).userApprovalHandler(userApprovalHandler)
  98. .authenticationManager(authenticationManager);
  99. }
  100.  
  101. @Override
  102. public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
  103. oauthServer.tokenKeyAccess("permitAll()").checkTokenAccess("isAuthenticated()").realm(REALM);
  104. }
  105.  
  106. @Bean
  107. public TokenEnhancer tokenEnhancer() {
  108. return new MicroInvestTokenEnhancer();
  109. }
  110.  
  111. @Bean
  112. public JwtAccessTokenConverter accessTokenConverter() {
  113. JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  114. converter.setSigningKey("123456789");
  115. return converter;
  116. }
  117.  
  118. }
  119.  
  120. @Component("myAuthenticationProvider")
  121. public class MyAuthenticationProvider implements AuthenticationProvider {
  122.  
  123. @Autowired
  124. private LoginService loginService;
  125.  
  126. @Override
  127. public Authentication authenticate(Authentication authentication) throws AuthenticationException {
  128. MicroInvestAuthenticationToken auth = null;
  129. if (authentication != null) {
  130. final String username = authentication.getPrincipal().toString();
  131. final String password = authentication.getCredentials().toString();
  132. LoginResponse user = loginService.login(username, password);
  133. if (user != null) {
  134. final List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
  135. grantedAuthorities.add(new SimpleGrantedAuthority("USER"));
  136. auth = new MicroInvestAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), grantedAuthorities);
  137. auth.setUser(user);
  138. }
  139. }
  140. return auth;
  141. }
  142.  
  143. @Override
  144. public boolean supports(Class<?> authentication) {
  145. return (UsernamePasswordAuthenticationToken.class).isAssignableFrom(authentication);
  146. }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement