Spring boot 如何使用jhipster的审核系统审核密码更改?
当用户登录或输入错误密码时,Jhister应用程序会生成审核事件。 我想使用相同的系统在用户更改密码或管理员用户更改另一用户的数据时生成事件。 我该如何称呼审计系统? 我目前的想法是在changePassword rest api调用中调用一个方法,并在该方法中执行与Spring boot 如何使用jhipster的审核系统审核密码更改?,spring-boot,jhipster,Spring Boot,Jhipster,当用户登录或输入错误密码时,Jhister应用程序会生成审核事件。 我想使用相同的系统在用户更改密码或管理员用户更改另一用户的数据时生成事件。 我该如何称呼审计系统? 我目前的想法是在changePassword rest api调用中调用一个方法,并在该方法中执行与CustomAuditEventRepositoryIntTest.addAuditEvent Map<String, Object> data = new HashMap<>(); data
CustomAuditEventRepositoryIntTest.addAuditEvent
Map<String, Object> data = new HashMap<>();
data.put("password-strength", "weak");
AuditEvent event = new AuditEvent(
loginUsername,
"PASSWORD_CHANGE",
data);
customAuditEventRepository.add(event);
Map data=newhashmap();
data.put(“密码强度”、“弱”);
AuditEvent=新的AuditEvent(
罗吉努瑟纳姆酒店,
“密码更改”,
数据);
customAuditEventRepository.add(事件);
我需要更改CustomAuditEventRepository
还是创建自己的版本?还是只使用PersistenceAuditEventRepository
?
是否有一种特殊的魔法配置,可以自动调用审计,或者我只是在rest api方法中调用它?我按照Gaël Marziou的建议解决了这个问题: 我发布一个事件,框架负责将其存储到存储库中(或执行其他操作,具体取决于侦听器的配置) 在我的用户服务中,我添加了以下内容:
...
private ApplicationEventPublisher applicationEventPublisher;
...
private void auditPasswordChange( User user ) {
applicationEventPublisher.publishEvent(
new AuditApplicationEvent(
user.getLogin(), AUDIT_PASSWORD_CHANGE, "message=Changed by own user")
);
}
...
public void changePassword(String password) {
...
auditPasswordChange(user);
}
在UserService中,发布事件,spring boot actuator会将它们保存到存储库中。