A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

5 years ago
5 years ago
5 years ago
  1. package org.ros.chatto.security;
  2. import java.io.IOException;
  3. import java.util.Collection;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.springframework.security.core.Authentication;
  8. import org.springframework.security.core.GrantedAuthority;
  9. import org.springframework.security.core.authority.SimpleGrantedAuthority;
  10. import org.springframework.security.web.DefaultRedirectStrategy;
  11. import org.springframework.security.web.RedirectStrategy;
  12. import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
  13. import org.springframework.stereotype.Component;
  14. @Component
  15. public class AuthenticationSuccessHandlerImpl
  16. implements AuthenticationSuccessHandler {
  17. private static final SimpleGrantedAuthority SUPER_USER_AUTHORITY = new SimpleGrantedAuthority(
  18. "ROLE_SUPER_USER");
  19. private static final SimpleGrantedAuthority ADMIN_AUTHORITY = new SimpleGrantedAuthority(
  20. "ROLE_ADMIN");
  21. private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();
  22. @Override
  23. public void onAuthenticationSuccess(HttpServletRequest httpServletRequest,
  24. HttpServletResponse httpServletResponse,
  25. Authentication authentication)
  26. throws IOException, ServletException {
  27. Collection<? extends GrantedAuthority> authorities = authentication
  28. .getAuthorities();
  29. if (authorities.contains(ADMIN_AUTHORITY)
  30. || authorities.contains(SUPER_USER_AUTHORITY)) {
  31. redirectStrategy.sendRedirect(httpServletRequest,
  32. httpServletResponse, "/admin");
  33. } else {
  34. redirectStrategy.sendRedirect(httpServletRequest,
  35. httpServletResponse, "/user");
  36. }
  37. }
  38. }