From 649bca76186e46dae1f32f20030877c2da9bf564 Mon Sep 17 00:00:00 2001 From: Bill Burke Date: Wed, 18 Oct 2017 09:37:17 -0400 Subject: [PATCH] KEYCLOAK-4328 --- .../admin/UserStorageProviderResource.java | 31 ++++++++++++++++ .../admin/resources/js/controllers/users.js | 35 ++++++++++++++----- .../theme/base/admin/resources/js/services.js | 4 +++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/admin/UserStorageProviderResource.java b/services/src/main/java/org/keycloak/services/resources/admin/UserStorageProviderResource.java index 638f57ba6f..d9ec881a34 100644 --- a/services/src/main/java/org/keycloak/services/resources/admin/UserStorageProviderResource.java +++ b/services/src/main/java/org/keycloak/services/resources/admin/UserStorageProviderResource.java @@ -34,6 +34,7 @@ import org.keycloak.storage.ldap.mappers.LDAPStorageMapper; import org.keycloak.storage.user.SynchronizationResult; import javax.ws.rs.BadRequestException; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -78,6 +79,36 @@ public class UserStorageProviderResource { this.adminEvent = adminEvent; } + /** + * Need this for admin console to display simple name of provider when displaying user detail + * + * KEYCLOAK-4328 + * + * @param id + * @return + */ + @GET + @Path("{id}/name") + @NoCache + @Produces(MediaType.APPLICATION_JSON) + public Map getSimpleName(@PathParam("id") String id) { + auth.users().requireQuery(); + + ComponentModel model = realm.getComponent(id); + if (model == null) { + throw new NotFoundException("Could not find component"); + } + if (!model.getProviderType().equals(UserStorageProvider.class.getName())) { + throw new NotFoundException("found, but not a UserStorageProvider"); + } + + Map data = new HashMap<>(); + data.put("id", model.getId()); + data.put("name", model.getName()); + return data; + } + + /** * Trigger sync of users * diff --git a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js index 549f621568..2222ebfd59 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/controllers/users.js @@ -325,6 +325,7 @@ module.controller('UserTabCtrl', function($scope, $location, Dialog, Notificatio module.controller('UserDetailCtrl', function($scope, realm, user, BruteForceUser, User, Components, UserImpersonation, RequiredActions, + UserStorageOperations, $location, $http, Dialog, Notifications) { $scope.realm = realm; $scope.create = !user.id; @@ -352,18 +353,36 @@ module.controller('UserDetailCtrl', function($scope, realm, user, BruteForceUser if(user.federationLink) { console.log("federationLink is not null. It is " + user.federationLink); - Components.get({realm: realm.realm, componentId: user.federationLink}, function (link) { - $scope.federationLinkName = link.name; - $scope.federationLink = "#/realms/" + realm.realm + "/user-storage/providers/" + link.providerId + "/" + link.id; - }); + if ($scope.access.viewRealm) { + Components.get({realm: realm.realm, componentId: user.federationLink}, function (link) { + $scope.federationLinkName = link.name; + $scope.federationLink = "#/realms/" + realm.realm + "/user-storage/providers/" + link.providerId + "/" + link.id; + }); + } else { + // KEYCLOAK-4328 + UserStorageOperations.simpleName.get({realm: realm.realm, componentId: user.federationLink}, function (link) { + $scope.federationLinkName = link.name; + $scope.federationLink = $location.absUrl(); + }) + } + } else { console.log("federationLink is null"); } if(user.origin) { - Components.get({realm: realm.realm, componentId: user.origin}, function (link) { - $scope.originName = link.name; - $scope.originLink = "#/realms/" + realm.realm + "/user-storage/providers/" + link.providerId + "/" + link.id; - }) + if ($scope.access.viewRealm) { + Components.get({realm: realm.realm, componentId: user.origin}, function (link) { + $scope.originName = link.name; + $scope.originLink = "#/realms/" + realm.realm + "/user-storage/providers/" + link.providerId + "/" + link.id; + }) + } + else { + // KEYCLOAK-4328 + UserStorageOperations.simpleName.get({realm: realm.realm, componentId: user.origin}, function (link) { + $scope.originName = link.name; + $scope.originLink = $location.absUrl(); + }) + } } else { console.log("origin is null"); } diff --git a/themes/src/main/resources/theme/base/admin/resources/js/services.js b/themes/src/main/resources/theme/base/admin/resources/js/services.js index b68af10dc7..9297965e4d 100755 --- a/themes/src/main/resources/theme/base/admin/resources/js/services.js +++ b/themes/src/main/resources/theme/base/admin/resources/js/services.js @@ -1789,6 +1789,10 @@ module.factory('UserStorageOperations', function($resource) { realm : '@realm', componentId : '@componentId' }); + object.simpleName = $resource(authUrl + '/admin/realms/:realm/user-storage/:componentId/name', { + realm : '@realm', + componentId : '@componentId' + }); return object; });