|
|
@@ -11,12 +11,15 @@ import cn.reghao.autodop.dmaster.auth.entity.UserAuth;
|
|
|
import cn.reghao.autodop.dmaster.auth.repository.PermissionRepository;
|
|
|
import cn.reghao.autodop.dmaster.auth.repository.RoleRepository;
|
|
|
import cn.reghao.autodop.dmaster.auth.repository.UserAuthRepository;
|
|
|
+import cn.reghao.autodop.dmaster.auth.vo.UserAuthVO;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.security.core.GrantedAuthority;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -74,31 +77,28 @@ public class UserService {
|
|
|
}
|
|
|
break;
|
|
|
case 3:
|
|
|
- UserAuth userAuth = (UserAuth) JsonUtil.jsonToObject(json, UserAuth.class);
|
|
|
- String password = userAuth.getPassword();
|
|
|
- String salt = Salt.get(64);
|
|
|
- String encryptedPwd = cryptor.encrypt(password + salt);
|
|
|
- userAuth.setPassword(encryptedPwd);
|
|
|
- userAuth.setSalt(salt);
|
|
|
- String roleName = rolePrefix + userAuth.getRole().getName();
|
|
|
- Role roleEntity2 = roleRepository.findRoleByName(roleName);
|
|
|
- if (roleEntity2 != null) {
|
|
|
- userAuth.setRole(roleEntity2);
|
|
|
- } else {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ UserAuthVO vo = (UserAuthVO) JsonUtil.jsonToObject(json, UserAuthVO.class);
|
|
|
+ UserAuth userAuth = vo.to();
|
|
|
UserAuth authEntity = userAuthRepository.findUserAuthByUsername(userAuth.getUsername());
|
|
|
if (authEntity == null) {
|
|
|
+ String password = userAuth.getPassword();
|
|
|
+ String salt = Salt.get(64);
|
|
|
+ String encryptedPwd = cryptor.encrypt(password + salt);
|
|
|
+ userAuth.setPassword(encryptedPwd);
|
|
|
+ userAuth.setSalt(salt);
|
|
|
userAuthRepository.save(userAuth);
|
|
|
} else {
|
|
|
- authEntity.setPassword(userAuth.getPassword());
|
|
|
- authEntity.setSalt(salt);
|
|
|
- authEntity.setRole(userAuth.getRole());
|
|
|
+ if (!authEntity.getPassword().equals(userAuth.getPassword())) {
|
|
|
+ String password = userAuth.getPassword();
|
|
|
+ String salt = Salt.get(64);
|
|
|
+ String encryptedPwd = cryptor.encrypt(password + salt);
|
|
|
+ authEntity.setPassword(encryptedPwd);
|
|
|
+ authEntity.setSalt(salt);
|
|
|
+ }
|
|
|
+ authEntity.setAuthorities(userAuth.authorities());
|
|
|
authEntity.setUpdateTime(LocalDateTime.now());
|
|
|
userAuthRepository.save(authEntity);
|
|
|
}
|
|
|
-
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
@@ -135,23 +135,13 @@ public class UserService {
|
|
|
return permissionPageList;
|
|
|
case 3:
|
|
|
Page<UserAuth> userAuthPage = userAuthRepository.findAll(pageRequest);
|
|
|
- PageList<UserAuth> userAuthPageList = new PageList<>();
|
|
|
- userAuthPageList.setTotalSize(userAuthPage.getTotalElements());
|
|
|
- userAuthPageList.setTotalPages(userAuthPage.getTotalPages());
|
|
|
- userAuthPageList.setList(userAuthPage.getContent().stream()
|
|
|
- .peek(userAuth -> {
|
|
|
- // Role 是一个共享实体
|
|
|
- Role role = userAuth.getRole();
|
|
|
- /* TODO 数组越界异常后会返回 401,而不是 500
|
|
|
- String name = role.getName().split(rolePrefix)[1];
|
|
|
- role.setName(name);*/
|
|
|
- if (role.getName().contains(rolePrefix)) {
|
|
|
- String name = role.getName().split(rolePrefix)[1];
|
|
|
- role.setName(name);
|
|
|
- }
|
|
|
- }).collect(Collectors.toList()));
|
|
|
-
|
|
|
- return userAuthPageList;
|
|
|
+ PageList<UserAuthVO> userAuthVOPageList = new PageList<>();
|
|
|
+ userAuthVOPageList.setTotalSize(userAuthPage.getTotalElements());
|
|
|
+ userAuthVOPageList.setTotalPages(userAuthPage.getTotalPages());
|
|
|
+ userAuthVOPageList.setList(userAuthPage.getContent().stream()
|
|
|
+ .map(UserAuthVO::new)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ return userAuthVOPageList;
|
|
|
default:
|
|
|
return null;
|
|
|
}
|