Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. @Override
  2. public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
  3. Authentication authentication) throws IOException, ServletException {
  4.  
  5. clearAuthenticationAttributes(request);
  6. }
  7.  
  8. public List<GrantedAuthority> getUserAuthorities() {
  9. Object principals = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  10.  
  11. //Тут нужна эта проверка тк если сразу получить principals без проверки
  12. //На анонимность пользавателя можем получим NullPointerException
  13. if (!principals.toString().equals("anonymousUser")) {
  14. org.springframework.security.core.userdetails.User u =
  15. (org.springframework.security.core.userdetails.User)
  16. principals;
  17.  
  18. List<GrantedAuthority> authorities = new LinkedList();
  19. authorities.addAll(u.getAuthorities());
  20.  
  21. return authorities;
  22. }
  23.  
  24. return new List();
  25. }
  26.  
  27. @Override
  28. public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
  29. Authentication authentication) throws IOException, ServletException {
  30. for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
  31. String authority = grantedAuthority.getAuthority();
  32. }
  33. clearAuthenticationAttributes(request);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement