|
9 | 9 | import org.junit.rules.TestRule; |
10 | 10 | import org.junit.runners.MethodSorters; |
11 | 11 | import org.keycloak.OAuth2Constants; |
| 12 | +import org.keycloak.federation.ldap.LDAPConfig; |
12 | 13 | import org.keycloak.federation.ldap.LDAPFederationProvider; |
13 | 14 | import org.keycloak.federation.ldap.LDAPFederationProviderFactory; |
14 | 15 | import org.keycloak.federation.ldap.idm.model.LDAPObject; |
@@ -353,20 +354,31 @@ public void testCaseSensitiveAttributeName() { |
353 | 354 |
|
354 | 355 | @Test |
355 | 356 | public void testDotInUsername() { |
356 | | - // Add LDAP user with same email like existing model user |
357 | | - keycloakRule.update(new KeycloakRule.KeycloakSetup() { |
| 357 | + KeycloakSession session = keycloakRule.startSession(); |
| 358 | + boolean skip = false; |
358 | 359 |
|
359 | | - @Override |
360 | | - public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) { |
361 | | - LDAPFederationProvider ldapFedProvider = FederationTestUtils.getLdapProvider(session, ldapModel); |
| 360 | + try { |
| 361 | + RealmModel appRealm = new RealmManager(session).getRealmByName("test"); |
| 362 | + LDAPFederationProvider ldapFedProvider = FederationTestUtils.getLdapProvider(session, ldapModel); |
| 363 | + |
| 364 | + // Workaround as dot is not allowed in sAMAccountName on active directory. So we will skip the test for this configuration |
| 365 | + LDAPConfig config = ldapFedProvider.getLdapIdentityStore().getConfig(); |
| 366 | + if (config.isActiveDirectory() && config.getUsernameLdapAttribute().equals(LDAPConstants.SAM_ACCOUNT_NAME)) { |
| 367 | + skip = true; |
| 368 | + } |
| 369 | + |
| 370 | + if (!skip) { |
362 | 371 | LDAPObject johnDot = FederationTestUtils. addLDAPUser( ldapFedProvider, appRealm, "john,dot", "John", "Dot", "[email protected]", null, "12387"); |
363 | 372 | ldapFedProvider.getLdapIdentityStore().updatePassword(johnDot, "Password1"); |
364 | 373 | } |
| 374 | + } finally { |
| 375 | + keycloakRule.stopSession(session, false); |
| 376 | + } |
365 | 377 |
|
366 | | - }); |
367 | | - |
368 | | - // Try to import the duplicated LDAP user into Keycloak |
369 | | - loginSuccessAndLogout("john,dot", "Password1"); |
| 378 | + if (!skip) { |
| 379 | + // Try to import the user with dot in username into Keycloak |
| 380 | + loginSuccessAndLogout("john,dot", "Password1"); |
| 381 | + } |
370 | 382 | } |
371 | 383 |
|
372 | 384 | @Test |
|
0 commit comments