KeycloakService.java 5.1 KB

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