org.springframework.data.domain.AuditorAwareName Maven / Gradle / Ivy
package org.springframework.data.domain;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
public class AuditorAwareName implements AuditorAware {
@Override
public String getCurrentAuditor() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null && authentication.isAuthenticated() && !(authentication instanceof AnonymousAuthenticationToken)) {
return authentication.getName();
}
return null;
}
}