-1

following question: I'm using Javers in my Spring Boot project, and want to extract the commit author name.

The value of snapshots.get(0).getCommitMetadata().getAuthor() gives only something like TokenPayload@254d2bf.

The first idea was to set the AuthorProvider Bean

@Bean
public AuthorProvider authorProvider() {
  return new SpringSecurityAuthorProvider();
}

but it didn't help. No extra configuration is used, only the default one. Thank you in advance.

Javers Version: 5.8.9
Spring Boot Version: 1.5.8

1 Answers1

1

You need to provide the rigth AuthorProvider bean, which plays along with you Spring Security setup. SpringSecurityAuthorProvider which is provided by Javers is just the default implementation.

/**
 * Returns a current user name from Spring Security context
 */
public class SpringSecurityAuthorProvider implements AuthorProvider {
    @Override
    public String provide() {
        Authentication auth =  SecurityContextHolder.getContext().getAuthentication();

        if (auth == null) {
            return "unauthenticated";
        }

        return auth.getName();
    }
}
Bartek Walacik
  • 3,386
  • 1
  • 9
  • 14