|
@@ -15,12 +15,14 @@ import org.hswebframework.web.service.AbstractService;
|
|
import org.hswebframework.web.service.DefaultDSLQueryService;
|
|
import org.hswebframework.web.service.DefaultDSLQueryService;
|
|
import org.hswebframework.web.service.DefaultDSLUpdateService;
|
|
import org.hswebframework.web.service.DefaultDSLUpdateService;
|
|
import org.hswebframework.web.service.authorization.*;
|
|
import org.hswebframework.web.service.authorization.*;
|
|
|
|
+import org.hswebframework.web.service.authorization.events.UserPasswordModifiedEvent;
|
|
import org.hswebframework.web.validate.ValidationException;
|
|
import org.hswebframework.web.validate.ValidationException;
|
|
import org.hswebframework.utils.ListUtils;
|
|
import org.hswebframework.utils.ListUtils;
|
|
import org.hswebframework.web.validator.group.CreateGroup;
|
|
import org.hswebframework.web.validator.group.CreateGroup;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
import org.springframework.cache.annotation.Caching;
|
|
import org.springframework.cache.annotation.Caching;
|
|
|
|
+import org.springframework.context.ApplicationEventPublisher;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.Assert;
|
|
import org.springframework.util.Assert;
|
|
@@ -62,6 +64,9 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
|
|
@Autowired
|
|
@Autowired
|
|
private RoleDao roleDao;
|
|
private RoleDao roleDao;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ApplicationEventPublisher publisher;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public String encodePassword(String password, String salt) {
|
|
public String encodePassword(String password, String salt) {
|
|
return passwordEncoder.encode(password, salt);
|
|
return passwordEncoder.encode(password, salt);
|
|
@@ -177,10 +182,11 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
|
|
//修改密码
|
|
//修改密码
|
|
if (StringUtils.hasLength(userEntity.getPassword())) {
|
|
if (StringUtils.hasLength(userEntity.getPassword())) {
|
|
//密码强度验证
|
|
//密码强度验证
|
|
- tryValidateProperty(usernameValidator, UserEntity.password, userEntity.getPassword());
|
|
|
|
|
|
+ tryValidateProperty(passwordStrengthValidator, UserEntity.password, userEntity.getPassword());
|
|
//密码MD5
|
|
//密码MD5
|
|
userEntity.setPassword(encodePassword(userEntity.getPassword(), oldUser.getSalt()));
|
|
userEntity.setPassword(encodePassword(userEntity.getPassword(), oldUser.getSalt()));
|
|
updateProperties.add(UserEntity.password);
|
|
updateProperties.add(UserEntity.password);
|
|
|
|
+
|
|
}
|
|
}
|
|
//修改数据
|
|
//修改数据
|
|
DefaultDSLUpdateService.createUpdate(getDao(), userEntity)
|
|
DefaultDSLUpdateService.createUpdate(getDao(), userEntity)
|
|
@@ -194,6 +200,9 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
|
|
//同步角色信息
|
|
//同步角色信息
|
|
trySyncUserRole(userEntity.getId(), bindRoleUserEntity.getRoles());
|
|
trySyncUserRole(userEntity.getId(), bindRoleUserEntity.getRoles());
|
|
}
|
|
}
|
|
|
|
+ if (updateProperties.contains(UserEntity.password)) {
|
|
|
|
+ publisher.publishEvent(new UserPasswordModifiedEvent(userId));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -220,11 +229,14 @@ public class SimpleUserService extends AbstractService<UserEntity, String>
|
|
if (!userEntity.getPassword().equals(oldPassword)) {
|
|
if (!userEntity.getPassword().equals(oldPassword)) {
|
|
throw new ValidationException("{old_password_error}", "password");
|
|
throw new ValidationException("{old_password_error}", "password");
|
|
}
|
|
}
|
|
|
|
+ tryValidateProperty(passwordStrengthValidator, UserEntity.password, newPassword);
|
|
|
|
+
|
|
newPassword = encodePassword(newPassword, userEntity.getSalt());
|
|
newPassword = encodePassword(newPassword, userEntity.getSalt());
|
|
DefaultDSLUpdateService.createUpdate(getDao())
|
|
DefaultDSLUpdateService.createUpdate(getDao())
|
|
.set(UserEntity.password, newPassword)
|
|
.set(UserEntity.password, newPassword)
|
|
.where(GenericEntity.id, userId)
|
|
.where(GenericEntity.id, userId)
|
|
.exec();
|
|
.exec();
|
|
|
|
+ publisher.publishEvent(new UserPasswordModifiedEvent(userId));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|