KeycloakService.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. package com.inspur.customer.client.keycloak;
  2. import com.alibaba.cola.dto.PageResponse;
  3. import com.alibaba.cola.dto.Response;
  4. import com.alibaba.cola.dto.SingleResponse;
  5. import com.inspur.customer.object.keycloak.KeycloakUserCO;
  6. import com.inspur.customer.object.keycloak.UsersRoleMappingDTO;
  7. import com.inspur.customer.object.org.SmsbDepartmentCmd;
  8. import com.inspur.customer.object.org.SmsbUserAdd;
  9. import com.inspur.customer.object.wechat.Pair;
  10. import org.keycloak.representations.idm.CredentialRepresentation;
  11. import org.keycloak.representations.idm.GroupRepresentation;
  12. import org.keycloak.representations.idm.RoleRepresentation;
  13. import org.keycloak.representations.idm.UserRepresentation;
  14. import org.springframework.web.bind.annotation.RequestBody;
  15. import java.util.List;
  16. import java.util.Map;
  17. /**
  18. * keycloak接口能力适配
  19. * @author wangbo13
  20. */
  21. public interface KeycloakService {
  22. /**
  23. * 获取当前releam下用户Map<id,name>
  24. *
  25. * @return
  26. */
  27. Map<String, String> getUserMap();
  28. List<KeycloakUserCO> getUsersInRole(String role);
  29. List<KeycloakUserCO> getUsersByIds(List<String> userIds);
  30. /**
  31. * 检查用户是否具备某角色权限
  32. *
  33. * @param userId
  34. * @param role
  35. * @return
  36. */
  37. Boolean checkUserRole(String userId,String role);
  38. /**
  39. * 更新用户attribute
  40. *
  41. * @param userId
  42. * @param property
  43. * @param value
  44. */
  45. void updateAttribute(String userId ,String property , String value);
  46. /**
  47. * 获取attributes
  48. *
  49. * @param groupPath
  50. * @param key
  51. * @return
  52. */
  53. List<String> getAttrByGroupPath(String groupPath, String key);
  54. List<KeycloakUserCO> getGroupSupervisor(String group);
  55. List<KeycloakUserCO> getSuperAdmin();
  56. List<KeycloakUserCO> getGroupAdmin(String group);
  57. String getSingleAttrByGroupPath(String group, String key);
  58. /**
  59. * 根据属性键值对查找用户
  60. *
  61. * @param entries 属性键值对
  62. * @return 找到的用户
  63. */
  64. List<KeycloakUserCO> searchUserByAttrEntry(List<Pair> entries);
  65. List<String> getUserGroupPathList(String userId);
  66. List<String> getUserRealmRoles(String userId);
  67. Map<String, List<String>> getUserClientRoles(String userId);
  68. void changePassword(String userId, String newPassword);
  69. /**
  70. * 获取当前releam下用户Map<id,name>
  71. *
  72. * @return
  73. */
  74. Map<String, String> getUsersMap();
  75. /**
  76. * 该租户下添加部门
  77. *
  78. * @param id
  79. * @param groupRepresentation
  80. * @return
  81. */
  82. Response addKeycloakGroup(String id , GroupRepresentation groupRepresentation);
  83. /**
  84. * 该租户下修改部门
  85. *
  86. * @param id
  87. * @param groupRepresentation
  88. * @return
  89. */
  90. Response updateKeycloakGroup(String id , GroupRepresentation groupRepresentation);
  91. /**
  92. * 该租户下删除部门
  93. *
  94. * @param id
  95. * @return
  96. */
  97. Response removeGroup(String id);
  98. /**
  99. * 添加用户
  100. *
  101. * @param smsbUserAdd
  102. * @return
  103. */
  104. SingleResponse addKeyClaokUser(SmsbUserAdd smsbUserAdd);
  105. /**
  106. * 更新用户信息
  107. *
  108. * @param userId
  109. * @param representation
  110. * @param oprateType 1:账号启用/禁用 2:重置密码
  111. * @return
  112. */
  113. Response updateUser(String userId , Object representation ,Integer oprateType);
  114. /**
  115. * 注销用户
  116. *
  117. * @param userId
  118. * @return
  119. */
  120. Response removeUser(String userId);
  121. /**
  122. * 用户重分组
  123. *
  124. * @param userId
  125. * @param groupId
  126. * @return
  127. */
  128. Response regrouping(String userId , String groupId);
  129. /**
  130. * 用户角色分配
  131. *
  132. * @param ssersRoleMappingDTO
  133. * @return
  134. */
  135. Response roleMapping(UsersRoleMappingDTO ssersRoleMappingDTO);
  136. /**
  137. * 获取用户凭证
  138. *
  139. * @param userId
  140. * @return
  141. */
  142. Response queryUserCredentials(String userId);
  143. /**
  144. * 删除用户凭证
  145. *
  146. * @param userId
  147. * @param credentialId
  148. * @return
  149. */
  150. Response removeUserCredentials(String userId ,String credentialId);
  151. /**
  152. * 新增租户
  153. *
  154. * @param groupRepresentation
  155. * @return
  156. */
  157. Response addKeyclaokTenant(GroupRepresentation groupRepresentation);
  158. /**
  159. * 判断用户是否具有某角色
  160. *
  161. * @param userId
  162. * @param role
  163. * @return
  164. */
  165. Boolean isExitTargetRole(String userId ,String role);
  166. /**
  167. * 获取用户所属租户
  168. *
  169. * @param userId
  170. * @return 租户
  171. */
  172. String queryUserTenant(String userId);
  173. /**
  174. * 新增或修改用户attributes
  175. *
  176. * @param userId
  177. * @param key key
  178. * @param values values
  179. * @return if success
  180. */
  181. Boolean addAttributesByUserId(String userId , String key , List<String> values);
  182. /**
  183. * 获取用户列表
  184. *
  185. * @param departmentCmd
  186. * @param userId
  187. * @return
  188. */
  189. PageResponse<UserRepresentation> getUserListByIds(SmsbDepartmentCmd departmentCmd , List<String> userId);
  190. }