From 5edb84ccfb12583242378c116bd6827d0f1f3aed Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 4 Aug 2014 16:36:29 +0200 Subject: [PATCH] Ensure that displayName is persisted. Add 'user' to ActiveDirectory classes --- .../theme/admin/base/resources/js/controllers/users.js | 2 +- .../java/org/keycloak/models/jpa/RealmAdapter.java | 3 ++- .../models/mongo/keycloak/adapters/RealmAdapter.java | 2 ++ .../services/managers/LDAPConnectionTestManager.java | 2 +- .../java/org/keycloak/testsuite/model/ImportTest.java | 9 +++++++++ .../src/test/resources/model/testrealm.json | 10 ++++++++++ 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js b/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js index 02ecbb7db5..95b1f51896 100755 --- a/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js +++ b/forms/common-themes/src/main/resources/theme/admin/base/resources/js/controllers/users.js @@ -485,7 +485,7 @@ module.controller('LDAPCtrl', function($scope, $location, Notifications, Dialog, if ($scope.lastVendor === "ad") { $scope.instance.config.usernameLDAPAttribute = "cn"; - $scope.instance.config.userObjectClasses = "person, organizationalPerson"; + $scope.instance.config.userObjectClasses = "person, organizationalPerson, user"; } else { $scope.instance.config.usernameLDAPAttribute = "uid"; $scope.instance.config.userObjectClasses = "inetOrgPerson, organizationalPerson"; diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java index 9822e98b90..5a6cba11a4 100755 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/RealmAdapter.java @@ -781,8 +781,9 @@ public class RealmAdapter implements RealmModel { entity.setPriority(model.getPriority()); String displayName = model.getDisplayName(); if (displayName == null) { - entity.setDisplayName(entity.getId()); + displayName = entity.getId(); } + entity.setDisplayName(displayName); em.persist(entity); realm.getUserFederationProviders().add(entity); diff --git a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java index ea75bb135d..8042b6850f 100755 --- a/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java +++ b/model/mongo/src/main/java/org/keycloak/models/mongo/keycloak/adapters/RealmAdapter.java @@ -766,6 +766,7 @@ public class RealmAdapter extends AbstractMongoAdapter impleme if (displayName == null) { displayName = entity.getId(); } + entity.setDisplayName(displayName); realm.getUserFederationProviders().add(entity); updateRealm(); @@ -840,6 +841,7 @@ public class RealmAdapter extends AbstractMongoAdapter impleme if (displayName == null) { entity.setDisplayName(entity.getId()); } + entity.setDisplayName(displayName); entities.add(entity); } diff --git a/services/src/main/java/org/keycloak/services/managers/LDAPConnectionTestManager.java b/services/src/main/java/org/keycloak/services/managers/LDAPConnectionTestManager.java index 468a146c1e..2b78406e8c 100755 --- a/services/src/main/java/org/keycloak/services/managers/LDAPConnectionTestManager.java +++ b/services/src/main/java/org/keycloak/services/managers/LDAPConnectionTestManager.java @@ -43,7 +43,7 @@ public class LDAPConnectionTestManager { ldapContext = new InitialLdapContext(env, null); return true; - } catch (NamingException ne) { + } catch (Exception ne) { String errorMessage = (TEST_AUTHENTICATION.equals(action)) ? "Error when authenticating to LDAP: " : "Error when connecting to LDAP: "; logger.error(errorMessage + ne.getMessage(), ne); return false; diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java index 31ccdf1fa6..cbdd172822 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/model/ImportTest.java @@ -12,6 +12,7 @@ import org.keycloak.models.RealmModel; import org.keycloak.models.RequiredCredentialModel; import org.keycloak.models.RoleModel; import org.keycloak.models.SocialLinkModel; +import org.keycloak.models.UserFederationProviderModel; import org.keycloak.models.UserModel; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.services.managers.RealmManager; @@ -194,6 +195,14 @@ public class ImportTest extends AbstractModelTest { Assert.assertEquals("abc", socialConfig.get("google.key")); Assert.assertEquals("def", socialConfig.get("google.secret")); + // Test federation providers + List fedProviders = realm.getUserFederationProviders(); + Assert.assertTrue(fedProviders.size() == 1); + UserFederationProviderModel ldap = fedProviders.get(0); + Assert.assertEquals("MyLDAPProvider", ldap.getDisplayName()); + Assert.assertEquals("dummy", ldap.getProviderName()); + Assert.assertEquals(1, ldap.getPriority()); + Assert.assertEquals("ldap://foo", ldap.getConfig().get("important.config")); } @Test diff --git a/testsuite/integration/src/test/resources/model/testrealm.json b/testsuite/integration/src/test/resources/model/testrealm.json index f6b212c1c5..a5bf38012e 100755 --- a/testsuite/integration/src/test/resources/model/testrealm.json +++ b/testsuite/integration/src/test/resources/model/testrealm.json @@ -16,6 +16,16 @@ "google.key": "abc", "google.secret": "def" }, + "userFederationProviders": [ + { + "displayName": "MyLDAPProvider", + "providerName": "dummy", + "priority": 1, + "config": { + "important.config": "ldap://foo" + } + } + ], "users": [ { "username": "wburke",