|
|
@@ -13,13 +13,7 @@ import com.inspur.customer.constant.Constant;
|
|
|
import com.inspur.customer.object.keycloak.KeycloakUserCO;
|
|
|
import com.inspur.customer.object.keycloak.SwitchDTO;
|
|
|
import com.inspur.customer.object.keycloak.UsersRoleMappingDTO;
|
|
|
-import com.inspur.customer.object.org.SmsbDepartmentCmd;
|
|
|
-import com.inspur.customer.object.org.SmsbRegrouping;
|
|
|
-import com.inspur.customer.object.org.SmsbSimpleUserCO;
|
|
|
-import com.inspur.customer.object.org.SmsbUserAdd;
|
|
|
-import com.inspur.customer.object.org.SmsbUserExceptionLevelUpdate;
|
|
|
-import com.inspur.customer.object.org.SmsbUserMigration;
|
|
|
-import com.inspur.customer.object.org.SmsbUserUpdate;
|
|
|
+import com.inspur.customer.object.org.*;
|
|
|
import com.inspur.customer.object.wechat.SubscribeDto;
|
|
|
import com.inspur.logging.annotation.SmsbMethodLog;
|
|
|
import com.inspur.logging.annotation.SmsbSysLog;
|
|
|
@@ -54,10 +48,11 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
-@SmsbSysLog(value = 3,description = "用户管理控制器")
|
|
|
+@SmsbSysLog(value = 3, description = "用户管理控制器")
|
|
|
@EnableScheduling
|
|
|
public class KeycloakUserController {
|
|
|
|
|
|
+ private static final String SWITCH_FLAG = "true";
|
|
|
@DubboReference
|
|
|
private KeycloakService keycloakService;
|
|
|
@DubboReference
|
|
|
@@ -70,26 +65,27 @@ public class KeycloakUserController {
|
|
|
private SmsbDepartmentService departmentService;
|
|
|
@DubboReference
|
|
|
private SmsbLogService smsbLogService;
|
|
|
+ @Value("${keycloak.askUser.switch}")
|
|
|
+ private String askUserSwitch;
|
|
|
|
|
|
- @SmsbMethodLog(description = "公众号扫描关注",business = "公众号关注")
|
|
|
+ @SmsbMethodLog(description = "公众号扫描关注", business = "公众号关注")
|
|
|
@PostMapping("/keycloak/update/user")
|
|
|
- public Response updateUser(@RequestBody String json){
|
|
|
+ public Response updateUser(@RequestBody String json) {
|
|
|
SubscribeDto subscribe = JSONObject.parseObject(json, SubscribeDto.class);
|
|
|
- if(StringUtils.isEmpty(subscribe.getUserId())){
|
|
|
- return Response.buildFailure("404","userId不能为空!");
|
|
|
+ if (StringUtils.isEmpty(subscribe.getUserId())) {
|
|
|
+ return Response.buildFailure("404", "userId不能为空!");
|
|
|
}
|
|
|
keycloakService.updateAttribute(subscribe.getUserId(), "wechat", subscribe.getOppenId());
|
|
|
return Response.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "公众号二维码展示" , business = "公众号二维码获取")
|
|
|
+ @SmsbMethodLog(description = "公众号二维码展示", business = "公众号二维码获取")
|
|
|
@GetMapping("/keycloak/query/ticket/{userId}")
|
|
|
- public SingleResponse getTicket(@PathVariable("userId") String userId,
|
|
|
- @RequestHeader("Authorization") String authorization) {
|
|
|
+ public SingleResponse getTicket(@PathVariable("userId") String userId, @RequestHeader("Authorization") String authorization) {
|
|
|
return SingleResponse.of(iWeChatService.queryTicket(appKey, userId, authorization));
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "密码重置" , business = "密码重置")
|
|
|
+ @SmsbMethodLog(description = "密码重置", business = "密码重置")
|
|
|
@PutMapping("/keycloak/changePassword")
|
|
|
public Response changePassword(@RequestHeader("userId") String userId, String newPassword) {
|
|
|
if (StringUtils.isEmpty(userId)) {
|
|
|
@@ -102,45 +98,47 @@ public class KeycloakUserController {
|
|
|
@SysLogIgnore
|
|
|
@Scheduled(cron = "0 0/10 * * * ?")
|
|
|
public void askUserOppenId() {
|
|
|
- log.info("update wechat openId");
|
|
|
- for (String userId : keycloakService.getUserMap().keySet()) {
|
|
|
- String oppenId = iWeChatService.askUser(userId);
|
|
|
- if (!StringUtils.isEmpty(oppenId)) {
|
|
|
- SubscribeDto dto = new SubscribeDto();
|
|
|
- dto.setUserId(userId);
|
|
|
- dto.setOppenId(oppenId);
|
|
|
- this.updateUser(JSONObject.toJSONString(dto));
|
|
|
+ if (SWITCH_FLAG.equals(askUserSwitch)) {
|
|
|
+ log.info("update wechat openId");
|
|
|
+ for (String userId : keycloakService.getUserMap().keySet()) {
|
|
|
+ String oppenId = iWeChatService.askUser(userId);
|
|
|
+ if (!StringUtils.isEmpty(oppenId)) {
|
|
|
+ SubscribeDto dto = new SubscribeDto();
|
|
|
+ dto.setUserId(userId);
|
|
|
+ dto.setOppenId(oppenId);
|
|
|
+ this.updateUser(JSONObject.toJSONString(dto));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "密码重置" ,business = "用户【${credential.userLabel}】密码重置")
|
|
|
+ @SmsbMethodLog(description = "密码重置", business = "用户【${credential.userLabel}】密码重置")
|
|
|
@PutMapping("/admin/users/{userId}/resetPassword")
|
|
|
- public Response resetPassword(@PathVariable("userId") String userId , @RequestBody CredentialRepresentation credential){
|
|
|
- if(StringUtils.isEmpty(credential.getType()) || !credential.getType().equals(Constant.type)){
|
|
|
- return Response.buildFailure("500","type参数不合法!");
|
|
|
+ public Response resetPassword(@PathVariable("userId") String userId, @RequestBody CredentialRepresentation credential) {
|
|
|
+ if (StringUtils.isEmpty(credential.getType()) || !credential.getType().equals(Constant.type)) {
|
|
|
+ return Response.buildFailure("500", "type参数不合法!");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(credential.getValue())){
|
|
|
- return Response.buildFailure("500","value不能为空!");
|
|
|
+ if (StringUtils.isEmpty(credential.getValue())) {
|
|
|
+ return Response.buildFailure("500", "value不能为空!");
|
|
|
}
|
|
|
- return keycloakService.updateUser(userId , credential , Constant.RESET_PASSWORD);
|
|
|
+ return keycloakService.updateUser(userId, credential, Constant.RESET_PASSWORD);
|
|
|
}
|
|
|
|
|
|
@SysLogIgnore
|
|
|
@PutMapping("/admin/users/role/configure")
|
|
|
- public Response roleMapping(@RequestHeader String userId ,@RequestBody UsersRoleMappingDTO usersRoleMappingDTO){
|
|
|
+ public Response roleMapping(@RequestHeader String userId, @RequestBody UsersRoleMappingDTO usersRoleMappingDTO) {
|
|
|
// 注解的方式不好描述日志信息,接口方式存储
|
|
|
SmsbLogDto logDto = new SmsbLogDto();
|
|
|
logDto.setUserId(userId);
|
|
|
logDto.setBusiness(3);
|
|
|
logDto.setDescription("账号角色分配");
|
|
|
String userName = keycloakService.getUserMap().get(usersRoleMappingDTO.getUserId());
|
|
|
- StringBuffer sbf = new StringBuffer("给用户:"+ (StringUtils.isNotEmpty(userName) ? userName : usersRoleMappingDTO.getUserId()));
|
|
|
- if(CollectionUtils.isNotEmpty(usersRoleMappingDTO.getAddRoleList())){
|
|
|
- sbf.append(",分配角色:"+getRoleNameList(usersRoleMappingDTO.getAddRoleList()));
|
|
|
+ StringBuffer sbf = new StringBuffer("给用户:" + (StringUtils.isNotEmpty(userName) ? userName : usersRoleMappingDTO.getUserId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(usersRoleMappingDTO.getAddRoleList())) {
|
|
|
+ sbf.append(",分配角色:" + getRoleNameList(usersRoleMappingDTO.getAddRoleList()));
|
|
|
}
|
|
|
- if(CollectionUtils.isNotEmpty(usersRoleMappingDTO.getRemoveRoleList())){
|
|
|
- sbf.append(",删除角色:"+getRoleNameList(usersRoleMappingDTO.getRemoveRoleList()));
|
|
|
+ if (CollectionUtils.isNotEmpty(usersRoleMappingDTO.getRemoveRoleList())) {
|
|
|
+ sbf.append(",删除角色:" + getRoleNameList(usersRoleMappingDTO.getRemoveRoleList()));
|
|
|
}
|
|
|
logDto.setParams(sbf.toString());
|
|
|
logDto.setRequestMethod(1);
|
|
|
@@ -149,7 +147,7 @@ public class KeycloakUserController {
|
|
|
logDto.setIp(NetUtils.getIpAddr(HttpContextUtils.getHttpServletRequest()));
|
|
|
logDto.setOperTime(LocalDateTime.now());
|
|
|
logDto.setTenant("unknown");
|
|
|
- log.info("账号角色分配日志记录:{}" , sbf);
|
|
|
+ log.info("账号角色分配日志记录:{}", sbf);
|
|
|
smsbLogService.saveLog(logDto);
|
|
|
return keycloakService.roleMapping(usersRoleMappingDTO);
|
|
|
}
|
|
|
@@ -162,39 +160,38 @@ public class KeycloakUserController {
|
|
|
|
|
|
@SysLogIgnore
|
|
|
@GetMapping("/admin/users/{userId}/roles")
|
|
|
- public MultiResponse<RoleRepresentation> getUserRoles(@PathVariable("userId")String userId) {
|
|
|
+ public MultiResponse<RoleRepresentation> getUserRoles(@PathVariable("userId") String userId) {
|
|
|
return MultiResponse.of(keycloakService.getUserRoles(userId));
|
|
|
}
|
|
|
|
|
|
- private List<String> getRoleNameList(List<RoleRepresentation> roleRepList){
|
|
|
+ private List<String> getRoleNameList(List<RoleRepresentation> roleRepList) {
|
|
|
return roleRepList.stream().map(RoleRepresentation::getDescription).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@SysLogIgnore
|
|
|
@GetMapping("/admin/users/{userId}/credentials")
|
|
|
- public Response queryUserCredentials(@PathVariable("userId")String userId){
|
|
|
+ public Response queryUserCredentials(@PathVariable("userId") String userId) {
|
|
|
return keycloakService.queryUserCredentials(userId);
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "OTP重置" ,business = "重置用户【${userName}】OTP")
|
|
|
+ @SmsbMethodLog(description = "OTP重置", business = "重置用户【${userName}】OTP")
|
|
|
@DeleteMapping("/admin/users/{userId}/credentials/{credentialId}")
|
|
|
- public Response removeUserCredentials(@PathVariable("userId")String userId,
|
|
|
- @PathVariable("credentialId")String credentialId,
|
|
|
- String userName){
|
|
|
- return keycloakService.removeUserCredentials(userId ,credentialId);
|
|
|
+ public Response removeUserCredentials(@PathVariable("userId") String userId, @PathVariable("credentialId") String credentialId,
|
|
|
+ String userName) {
|
|
|
+ return keycloakService.removeUserCredentials(userId, credentialId);
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "更新用户属性" ,business = "用户属性更新")
|
|
|
+ @SmsbMethodLog(description = "更新用户属性", business = "用户属性更新")
|
|
|
@PutMapping("/keycloak/users/attribute")
|
|
|
- public Response updateUserAttribute(@RequestHeader String userId , @RequestBody UserRepresentation representation){
|
|
|
+ public Response updateUserAttribute(@RequestHeader String userId, @RequestBody UserRepresentation representation) {
|
|
|
Map<String, List<String>> userAttribute = representation.getAttributes();
|
|
|
KeycloakUserCO userCO = new KeycloakUserCO();
|
|
|
- if(userAttribute != null){
|
|
|
+ if (userAttribute != null) {
|
|
|
userCO.setPhone(userAttribute.get("phone"));
|
|
|
userCO.setWechat(userAttribute.get("wechat"));
|
|
|
userCO.setWechatApplet(userAttribute.get("wechat-applet-openid"));
|
|
|
}
|
|
|
- if(representation.getEmail() != null){
|
|
|
+ if (representation.getEmail() != null) {
|
|
|
userCO.setEmail(representation.getEmail());
|
|
|
}
|
|
|
userCO.setId(userId);
|
|
|
@@ -212,75 +209,83 @@ public class KeycloakUserController {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "新增账号",
|
|
|
- business = "新增账号【${smsbUserAdd.username}】到部门【${smsbUserAdd.departmentName}】")
|
|
|
+ @SmsbMethodLog(description = "新增账号", business = "新增账号【${smsbUserAdd.username}】到部门【${smsbUserAdd.departmentName}】")
|
|
|
@PostMapping("/admin/users")
|
|
|
- public Response addKeyClaokUser(@RequestHeader String userId ,@Valid @RequestBody SmsbUserAdd smsbUserAdd){
|
|
|
+ public Response addKeyClaokUser(@RequestHeader String userId, @Valid @RequestBody SmsbUserAdd smsbUserAdd) {
|
|
|
Response checkResponse = departmentService.checkOperationAuthority(userId, smsbUserAdd.getTenant());
|
|
|
- if(!checkResponse.isSuccess()){return checkResponse;}
|
|
|
- return departmentService.addKeyClaokUser(userId ,smsbUserAdd);
|
|
|
+ if (!checkResponse.isSuccess()) {
|
|
|
+ return checkResponse;
|
|
|
+ }
|
|
|
+ return departmentService.addKeyClaokUser(userId, smsbUserAdd);
|
|
|
}
|
|
|
|
|
|
- @SmsbMethodLog(description = "账号分组",
|
|
|
- business = "将账号【${smsbRegrouping.userName}】添加到部门【${smsbRegrouping.departmentName}】")
|
|
|
+ @SmsbMethodLog(description = "账号分组", business = "将账号【${smsbRegrouping.userName}】添加到部门【${smsbRegrouping.departmentName}】")
|
|
|
@PutMapping("/admin/users/regrouping")
|
|
|
- public Response regrouping(@RequestHeader String userId,
|
|
|
- @Valid @RequestBody SmsbRegrouping smsbRegrouping){
|
|
|
- Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(
|
|
|
- smsbRegrouping.getUserId()).getTenant());
|
|
|
- if(!checkResponse.isSuccess()){return checkResponse;}
|
|
|
+ public Response regrouping(@RequestHeader String userId, @Valid @RequestBody SmsbRegrouping smsbRegrouping) {
|
|
|
+ Response checkResponse = departmentService.checkOperationAuthority(userId,
|
|
|
+ userService.getOneByUserId(smsbRegrouping.getUserId())
|
|
|
+ .getTenant());
|
|
|
+ if (!checkResponse.isSuccess()) {
|
|
|
+ return checkResponse;
|
|
|
+ }
|
|
|
return departmentService.regrouping(smsbRegrouping);
|
|
|
}
|
|
|
|
|
|
@SmsbMethodLog(description = "账号注销", business = "注销账号【${userName}】")
|
|
|
@DeleteMapping("/admin/users/{uId}")
|
|
|
- public Response enableSwitch(@RequestHeader String userId,
|
|
|
- @PathVariable("uId") String uId,
|
|
|
- String userName){
|
|
|
+ public Response enableSwitch(@RequestHeader String userId, @PathVariable("uId") String uId, String userName) {
|
|
|
Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(uId).getTenant());
|
|
|
- if(!checkResponse.isSuccess()){return checkResponse;}
|
|
|
- if(userService.removeUser(uId)){
|
|
|
+ if (!checkResponse.isSuccess()) {
|
|
|
+ return checkResponse;
|
|
|
+ }
|
|
|
+ if (userService.removeUser(uId)) {
|
|
|
return keycloakService.removeUser(uId);
|
|
|
- }else{
|
|
|
- return Response.buildFailure("500","注销用户失败!");
|
|
|
+ } else {
|
|
|
+ return Response.buildFailure("500", "注销用户失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SysLogIgnore
|
|
|
@PostMapping("/admin/department/user/list")
|
|
|
- public PageResponse<SmsbSimpleUserCO> queryDepartmentUserList(@RequestHeader String userId , @Valid @RequestBody SmsbDepartmentCmd departmentCmd){
|
|
|
+ public PageResponse<SmsbSimpleUserCO> queryDepartmentUserList(@RequestHeader String userId,
|
|
|
+ @Valid @RequestBody SmsbDepartmentCmd departmentCmd) {
|
|
|
Response checkResponse = departmentService.checkOperationAuthority(userId, departmentCmd.getTenant());
|
|
|
- if(!checkResponse.isSuccess()){return PageResponse.buildFailure(checkResponse.getErrCode(),checkResponse.getErrMessage());}
|
|
|
+ if (!checkResponse.isSuccess()) {
|
|
|
+ return PageResponse.buildFailure(checkResponse.getErrCode(), checkResponse.getErrMessage());
|
|
|
+ }
|
|
|
return departmentService.queryDepartmentUserList(departmentCmd);
|
|
|
}
|
|
|
|
|
|
@SysLogIgnore
|
|
|
@PostMapping("/admin/users/temporary/migration")
|
|
|
- public Response migration(@RequestHeader String userId , @RequestBody SmsbUserMigration userMigration){
|
|
|
+ public Response migration(@RequestHeader String userId, @RequestBody SmsbUserMigration userMigration) {
|
|
|
Response checkResponse = departmentService.checkOperationAuthority(userId, userMigration.getTenant());
|
|
|
- if(!checkResponse.isSuccess()){return checkResponse;}
|
|
|
+ if (!checkResponse.isSuccess()) {
|
|
|
+ return checkResponse;
|
|
|
+ }
|
|
|
return userService.migration(userMigration);
|
|
|
}
|
|
|
|
|
|
@SmsbMethodLog(description = "账号启用/禁用", business = "账号【${switchDTO.userName}】启用【${switchDTO.enabled}】")
|
|
|
@PutMapping("/admin/users/enabled")
|
|
|
- public Response enableSwitch(@RequestHeader String userId,
|
|
|
- @RequestBody SwitchDTO switchDTO){
|
|
|
+ public Response enableSwitch(@RequestHeader String userId, @RequestBody SwitchDTO switchDTO) {
|
|
|
Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(switchDTO.getUserId())
|
|
|
.getTenant());
|
|
|
- if(!checkResponse.isSuccess()){return checkResponse;}
|
|
|
+ if (!checkResponse.isSuccess()) {
|
|
|
+ return checkResponse;
|
|
|
+ }
|
|
|
Boolean flag = userService.enableSwitch(switchDTO);
|
|
|
- if(flag){
|
|
|
- return keycloakService.updateUser(switchDTO.getUserId() , switchDTO , Constant.ENABLE);
|
|
|
+ if (flag) {
|
|
|
+ return keycloakService.updateUser(switchDTO.getUserId(), switchDTO, Constant.ENABLE);
|
|
|
}
|
|
|
- return Response.buildFailure("500","账号启用/禁用失败!");
|
|
|
+ return Response.buildFailure("500", "账号启用/禁用失败!");
|
|
|
}
|
|
|
|
|
|
@SmsbMethodLog(description = "账号名称修改", business = "用户【${userUpdate.userId}】将名称修改为【${userUpdate.name}】")
|
|
|
@PutMapping("/admin/users/update")
|
|
|
- public Response updateUserFirstName(@RequestHeader String userId ,
|
|
|
- @RequestBody SmsbUserUpdate userUpdate) {
|
|
|
- Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(userUpdate.getUserId()).getTenant());
|
|
|
+ public Response updateUserFirstName(@RequestHeader String userId, @RequestBody SmsbUserUpdate userUpdate) {
|
|
|
+ Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(userUpdate.getUserId())
|
|
|
+ .getTenant());
|
|
|
if (!checkResponse.isSuccess()) {
|
|
|
return checkResponse;
|
|
|
}
|
|
|
@@ -293,9 +298,9 @@ public class KeycloakUserController {
|
|
|
|
|
|
@SmsbMethodLog(description = "消息推送预警级别", business = "将用户账号【${levelUpdate.userName}】消息推送预警级别改为【${levelUpdate.informName}】")
|
|
|
@PutMapping("/admin/users/update/deviceExceptionLevel")
|
|
|
- public Response updateUserFirstName(@RequestHeader String userId,
|
|
|
- @RequestBody SmsbUserExceptionLevelUpdate levelUpdate) {
|
|
|
- Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(levelUpdate.getUserId()).getTenant());
|
|
|
+ public Response updateUserFirstName(@RequestHeader String userId, @RequestBody SmsbUserExceptionLevelUpdate levelUpdate) {
|
|
|
+ Response checkResponse = departmentService.checkOperationAuthority(userId, userService.getOneByUserId(levelUpdate.getUserId())
|
|
|
+ .getTenant());
|
|
|
if (!checkResponse.isSuccess()) {
|
|
|
return checkResponse;
|
|
|
}
|
|
|
@@ -307,9 +312,9 @@ public class KeycloakUserController {
|
|
|
|
|
|
@SysLogIgnore
|
|
|
@GetMapping("/admin/user/custom")
|
|
|
- public Response queryUserInformType(String userId){
|
|
|
- return StringUtils.isEmpty(userId) ? Response.buildFailure("400","userI不能为空!")
|
|
|
- : SingleResponse.of(userService.queryUserInformType(userId));
|
|
|
+ public Response queryUserInformType(String userId) {
|
|
|
+ return StringUtils.isEmpty(userId) ? Response.buildFailure("400", "userI不能为空!") :
|
|
|
+ SingleResponse.of(userService.queryUserInformType(userId));
|
|
|
}
|
|
|
|
|
|
@SysLogIgnore
|