|
|
@@ -5,15 +5,27 @@ import com.alibaba.cola.dto.SingleResponse;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.inspur.customer.client.keycloak.KeycloakService;
|
|
|
import com.inspur.customer.client.wechat.IWeChatService;
|
|
|
+import com.inspur.customer.constant.Constant;
|
|
|
+import com.inspur.customer.object.keycloak.SwitchDTO;
|
|
|
+import com.inspur.customer.object.keycloak.UsersRoleMappingDTO;
|
|
|
import com.inspur.customer.object.wechat.SubscribeDto;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.dubbo.config.Constants;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.keycloak.representations.idm.CredentialRepresentation;
|
|
|
+import org.keycloak.representations.idm.GroupRepresentation;
|
|
|
+import org.keycloak.representations.idm.RoleRepresentation;
|
|
|
+import org.keycloak.representations.idm.UserRepresentation;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
/**
|
|
|
* 微信模块
|
|
|
* @author wangbo13
|
|
|
@@ -21,7 +33,6 @@ import org.springframework.web.bind.annotation.*;
|
|
|
@Slf4j
|
|
|
@RestController
|
|
|
@EnableScheduling
|
|
|
-@RequestMapping("/keycloak")
|
|
|
public class KeycloakController {
|
|
|
|
|
|
@Value("${system.appKey}")
|
|
|
@@ -33,7 +44,7 @@ public class KeycloakController {
|
|
|
@DubboReference
|
|
|
private IWeChatService iWeChatService;
|
|
|
|
|
|
- @PostMapping("update/user")
|
|
|
+ @PostMapping("/keycloak/update/user")
|
|
|
public Response updateUser(@RequestBody String json){
|
|
|
SubscribeDto subscribe = JSONObject.parseObject(json, SubscribeDto.class);
|
|
|
if(StringUtils.isEmpty(subscribe.getUserId())){
|
|
|
@@ -43,13 +54,13 @@ public class KeycloakController {
|
|
|
return Response.buildSuccess();
|
|
|
}
|
|
|
|
|
|
- @GetMapping("query/ticket/{userId}")
|
|
|
+ @GetMapping("/keycloak/query/ticket/{userId}")
|
|
|
public SingleResponse getTicket(@PathVariable("userId") String userId,
|
|
|
@RequestHeader("Authorization") String authorization) {
|
|
|
return SingleResponse.of(iWeChatService.queryTicket(appKey, userId, authorization));
|
|
|
}
|
|
|
|
|
|
- @PutMapping("changePassword")
|
|
|
+ @PutMapping("/keycloak/changePassword")
|
|
|
public Response changePassword(@RequestHeader("userId") String userId, String newPassword) {
|
|
|
if (StringUtils.isEmpty(userId)) {
|
|
|
return Response.buildFailure("400", "密码不能为空");
|
|
|
@@ -70,4 +81,79 @@ public class KeycloakController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/admin/group/{id}/children")
|
|
|
+ public Response addKeycloakGroup(@PathVariable("id") String id , @RequestBody GroupRepresentation groupRepresentation){
|
|
|
+ if(StringUtils.isEmpty(groupRepresentation.getName())){
|
|
|
+ return Response.buildFailure("500","name不能为空!");
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(groupRepresentation.getAttributes())){
|
|
|
+ return Response.buildFailure("500","attributes不能为空!");
|
|
|
+ }
|
|
|
+ return keycloakService.addKeycloakGroup(id , groupRepresentation);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/admin/group/{id}")
|
|
|
+ public Response updateKeycloakGroup(@PathVariable("id") String id , @RequestBody GroupRepresentation groupRepresentation){
|
|
|
+ if(StringUtils.isEmpty(groupRepresentation.getName())){
|
|
|
+ return Response.buildFailure("500","name不能为空!");
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(groupRepresentation.getAttributes())){
|
|
|
+ return Response.buildFailure("500","attributes不能为空!");
|
|
|
+ }
|
|
|
+ return keycloakService.updateKeycloakGroup(id , groupRepresentation);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/admin/group/{id}")
|
|
|
+ public Response removeGroup(@PathVariable("id") String id){
|
|
|
+ return keycloakService.removeGroup(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/admin/users/add")
|
|
|
+ public Response addKeyClaokUser(@RequestBody UserRepresentation userRepresentation){
|
|
|
+ if(StringUtils.isEmpty(userRepresentation.getUsername())){
|
|
|
+ return Response.buildFailure("500","userName不能为空!");
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(userRepresentation.getGroups())){
|
|
|
+ return Response.buildFailure("500","groups不能为空!");
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(userRepresentation.getCredentials())){
|
|
|
+ return Response.buildFailure("500","credentials不能为空!");
|
|
|
+ }
|
|
|
+ return keycloakService.addKeyClaokUser(userRepresentation);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/admin/users/{userId}")
|
|
|
+ public Response enableSwitch(@PathVariable("userId") String userId, @RequestBody SwitchDTO switchDTO){
|
|
|
+ log.info("userId:{}",userId);
|
|
|
+ return keycloakService.updateUser(userId , switchDTO , Constant.ENABLE);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/admin/users/{userId}/reset")
|
|
|
+ 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不能为空!");
|
|
|
+ }
|
|
|
+ return keycloakService.updateUser(userId , credential , Constant.RESET_PASSWORD);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/admin/users/{userId}")
|
|
|
+ public Response enableSwitch(@PathVariable("userId") String userId){
|
|
|
+ return keycloakService.removeUser(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/admin/users/{userId}/groups/{groupId}")
|
|
|
+ public Response regrouping(@PathVariable("userId")String userId,
|
|
|
+ @PathVariable("groupId")String groupId){
|
|
|
+ return keycloakService.regrouping(userId , groupId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/admin/users/role/configure")
|
|
|
+ public Response roleMapping(@RequestBody UsersRoleMappingDTO ssersRoleMappingDTO){
|
|
|
+ return keycloakService.roleMapping(ssersRoleMappingDTO);
|
|
|
+ }
|
|
|
+
|
|
|
}
|