Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import org.springframework.data.domain.AuditorAware;
  2. import org.springframework.security.core.Authentication;
  3. import org.springframework.security.core.context.SecurityContextHolder;
  4.  
  5. public class SpringSecurityAuditor implements AuditorAware<String> {
  6.  
  7. @Override
  8. public String getCurrentAuditor() {
  9.  
  10. Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  11.  
  12. if (authentication == null || authentication.getPrincipal().equals("anonymousUser")) {
  13.  
  14. return authentication.getPrincipal().toString();
  15. }
  16.  
  17. return ((UsuarioLogado) authentication.getPrincipal()).getUsername();
  18. }
  19.  
  20. }
  21.  
  22. @Override
  23. public Optional<String> getCurrentAuditor() {
  24.  
  25. Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
  26.  
  27. if (authentication == null || authentication.getPrincipal().equals("anonymousUser")) {
  28.  
  29. return (Optional<String>) authentication.getPrincipal();
  30. }
  31. return ... código a ser implementado...
  32. }
Add Comment
Please, Sign In to add comment