Search in sources :

Example 66 with IdentityProviderRepresentation

use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.

the class KcOidcBrokerTest method loginFetchingUserFromUserEndpoint.

@Test
public void loginFetchingUserFromUserEndpoint() {
    RealmResource realm = realmsResouce().realm(bc.providerRealmName());
    ClientsResource clients = realm.clients();
    ClientRepresentation brokerApp = clients.findByClientId("brokerapp").get(0);
    try {
        IdentityProviderResource identityProviderResource = realmsResouce().realm(bc.consumerRealmName()).identityProviders().get(bc.getIDPAlias());
        IdentityProviderRepresentation idp = identityProviderResource.toRepresentation();
        idp.getConfig().put(OIDCIdentityProviderConfig.JWKS_URL, getProviderRoot() + "/auth/realms/" + REALM_PROV_NAME + "/protocol/openid-connect/certs");
        identityProviderResource.update(idp);
        brokerApp.getAttributes().put(OIDCConfigAttributes.USER_INFO_RESPONSE_SIGNATURE_ALG, Algorithm.RS256);
        brokerApp.getAttributes().put("validateSignature", Boolean.TRUE.toString());
        clients.get(brokerApp.getId()).update(brokerApp);
        driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
        logInWithBroker(bc);
        waitForPage(driver, "update account information", false);
        updateAccountInformationPage.assertCurrent();
        Assert.assertTrue("We must be on correct realm right now", driver.getCurrentUrl().contains("/auth/realms/" + bc.consumerRealmName() + "/"));
        log.debug("Updating info on updateAccount page");
        updateAccountInformationPage.updateAccountInformation(bc.getUserLogin(), bc.getUserEmail(), "Firstname", "Lastname");
        UsersResource consumerUsers = adminClient.realm(bc.consumerRealmName()).users();
        int userCount = consumerUsers.count();
        Assert.assertTrue("There must be at least one user", userCount > 0);
        List<UserRepresentation> users = consumerUsers.search("", 0, userCount);
        boolean isUserFound = false;
        for (UserRepresentation user : users) {
            if (user.getUsername().equals(bc.getUserLogin()) && user.getEmail().equals(bc.getUserEmail())) {
                isUserFound = true;
                break;
            }
        }
        Assert.assertTrue("There must be user " + bc.getUserLogin() + " in realm " + bc.consumerRealmName(), isUserFound);
    } finally {
        brokerApp.getAttributes().put(OIDCConfigAttributes.USER_INFO_RESPONSE_SIGNATURE_ALG, null);
        brokerApp.getAttributes().put("validateSignature", Boolean.FALSE.toString());
        clients.get(brokerApp.getId()).update(brokerApp);
    }
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) RealmResource(org.keycloak.admin.client.resource.RealmResource) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) UsersResource(org.keycloak.admin.client.resource.UsersResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 67 with IdentityProviderRepresentation

use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.

the class KcOidcBrokerTest method checkUpdatedUserAttributesIdP.

private void checkUpdatedUserAttributesIdP(boolean isForceSync) {
    final String IDP_NAME = getBrokerConfiguration().getIDPAlias();
    final String USERNAME = "demoUser";
    final String FIRST_NAME = "John";
    final String LAST_NAME = "Doe";
    final String EMAIL = "mail@example.com";
    final String NEW_FIRST_NAME = "Jack";
    final String NEW_LAST_NAME = "Doee";
    final String NEW_EMAIL = "mail123@example.com";
    UsersResource providerUserResource = Optional.ofNullable(realmsResouce().realm(bc.providerRealmName()).users()).orElse(null);
    assertThat("Cannot get User Resource from Provider realm", providerUserResource, Matchers.notNullValue());
    String userID = createUser(bc.providerRealmName(), USERNAME, USERNAME, FIRST_NAME, LAST_NAME, EMAIL);
    assertThat("Cannot create user : " + USERNAME, userID, Matchers.notNullValue());
    try {
        UserRepresentation user = Optional.ofNullable(providerUserResource.get(userID).toRepresentation()).orElse(null);
        assertThat("Cannot get user from provider", user, Matchers.notNullValue());
        IdentityProviderResource consumerIdentityResource = Optional.ofNullable(getIdentityProviderResource()).orElse(null);
        assertThat("Cannot get Identity Provider resource", consumerIdentityResource, Matchers.notNullValue());
        IdentityProviderRepresentation idProvider = Optional.ofNullable(consumerIdentityResource.toRepresentation()).orElse(null);
        assertThat("Cannot get Identity Provider", idProvider, Matchers.notNullValue());
        updateIdPSyncMode(idProvider, consumerIdentityResource, isForceSync ? IdentityProviderSyncMode.FORCE : IdentityProviderSyncMode.IMPORT);
        driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
        WaitUtils.waitForPageToLoad();
        assertThat(driver.getTitle(), Matchers.containsString("Sign in to " + bc.consumerRealmName()));
        logInWithIdp(IDP_NAME, USERNAME, USERNAME);
        accountUpdateProfilePage.assertCurrent();
        logoutFromRealm(getProviderRoot(), bc.providerRealmName());
        logoutFromRealm(getConsumerRoot(), bc.consumerRealmName());
        driver.navigate().to(getAccountUrl(getProviderRoot(), bc.providerRealmName()));
        WaitUtils.waitForPageToLoad();
        assertThat(driver.getTitle(), Matchers.containsString("Sign in to " + bc.providerRealmName()));
        loginPage.login(USERNAME, USERNAME);
        WaitUtils.waitForPageToLoad();
        accountUpdateProfilePage.assertCurrent();
        accountUpdateProfilePage.updateProfile(NEW_FIRST_NAME, NEW_LAST_NAME, NEW_EMAIL);
        logoutFromRealm(getProviderRoot(), bc.providerRealmName());
        driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
        WaitUtils.waitForPageToLoad();
        assertThat(driver.getTitle(), Matchers.containsString("Sign in to " + bc.consumerRealmName()));
        logInWithIdp(IDP_NAME, USERNAME, USERNAME);
        accountUpdateProfilePage.assertCurrent();
        assertThat(accountUpdateProfilePage.getEmail(), Matchers.equalTo(isForceSync ? NEW_EMAIL : EMAIL));
        assertThat(accountUpdateProfilePage.getFirstName(), Matchers.equalTo(isForceSync ? NEW_FIRST_NAME : FIRST_NAME));
        assertThat(accountUpdateProfilePage.getLastName(), Matchers.equalTo(isForceSync ? NEW_LAST_NAME : LAST_NAME));
    } finally {
        providerUserResource.delete(userID);
        assertThat("User wasn't deleted", providerUserResource.search(USERNAME).size(), Matchers.is(0));
    }
}
Also used : IdentityProviderResource(org.keycloak.admin.client.resource.IdentityProviderResource) UsersResource(org.keycloak.admin.client.resource.UsersResource) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Example 68 with IdentityProviderRepresentation

use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.

the class AbstractFirstBrokerLoginTest method testVerifyEmailNotRequiredActionWhenEmailIsTrustedByProvider.

/**
 * Refers to in old test suite: org.keycloak.testsuite.broker.AbstractKeycloakIdentityProviderTest#testSuccessfulAuthenticationWithoutUpdateProfile_emailProvided_emailVerifyEnabled_emailTrustEnabled
 */
@Test
public void testVerifyEmailNotRequiredActionWhenEmailIsTrustedByProvider() {
    RealmResource realm = adminClient.realm(bc.consumerRealmName());
    RealmRepresentation realmRep = realm.toRepresentation();
    realmRep.setVerifyEmail(true);
    realm.update(realmRep);
    IdentityProviderRepresentation idpRep = identityProviderResource.toRepresentation();
    idpRep.setTrustEmail(true);
    identityProviderResource.update(idpRep);
    driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
    logInWithBroker(bc);
    waitForPage(driver, "update account information", false);
    updateAccountInformationPage.assertCurrent();
    updateAccountInformationPage.updateAccountInformation("FirstName", "LastName");
    waitForAccountManagementTitle();
    accountUpdateProfilePage.assertCurrent();
    List<UserRepresentation> users = realm.users().search(bc.getUserLogin());
    assertEquals(1, users.size());
    List<String> requiredActions = users.get(0).getRequiredActions();
    assertEquals(0, requiredActions.size());
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test) VerifyProfileTest(org.keycloak.testsuite.forms.VerifyProfileTest)

Example 69 with IdentityProviderRepresentation

use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.

the class AbstractFirstBrokerLoginTest method testLinkAccountWithUntrustedEmailVerified.

/**
 * Refers to in old test suite: org.keycloak.testsuite.broker.AbstractKeycloakIdentityProviderTest#testSuccessfulAuthenticationWithoutUpdateProfile_emailProvided_emailVerifyEnabled
 */
@Test
public void testLinkAccountWithUntrustedEmailVerified() {
    RealmResource realm = adminClient.realm(bc.consumerRealmName());
    RealmRepresentation realmRep = realm.toRepresentation();
    realmRep.setVerifyEmail(true);
    realm.update(realmRep);
    IdentityProviderRepresentation idpRep = identityProviderResource.toRepresentation();
    idpRep.setTrustEmail(false);
    identityProviderResource.update(idpRep);
    configureSMTPServer();
    driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
    logInWithBroker(bc);
    waitForPage(driver, "update account information", false);
    updateAccountInformationPage.assertCurrent();
    updateAccountInformationPage.updateAccountInformation("FirstName", "LastName");
    verifyEmailPage.assertCurrent();
    String verificationUrl = assertEmailAndGetUrl(MailServerConfiguration.FROM, USER_EMAIL, "verify your email address", false);
    driver.navigate().to(verificationUrl.trim());
    waitForAccountManagementTitle();
    accountUpdateProfilePage.assertCurrent();
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) Test(org.junit.Test) VerifyProfileTest(org.keycloak.testsuite.forms.VerifyProfileTest)

Example 70 with IdentityProviderRepresentation

use of org.keycloak.representations.idm.IdentityProviderRepresentation in project keycloak by keycloak.

the class AbstractGroupMapperTest method loginAsUserTwiceWithMapper.

protected UserRepresentation loginAsUserTwiceWithMapper(IdentityProviderMapperSyncMode syncMode, boolean createAfterFirstLogin, Map<String, List<String>> userConfig) {
    final IdentityProviderRepresentation idp = setupIdentityProvider();
    if (!createAfterFirstLogin) {
        createMapperInIdp(idp, syncMode);
    }
    createUserInProviderRealm(userConfig);
    logInAsUserInIDPForFirstTime();
    UserRepresentation user = findUser(bc.consumerRealmName(), bc.getUserLogin(), bc.getUserEmail());
    if (!createAfterFirstLogin) {
        assertThatUserHasBeenAssignedToGroup(user);
    } else {
        assertThatUserHasNotBeenAssignedToGroup(user);
    }
    if (createAfterFirstLogin) {
        createMapperInIdp(idp, syncMode);
    }
    logoutFromRealm(getConsumerRoot(), bc.consumerRealmName());
    updateUser();
    logInAsUserInIDP();
    user = findUser(bc.consumerRealmName(), bc.getUserLogin(), bc.getUserEmail());
    return user;
}
Also used : IdentityProviderRepresentation(org.keycloak.representations.idm.IdentityProviderRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Aggregations

IdentityProviderRepresentation (org.keycloak.representations.idm.IdentityProviderRepresentation)91 Test (org.junit.Test)45 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)23 RealmResource (org.keycloak.admin.client.resource.RealmResource)22 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)17 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)16 Response (javax.ws.rs.core.Response)15 Matchers.containsString (org.hamcrest.Matchers.containsString)10 List (java.util.List)9 MultipartFormDataOutput (org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataOutput)8 URL (java.net.URL)7 IdentityProviderMapperRepresentation (org.keycloak.representations.idm.IdentityProviderMapperRepresentation)7 OAuthClient (org.keycloak.testsuite.util.OAuthClient)7 IOException (java.io.IOException)6 URI (java.net.URI)6 Map (java.util.Map)6 Matchers.hasSize (org.hamcrest.Matchers.hasSize)6 Matchers.is (org.hamcrest.Matchers.is)6 SAMLIdentityProviderConfig (org.keycloak.broker.saml.SAMLIdentityProviderConfig)6 AttributeType (org.keycloak.dom.saml.v2.assertion.AttributeType)6