|
|
@@ -8,6 +8,7 @@ import org.apache.dubbo.config.annotation.DubboService;
|
|
|
import org.keycloak.admin.client.Keycloak;
|
|
|
import org.keycloak.admin.client.resource.RealmResource;
|
|
|
import org.keycloak.admin.client.resource.UserResource;
|
|
|
+import org.keycloak.representations.idm.ClientRepresentation;
|
|
|
import org.keycloak.representations.idm.GroupRepresentation;
|
|
|
import org.keycloak.representations.idm.RoleRepresentation;
|
|
|
import org.keycloak.representations.idm.UserRepresentation;
|
|
|
@@ -184,16 +185,35 @@ public class KeycloakServiceImpl implements KeycloakService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String getUserTenant(String userId) {
|
|
|
- List<GroupRepresentation> groups = keycloak.realm(realm).users().get(userId).groups();
|
|
|
- if (groups.isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String path = groups.get(0).getPath();
|
|
|
- if (path.lastIndexOf('/') == 0) {
|
|
|
- return path;
|
|
|
+ public List<String> getUserGroupPathList(String userId) {
|
|
|
+ return keycloak.realm(realm).users().get(userId).groups().stream().map(GroupRepresentation::getPath).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> getUserRealmRoles(String userId) {
|
|
|
+ return keycloak.realm(realm)
|
|
|
+ .users()
|
|
|
+ .get(userId)
|
|
|
+ .roles()
|
|
|
+ .getAll()
|
|
|
+ .getRealmMappings()
|
|
|
+ .stream()
|
|
|
+ .map(RoleRepresentation::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, List<String>> getUserClientRoles(String userId) {
|
|
|
+ Map<String, List<String>> resultMap = new HashMap<>();
|
|
|
+ List<ClientRepresentation> clientList = keycloak.realm(realm).clients().findAll();
|
|
|
+ for (ClientRepresentation clientRepresentation : clientList) {
|
|
|
+ String clientId = clientRepresentation.getClientId();
|
|
|
+ List<RoleRepresentation> roleList = keycloak.realm(realm).users().get(userId).roles().clientLevel(clientRepresentation.getId()).listEffective();
|
|
|
+ if (!roleList.isEmpty()) {
|
|
|
+ resultMap.put(clientId, roleList.stream().map(RoleRepresentation::getName).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
}
|
|
|
- return path.substring(0, path.indexOf('/', 1));
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
|
|
|
private List<KeycloakUserCO> getUserByRoleAndGroup(String group, String role) {
|