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));
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations