You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by is...@apache.org on 2020/03/18 19:04:16 UTC

[airavata-custos] branch develop updated: Add client roles to response of find users

This is an automated email from the ASF dual-hosted git repository.

isjarana pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/develop by this push:
     new 084109a  Add client roles to response of find users
     new 3226722  Merge pull request #29 from isururanawaka/microservices_based_impl
084109a is described below

commit 084109a9af1817c1ad487bc9c927ec98dc9db5d7
Author: Isuru Ranawaka <ir...@gmail.com>
AuthorDate: Wed Mar 18 15:01:46 2020 -0400

    Add client roles to response of find users
---
 .../apache/custos/iam/service/IamAdminService.java |   2 +-
 .../src/main/proto/IamAdminService.proto           |   2 +-
 .../services/clients/keycloak/KeycloakClient.java  |  40 +++++++++++++++++----
 .../src/main/resources/user-management-service.pb  | Bin 103506 -> 103508 bytes
 4 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/custos-core-services/iam-admin-core-service/src/main/java/org/apache/custos/iam/service/IamAdminService.java b/custos-core-services/iam-admin-core-service/src/main/java/org/apache/custos/iam/service/IamAdminService.java
index 5861b1c..992ce32 100644
--- a/custos-core-services/iam-admin-core-service/src/main/java/org/apache/custos/iam/service/IamAdminService.java
+++ b/custos-core-services/iam-admin-core-service/src/main/java/org/apache/custos/iam/service/IamAdminService.java
@@ -312,7 +312,7 @@ public class IamAdminService extends IamAdminServiceImplBase {
             representation.stream().forEach(r -> users.add(this.getUser(r, request.getClientId())));
 
 
-            FindUsersResponse response = FindUsersResponse.newBuilder().addAllUser(users).build();
+            FindUsersResponse response = FindUsersResponse.newBuilder().addAllUsers(users).build();
             responseObserver.onNext(response);
             responseObserver.onCompleted();
 
diff --git a/custos-core-services/iam-admin-core-service/src/main/proto/IamAdminService.proto b/custos-core-services/iam-admin-core-service/src/main/proto/IamAdminService.proto
index e8c7fb9..0572524 100644
--- a/custos-core-services/iam-admin-core-service/src/main/proto/IamAdminService.proto
+++ b/custos-core-services/iam-admin-core-service/src/main/proto/IamAdminService.proto
@@ -154,7 +154,7 @@ message UserSearchRequest {
 }
 
 message FindUsersResponse {
-    repeated UserRepresentation user = 1;
+    repeated UserRepresentation users = 1;
 }
 
 message ResetUserPassword {
diff --git a/custos-federated-services-clients/src/main/java/org/apache/custos/federated/services/clients/keycloak/KeycloakClient.java b/custos-federated-services-clients/src/main/java/org/apache/custos/federated/services/clients/keycloak/KeycloakClient.java
index 1a30225..83fccca 100644
--- a/custos-federated-services-clients/src/main/java/org/apache/custos/federated/services/clients/keycloak/KeycloakClient.java
+++ b/custos-federated-services-clients/src/main/java/org/apache/custos/federated/services/clients/keycloak/KeycloakClient.java
@@ -757,11 +757,11 @@ public class KeycloakClient {
 
                 if (exAtrMap != null && !exAtrMap.isEmpty()) {
                     attributeMap.keySet().forEach(key -> {
-                       List<String> stringList =  exAtrMap.get(key);
-                       if (stringList != null && !stringList.isEmpty()) {
-                           stringList.removeAll(attributeMap.get(key));
-                           exAtrMap.put(key,stringList);
-                       }
+                        List<String> stringList = exAtrMap.get(key);
+                        if (stringList != null && !stringList.isEmpty()) {
+                            stringList.removeAll(attributeMap.get(key));
+                            exAtrMap.put(key, stringList);
+                        }
                     });
                     userRepresentation.setAttributes(exAtrMap);
                 }
@@ -1037,10 +1037,36 @@ public class KeycloakClient {
                                                  String firstName, String lastName, String email, int offset, int limit) {
 
         // Searching for users by username returns also partial matches, so need to filter down to an exact match if it exists
-        return client.realm(tenantId).users().search(
+        List<UserRepresentation> userResourceList = client.realm(tenantId).users().search(
                 username.toLowerCase(), firstName, lastName, email, offset, limit);
 
-    }
+        if (userResourceList != null && !userResourceList.isEmpty()) {
+            List<UserRepresentation> newList = new ArrayList<>();
+            for (UserRepresentation userRepresentation : userResourceList) {
+                RoleMappingResource resource = client.realm(tenantId).users().get(userRepresentation.getId()).roles();
+                MappingsRepresentation representation = resource.getAll();
+                if (representation != null && representation.getRealmMappings() != null) {
+                    List<String> roleRepresentations = new ArrayList<>();
+                    representation.getRealmMappings().forEach(t -> roleRepresentations.add(t.getName()));
+                    userRepresentation.setRealmRoles(roleRepresentations);
+                }
+                if (representation != null && representation.getClientMappings() != null) {
+                    Map<String, List<String>> roleRepresentations = new HashMap<>();
+                    representation.getClientMappings().keySet().forEach(key -> {
+                        if (representation.getClientMappings().get(key).getMappings() != null) {
+                            List<String> roleList = new ArrayList<>();
+                            representation.getClientMappings().get(key).getMappings().forEach(t -> roleList.add(t.getName()));
+                            roleRepresentations.put(key, roleList);
+                        }
+                    });
+                    userRepresentation.setClientRoles(roleRepresentations);
+                }
+                newList.add(userRepresentation);
+            }
+            return userResourceList;
+        }
 
+        return userResourceList;
+    }
 
 }
diff --git a/custos-integration-services/user-management-service-parent/user-management-service-sidecar/src/main/resources/user-management-service.pb b/custos-integration-services/user-management-service-parent/user-management-service-sidecar/src/main/resources/user-management-service.pb
index af96900..871e963 100644
Binary files a/custos-integration-services/user-management-service-parent/user-management-service-sidecar/src/main/resources/user-management-service.pb and b/custos-integration-services/user-management-service-parent/user-management-service-sidecar/src/main/resources/user-management-service.pb differ