Javers 提交作者姓名 [英] Javers commit author name

查看:67
本文介绍了Javers 提交作者姓名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下问题:我在 Spring Boot 项目中使用 Javers,并想提取提交作者姓名.

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

snapshots.get(0).getCommitMetadata().getAuthor() 的值只给出了类似 TokenPayload@254d2bf 的东西.

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

第一个想法是设置 AuthorProvider Bean

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

推荐答案

您需要提供严格的 AuthorProvider bean,它与您的 Spring Security 设置一起发挥作用.Javers 提供的 SpringSecurityAuthorProvider 只是默认实现.

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();
    }
}

这篇关于Javers 提交作者姓名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆