|
|
@@ -87,45 +87,58 @@ public class UserController {
|
|
|
|
|
|
private void updateUserRoles(UserSaveReqVO reqVO) {
|
|
|
Set<Long> roleIds = new HashSet<>();
|
|
|
- if(reqVO.getRoleType().equals(CommonStatusEnum.ENABLE.getStatus())){
|
|
|
+ if (reqVO.getRoleType().equals(CommonStatusEnum.ENABLE.getStatus())) {
|
|
|
//可创建用户
|
|
|
roleIds.add(112L);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
//不可创建用户
|
|
|
roleIds.add(113L);
|
|
|
}
|
|
|
- permissionService.assignUserRole(reqVO.getId(),roleIds);
|
|
|
+ permissionService.assignUserRole(reqVO.getId(), roleIds);
|
|
|
}
|
|
|
|
|
|
private void updateUserClient(UserSaveReqVO reqVO) {
|
|
|
Set<Long> clientIds = reqVO.getAssociatedSystem();
|
|
|
- if(CollectionUtils.isNotEmpty(clientIds)){
|
|
|
- updateUserClientInfo(clientIds,reqVO.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(clientIds)) {
|
|
|
+ updateUserClientInfo(clientIds, reqVO.getId());
|
|
|
+ } else {
|
|
|
+ clearUserClientInfo(reqVO.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void updateUserClientInfo(Set<Long> clientIds,Long userId) {
|
|
|
+ private void clearUserClientInfo(Long userId) {
|
|
|
+ List<UserClientDO> clients = userClientService.getClientsByUserId(userId);
|
|
|
+ if (CollectionUtils.isNotEmpty(clients)) {
|
|
|
+ List<Long> removeIds = clients.stream().map(UserClientDO::getId).collect(Collectors.toList());
|
|
|
+ userClientService.removeByIds(removeIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateUserClientInfo(Set<Long> clientIds, Long userId) {
|
|
|
List<Long> addIds = new ArrayList<>();
|
|
|
// Long userId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
List<UserClientDO> clientsByUserId = userClientService.getClientsByUserId(userId);
|
|
|
List<Long> removeIds = new ArrayList<>();
|
|
|
List<Long> modifyIds = new ArrayList<>();
|
|
|
- if(CollectionUtils.isNotEmpty(clientsByUserId)){
|
|
|
- clientsByUserId.forEach(item->{
|
|
|
- if(clientIds.contains(item.getClientId())){
|
|
|
+ if (CollectionUtils.isNotEmpty(clientsByUserId)) {
|
|
|
+ clientsByUserId.forEach(item -> {
|
|
|
+ if (clientIds.contains(item.getClientId())) {
|
|
|
modifyIds.add(item.getClientId());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
removeIds.add(item.getId());
|
|
|
}
|
|
|
});
|
|
|
- addIds = clientIds.stream().filter(item->!modifyIds.contains(item)).collect(Collectors.toList());
|
|
|
- }else{
|
|
|
+ addIds = clientIds.stream().filter(item -> !modifyIds.contains(item)).collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
addIds = new ArrayList<>(clientIds);
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(addIds)){
|
|
|
+ if (CollectionUtils.isNotEmpty(removeIds)) {
|
|
|
+ userClientService.removeByIds(removeIds);
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(addIds)) {
|
|
|
List<UserClientDO> addDOs = new ArrayList<>();
|
|
|
UserClientDO tmpUserClientDO = null;
|
|
|
- for(Long addId:addIds){
|
|
|
+ for (Long addId : addIds) {
|
|
|
tmpUserClientDO = new UserClientDO();
|
|
|
tmpUserClientDO.setUserId(userId);
|
|
|
tmpUserClientDO.setClientId(addId);
|
|
|
@@ -143,6 +156,7 @@ public class UserController {
|
|
|
@Operation(summary = "修改用户")
|
|
|
@PreAuthorize("@ss.hasPermission('system:user:update')")
|
|
|
public CommonResult<Boolean> updateUser(@Valid @RequestBody UserSaveReqVO reqVO) {
|
|
|
+ //
|
|
|
userService.updateUser(reqVO);
|
|
|
//增加
|
|
|
updateUserClient(reqVO);
|
|
|
@@ -167,6 +181,14 @@ public class UserController {
|
|
|
return success(true);
|
|
|
}
|
|
|
|
|
|
+ @PutMapping("/reset-password")
|
|
|
+ @Operation(summary = "重置密码")
|
|
|
+ public CommonResult<Boolean> resetUserPassword(@Valid @RequestBody UserUpdatePasswordReqVO reqVO) {
|
|
|
+ Long loginUserId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
+ userService.updateUserPassword(loginUserId, reqVO.getPassword());
|
|
|
+ return success(true);
|
|
|
+ }
|
|
|
+
|
|
|
@PutMapping("/update-status")
|
|
|
@Operation(summary = "修改用户状态")
|
|
|
@PreAuthorize("@ss.hasPermission('system:user:update')")
|
|
|
@@ -259,61 +281,62 @@ public class UserController {
|
|
|
@GetMapping("/getLinkInfo")
|
|
|
@Operation(summary = "获得用户详情")
|
|
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
|
|
- public CommonResult<String> getLinkInfo(@RequestParam("linkId") Long linkId,@RequestParam("refreshToken") String refreshToken) {
|
|
|
+ public CommonResult<String> getLinkInfo(@RequestParam("linkId") Long linkId, @RequestParam("refreshToken") String refreshToken) {
|
|
|
String url = StringUtils.EMPTY;
|
|
|
Long userId = SecurityFrameworkUtils.getLoginUserId();
|
|
|
- if(Objects.nonNull(userId)){
|
|
|
+ if (Objects.nonNull(userId)) {
|
|
|
AdminUserDO user = userService.getUser(userId);
|
|
|
- if(Objects.isNull(user)){
|
|
|
+ if (Objects.isNull(user)) {
|
|
|
throw exception(USER_NOT_EXISTS);
|
|
|
- }else{
|
|
|
- if(user.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())){
|
|
|
- log.error(USER_IS_DISABLE.getMsg(),user.getUsername());
|
|
|
+ } else {
|
|
|
+ if (user.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
|
|
|
+ log.error(USER_IS_DISABLE.getMsg(), user.getUsername());
|
|
|
throw exception(USER_CLIENT_LINK_AUTH_ERROR);
|
|
|
}
|
|
|
- if(!user.getAssociatedSystem().contains(linkId)){
|
|
|
+ if (!user.getAssociatedSystem().contains(linkId)) {
|
|
|
log.error(USER_CLIENT_NOT_EXISTS.getMsg());
|
|
|
throw exception(USER_CLIENT_LINK_AUTH_ERROR);
|
|
|
}
|
|
|
OAuth2ClientDO oAuth2Client = oAuth2ClientService.getOAuth2Client(linkId);
|
|
|
- if(Objects.isNull(oAuth2Client)){
|
|
|
+ if (Objects.isNull(oAuth2Client)) {
|
|
|
log.error(USER_CLIENT_NOT_EXISTS.getMsg());
|
|
|
throw exception(USER_CLIENT_LINK_AUTH_ERROR);
|
|
|
}
|
|
|
UserClientDO userClient = userClientService.getUserClientByParam(userId, linkId);
|
|
|
- if(Objects.isNull(userClient)){
|
|
|
+ if (Objects.isNull(userClient)) {
|
|
|
log.error(USER_CLIENT_NOT_EXISTS.getMsg());
|
|
|
throw exception(USER_CLIENT_LINK_AUTH_ERROR);
|
|
|
}
|
|
|
- if(userClient.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())){
|
|
|
+ if (userClient.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
|
|
|
log.error(USER_CLIENT_STOP.getMsg());
|
|
|
throw exception(USER_CLIENT_LINK_AUTH_ERROR);
|
|
|
}
|
|
|
- if(userClient.getSyncStatus()==0 || userClient.getSyncStatus()==2){
|
|
|
+ if (userClient.getSyncStatus() == 0 || userClient.getSyncStatus() == 2) {
|
|
|
log.error(USER_NO_SYNC.getMsg());
|
|
|
throw exception(USER_CLIENT_LINK_AUTH_ERROR);
|
|
|
}
|
|
|
// 拼接数据
|
|
|
- url = constructLinkUrl(userClient,oAuth2Client,refreshToken,user);
|
|
|
+ url = constructLinkUrl(userClient, oAuth2Client, refreshToken, user);
|
|
|
}
|
|
|
}
|
|
|
return success(url);
|
|
|
}
|
|
|
|
|
|
- private String constructLinkUrl( UserClientDO userClient,OAuth2ClientDO oAuth2Client, String refreshToken, AdminUserDO user) {
|
|
|
+ private String constructLinkUrl(UserClientDO userClient, OAuth2ClientDO oAuth2Client, String refreshToken, AdminUserDO user) {
|
|
|
|
|
|
- if(oAuth2Client.getLinkMode()==0){
|
|
|
- return makeDefaultUrl(userClient,oAuth2Client,refreshToken,user.getUsername());
|
|
|
- }else if(oAuth2Client.getLinkMode()==1){
|
|
|
+ if (oAuth2Client.getLinkMode() == 0) {
|
|
|
+ return makeDefaultUrl(userClient, oAuth2Client, refreshToken, user.getUsername());
|
|
|
+ } else if (oAuth2Client.getLinkMode() == 1) {
|
|
|
//观远sso集成
|
|
|
- return makeGuanUrl(userClient,oAuth2Client,refreshToken,user);
|
|
|
- }else{
|
|
|
+ return makeGuanUrl(userClient, oAuth2Client, refreshToken, user);
|
|
|
+ } else {
|
|
|
return StringUtils.EMPTY;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 观远sso url
|
|
|
+ *
|
|
|
* @param userClient
|
|
|
* @param oAuth2Client
|
|
|
* @param refreshToken
|
|
|
@@ -329,25 +352,27 @@ public class UserController {
|
|
|
} catch (InvalidKeySpecException e) {
|
|
|
throw exception(USER_LINK_ERROR);
|
|
|
}
|
|
|
- String str = "{\"domainId\":\"guanbi\",\"externalUserId\":\""+ user.getUsername()+"\"}";
|
|
|
+ String str = "{\"domainId\":\"guanbi\",\"externalUserId\":\"" + user.getUsername() + "\"}";
|
|
|
String encodedData = GuanRsa.privateEncrypt(str, key);
|
|
|
- String token = GuanRsa.toHexString(encodedData);
|
|
|
- userClientService.updateTokenById(userClient.getId(),token);
|
|
|
- return oAuth2Client.getLoginUrl()+"?provider=guanbi&ssoToken="+token;
|
|
|
+ String token = GuanRsa.toHexString(encodedData);
|
|
|
+ userClientService.updateTokenById(userClient.getId(), token);
|
|
|
+ return oAuth2Client.getLoginUrl() + "?provider=guanbi&ssoToken=" + token;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 默认路径
|
|
|
+ *
|
|
|
* @param userClient
|
|
|
* @param oAuth2Client
|
|
|
* @param refreshToken
|
|
|
* @param loginUserName
|
|
|
* @return
|
|
|
*/
|
|
|
- private String makeDefaultUrl(UserClientDO userClient,OAuth2ClientDO oAuth2Client, String refreshToken, String loginUserName) {
|
|
|
+ private String makeDefaultUrl(UserClientDO userClient, OAuth2ClientDO oAuth2Client, String refreshToken, String loginUserName) {
|
|
|
String timestamp = System.currentTimeMillis() + "";
|
|
|
- String token = TransmitSecurityUtil.MD5(timestamp+loginUserName+oAuth2Client.getSecret());
|
|
|
- userClientService.updateTokenById(userClient.getId(),token);
|
|
|
- return oAuth2Client.getLoginUrl()+"?timestamp="+timestamp+"&user="+loginUserName+"&token="+token;
|
|
|
+ String token = TransmitSecurityUtil.MD5(timestamp + loginUserName + oAuth2Client.getSecret());
|
|
|
+ userClientService.updateTokenById(userClient.getId(), token);
|
|
|
+ return oAuth2Client.getLoginUrl() + "?timestamp=" + timestamp + "&user=" + loginUserName + "&token=" + token;
|
|
|
}
|
|
|
+
|
|
|
}
|