From 933265511032f44d3317ed76d82da5ef3bb62d7e Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 29 Jan 2016 18:10:06 +0100 Subject: [PATCH] KEYCLOAK-2292 Broker login: remove identity provider prefix from autogenerated username --- .../services/resources/IdentityBrokerService.java | 2 +- .../testsuite/broker/AbstractIdentityProviderTest.java | 2 +- .../broker/AbstractKeycloakIdentityProviderTest.java | 4 ++-- .../keycloak/testsuite/broker/PostBrokerFlowTest.java | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/src/main/java/org/keycloak/services/resources/IdentityBrokerService.java b/services/src/main/java/org/keycloak/services/resources/IdentityBrokerService.java index f19151a3f8..3a8efffc77 100755 --- a/services/src/main/java/org/keycloak/services/resources/IdentityBrokerService.java +++ b/services/src/main/java/org/keycloak/services/resources/IdentityBrokerService.java @@ -299,7 +299,7 @@ public class IdentityBrokerService implements IdentityProvider.AuthenticationCal } else if (context.getUsername() == null) { username = context.getIdpConfig().getAlias() + "." + context.getId(); } else { - username = context.getIdpConfig().getAlias() + "." + context.getUsername(); + username = context.getUsername(); } } username = username.trim(); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java index 457b5aa136..2f0dc2768b 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractIdentityProviderTest.java @@ -155,7 +155,7 @@ public abstract class AbstractIdentityProviderTest { FederatedIdentityModel federatedIdentityModel = federatedIdentities.iterator().next(); assertEquals(getProviderId(), federatedIdentityModel.getIdentityProvider()); - assertEquals(federatedUser.getUsername(), federatedIdentityModel.getIdentityProvider() + "." + federatedIdentityModel.getUserName()); + assertEquals(federatedUser.getUsername(), federatedIdentityModel.getUserName()); driver.navigate().to("http://localhost:8081/test-app/logout"); driver.navigate().to("http://localhost:8081/test-app"); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractKeycloakIdentityProviderTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractKeycloakIdentityProviderTest.java index f0d2ed0db8..4b61c815e9 100755 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractKeycloakIdentityProviderTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/AbstractKeycloakIdentityProviderTest.java @@ -138,7 +138,7 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent FederatedIdentityModel federatedIdentityModel = federatedIdentities.iterator().next(); assertEquals(getProviderId(), federatedIdentityModel.getIdentityProvider()); - assertEquals(federatedUser.getUsername(), federatedIdentityModel.getIdentityProvider() + "." + federatedIdentityModel.getUserName()); + assertEquals(federatedUser.getUsername(), federatedIdentityModel.getUserName()); driver.navigate().to("http://localhost:8081/test-app/logout"); driver.navigate().to("http://localhost:8081/test-app"); @@ -485,7 +485,7 @@ public abstract class AbstractKeycloakIdentityProviderTest extends AbstractIdent System.out.println("after logout currentUrl: " + currentUrl); assertTrue(currentUrl.startsWith("http://localhost:8081/auth/realms/realm-with-broker/protocol/openid-connect/auth")); - unconfigureUserRetrieveToken(getProviderId() + ".test-user"); + unconfigureUserRetrieveToken("test-user"); loginIDP("test-user"); //authenticateWithIdentityProvider(identityProviderModel, "test-user"); assertEquals("http://localhost:8081/test-app", driver.getCurrentUrl()); diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/PostBrokerFlowTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/PostBrokerFlowTest.java index dc8cc35257..9fc168fe13 100644 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/PostBrokerFlowTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/broker/PostBrokerFlowTest.java @@ -122,7 +122,7 @@ public class PostBrokerFlowTest extends AbstractIdentityProviderTest { String totpSecret = totpPage.getTotpSecret(); totpPage.configure(totp.generateTOTP(totpSecret)); - assertFederatedUser(getProviderId() + ".test-user", "test-user@localhost", "test-user", getProviderId()); + assertFederatedUser("test-user", "test-user@localhost", "test-user", getProviderId()); driver.navigate().to("http://localhost:8081/test-app/logout"); @@ -131,7 +131,7 @@ public class PostBrokerFlowTest extends AbstractIdentityProviderTest { loginTotpPage.assertCurrent(); loginTotpPage.login(totp.generateTOTP(totpSecret)); - assertFederatedUser(getProviderId() + ".test-user", "test-user@localhost", "test-user", getProviderId()); + assertFederatedUser("test-user", "test-user@localhost", "test-user", getProviderId()); driver.navigate().to("http://localhost:8081/test-app/logout"); @@ -141,7 +141,7 @@ public class PostBrokerFlowTest extends AbstractIdentityProviderTest { this.session = brokerServerRule.startSession(); loginIDP("test-user"); - assertFederatedUser(getProviderId() + ".test-user", "test-user@localhost", "test-user", getProviderId()); + assertFederatedUser("test-user", "test-user@localhost", "test-user", getProviderId()); driver.navigate().to("http://localhost:8081/test-app/logout"); } @@ -248,7 +248,7 @@ public class PostBrokerFlowTest extends AbstractIdentityProviderTest { // assert reauthentication with login page. On login page is link to kc-saml-idp-basic as user has it linked already Assert.assertEquals("Log in to " + APP_REALM_ID, this.driver.getTitle()); - Assert.assertEquals("Authenticate as kc-saml-idp-basic.test-user to link your account with " + getProviderId(), this.loginPage.getSuccessMessage()); + Assert.assertEquals("Authenticate as test-user to link your account with " + getProviderId(), this.loginPage.getSuccessMessage()); // reauthenticate with SAML broker. OTP authentication is required as well this.loginPage.clickSocial("kc-saml-idp-basic"); @@ -267,7 +267,7 @@ public class PostBrokerFlowTest extends AbstractIdentityProviderTest { } // authenticated and redirected to app. User is linked with both identity providers - assertFederatedUser("kc-saml-idp-basic.test-user", "test-user@localhost", "test-user", getProviderId(), "kc-saml-idp-basic"); + assertFederatedUser("test-user", "test-user@localhost", "test-user", getProviderId(), "kc-saml-idp-basic"); } private void setPostBrokerFlowForProvider(IdentityProviderModel identityProvider, RealmModel realm, boolean enable) {