Search in sources :

Example 16 with UsersResource

use of org.keycloak.admin.client.resource.UsersResource in project ART-TIME by Artezio.

the class KeycloakClientTest method testListGroups.

@Test
public void testListGroups() {
    UserRepresentation user = new UserRepresentation();
    RealmResource realm = mock(RealmResource.class);
    UsersResource usersResource = mock(UsersResource.class);
    UserResource userResource = mock(UserResource.class);
    String group1 = "Group1";
    String group2 = "Group_2";
    String userId = "id-user";
    user.setId(userId);
    expect(realm.users()).andReturn(usersResource);
    expect(usersResource.get(userId)).andReturn(userResource);
    GroupRepresentation groupRepresentation1 = new GroupRepresentation();
    GroupRepresentation groupRepresentation2 = new GroupRepresentation();
    groupRepresentation1.setName(group1);
    groupRepresentation2.setName(group2);
    expect(userResource.groups()).andReturn(Arrays.asList(groupRepresentation1, groupRepresentation2));
    replay(realm, usersResource, userResource);
    Set<String> actual = keycloakClient.listGroups(user, realm);
    verify(realm);
    assertFalse(actual.isEmpty());
    assertTrue(actual.contains(group1));
    assertTrue(actual.contains(group2));
}
Also used : GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) UsersResource(org.keycloak.admin.client.resource.UsersResource) UserResource(org.keycloak.admin.client.resource.UserResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 17 with UsersResource

use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.

the class Creator method create.

public static Creator<UserResource> create(RealmResource realmResource, UserRepresentation rep) {
    final UsersResource users = realmResource.users();
    try (Response response = users.create(rep)) {
        String createdId = getCreatedId(response);
        final UserResource r = users.get(createdId);
        LOG.debugf("Created user ID %s", createdId);
        return new Creator(createdId, r, r::remove);
    }
}
Also used : Response(javax.ws.rs.core.Response) Logger(org.jboss.logging.Logger) UsersResource(org.keycloak.admin.client.resource.UsersResource) UserResource(org.keycloak.admin.client.resource.UserResource)

Example 18 with UsersResource

use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.

the class KcOidcBrokerLoginHintTest method loginUser.

@Override
protected void loginUser() {
    driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
    driver.navigate().to(driver.getCurrentUrl() + "&login_hint=" + USER_EMAIL);
    log.debug("Clicking social " + bc.getIDPAlias());
    loginPage.clickSocial(bc.getIDPAlias());
    waitForPage(driver, "sign in to", true);
    Assert.assertTrue("Driver should be on the provider realm page right now", driver.getCurrentUrl().contains("/auth/realms/" + bc.providerRealmName() + "/"));
    Assert.assertTrue("User identifiant should be fullfilled", loginPage.getUsername().equalsIgnoreCase(USER_EMAIL));
    log.debug("Logging in");
    loginPage.login(bc.getUserPassword());
    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);
}
Also used : UsersResource(org.keycloak.admin.client.resource.UsersResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Example 19 with UsersResource

use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.

the class AccountLinkTest method testDeleteIdentityOnProviderRemoval.

@Test
public void testDeleteIdentityOnProviderRemoval() {
    String childUsername = "child";
    String childPassword = "password";
    String childIdp = CHILD_IDP;
    assertFederatedIdentity(childUsername, childPassword, childIdp);
    RealmResource realm = adminClient.realm(CHILD_IDP);
    UsersResource users = realm.users();
    List<UserRepresentation> search = users.search(childUsername);
    assertFalse(search.isEmpty());
    String userId = search.get(0).getId();
    List<FederatedIdentityRepresentation> identities = users.get(userId).getFederatedIdentity();
    assertFalse(identities.isEmpty());
    realm.identityProviders().get(PARENT_IDP).remove();
    identities = users.get(userId).getFederatedIdentity();
    assertTrue(identities.isEmpty());
    getTestingClient().server(CHILD_IDP).run(AccountLinkTest::checkEmptyFederatedIdentities);
}
Also used : RealmResource(org.keycloak.admin.client.resource.RealmResource) UsersResource(org.keycloak.admin.client.resource.UsersResource) FederatedIdentityRepresentation(org.keycloak.representations.idm.FederatedIdentityRepresentation) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 20 with UsersResource

use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.

the class KcOidcBrokerAcrParameterTest method loginUser.

@Override
protected void loginUser() {
    driver.navigate().to(getAccountUrl(getConsumerRoot(), bc.consumerRealmName()));
    driver.navigate().to(driver.getCurrentUrl() + "&" + ACR_VALUES + "=" + ACR_3);
    log.debug("Clicking social " + bc.getIDPAlias());
    loginPage.clickSocial(bc.getIDPAlias());
    waitForPage(driver, "sign in to", true);
    Assert.assertTrue("Driver should be on the provider realm page right now", driver.getCurrentUrl().contains("/auth/realms/" + bc.providerRealmName() + "/"));
    Assert.assertTrue(ACR_VALUES + "=" + ACR_3 + " should be part of the url", driver.getCurrentUrl().contains(ACR_VALUES + "=" + ACR_3));
    log.debug("Logging in");
    loginPage.login(bc.getUserLogin(), bc.getUserPassword());
    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);
}
Also used : UsersResource(org.keycloak.admin.client.resource.UsersResource) UserRepresentation(org.keycloak.representations.idm.UserRepresentation)

Aggregations

UsersResource (org.keycloak.admin.client.resource.UsersResource)36 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)32 Test (org.junit.Test)18 UserResource (org.keycloak.admin.client.resource.UserResource)10 RealmResource (org.keycloak.admin.client.resource.RealmResource)9 Response (javax.ws.rs.core.Response)7 ClientsResource (org.keycloak.admin.client.resource.ClientsResource)7 Map (java.util.Map)6 List (java.util.List)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Before (org.junit.Before)5 UserSessionRepresentation (org.keycloak.representations.idm.UserSessionRepresentation)5 IdentityProviderResource (org.keycloak.admin.client.resource.IdentityProviderResource)4 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)4 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Matchers.hasSize (org.hamcrest.Matchers.hasSize)3 Assert.assertThat (org.junit.Assert.assertThat)3 RolesResource (org.keycloak.admin.client.resource.RolesResource)3 AbstractKeycloakTest (org.keycloak.testsuite.AbstractKeycloakTest)3