我正在使用 picketlink 对项目中的用户进行身份验证。我还创建了一个 @produces 注释方法,因此我可以在其他地方注入经过身份验证的用户。现在,我正在使用 envers,除了默认信息之外,我还想存储执行该操作的用户,但我无法将它注入到 envers 侦听器中。它始终为空。我怎样才能进行这种注射,或检索这些信息?
生产者类:
@SessionScoped
public class Resources implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private AuthenticationManagerBean authenticator;
@Inject
private Identity credentials;
@CurrentUser
private AuthenticatedUser currentUser;
@Produces
@CurrentUser
@SessionScoped
private AuthenticatedUser createAuthenticatedUser() {
AuthenticatedUser user = new AuthenticatedUser();
org.picketlink.idm.model.basic.User loggedInUser = (org.picketlink.idm.model.basic.User) credentials.getAccount();
User pu = authenticator.getUserRoles(loggedInUser.getLoginName());
if (pu != null) {
user.setUser(pu.getName());
for (Role role : pu.getRoles()) {
user.getRoles().add(role.getName());
}
}
return user;
}
@Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
和 envers 监听器:
public class AuditListener implements RevisionListener, Serializable {
private static final long serialVersionUID = 1L;
@Inject
@CurrentUser
private AuthenticatedUser identity; //this is always null
public void newRevision(Object revisionEntity) {
System.out.println(identity.getUser());
}
}