SecurityContextHolder.getContext().getAuthentication() always return 'anonymousUser'

I created Spring boot application with the following configuration:

  • Spring boot 2.1.0.RELEASE
  • OpenJdk 11

I have an AuditConfiguration class in my project that looks like:

@EnableJpaAuditing(auditorAwareRef = "auditorProvider")
public class AuditConfiguration {

    public AuditorAware<String> auditorProvider() {
        return new AuditorAwareImpl();

    class AuditorAwareImpl implements AuditorAware<String> {
        public Optional<String> getCurrentAuditor() {
            Principal principal = 
            return Optional.of(principal.getName());

and SecurityContextHolder.getContext().getAuthentication() always returns anonymousUser.

However, the following code returns the correct user name.

public class HistoryEndpoint {

    @RequestMapping(value = "/username", method = RequestMethod.GET)
    public String currentUserName(Principal principal) {
        return principal.getName();

I need your help for resolving this issue.