Jelajahi Sumber

fix:添加keycloak方法

wangbo 3 tahun lalu
induk
melakukan
0f6eab7472

+ 11 - 0
smsb-customer-manager-app/src/main/java/com/inspur/customer/service/keycloak/KeycloakServiceImpl.java

@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.keycloak.admin.client.Keycloak;
 import org.keycloak.admin.client.resource.UserResource;
+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;
@@ -65,4 +66,14 @@ public class KeycloakServiceImpl implements KeycloakService {
         user.update(userRepresentation);
     }
 
+    @Override
+    public List<String> getAttrByGroupPath(String groupPath, String key) {
+        GroupRepresentation groupRepresentation = keycloak.realm(realm).getGroupByPath(groupPath);
+        if (groupRepresentation != null) {
+            Map<String, List<String>> attributes = groupRepresentation.getAttributes();
+            return attributes != null ? attributes.get(key) : Collections.emptyList();
+        }
+        return Collections.emptyList();
+    }
+
 }

+ 10 - 0
smsb-customer-manager-client/src/main/java/com/inspur/customer/service/client/keycloak/KeycloakService.java

@@ -1,4 +1,5 @@
 package com.inspur.customer.service.client.keycloak;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -30,4 +31,13 @@ public interface KeycloakService {
      * @param value
      */
     void updateAttribute(String userId ,String property , String value);
+
+    /**
+     * 获取attributes
+     *
+     * @param groupPath
+     * @param key
+     * @return
+     */
+    List<String> getAttrByGroupPath(String groupPath, String key);
 }