Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.data.domain.AuditorAware;
- import org.springframework.security.core.Authentication;
- import org.springframework.security.core.context.SecurityContextHolder;
- public class SpringSecurityAuditor implements AuditorAware<String> {
- @Override
- public String getCurrentAuditor() {
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
- if (authentication == null || authentication.getPrincipal().equals("anonymousUser")) {
- return authentication.getPrincipal().toString();
- }
- return ((UsuarioLogado) authentication.getPrincipal()).getUsername();
- }
- }
- @Override
- public Optional<String> getCurrentAuditor() {
- Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
- if (authentication == null || authentication.getPrincipal().equals("anonymousUser")) {
- return (Optional<String>) authentication.getPrincipal();
- }
- return ... código a ser implementado...
- }
Add Comment
Please, Sign In to add comment