use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.
the class GroupTest method testBriefRepresentationOnGroupMembers.
@Test
public void testBriefRepresentationOnGroupMembers() {
RealmResource realm = adminClient.realms().realm("test");
String groupName = "brief-grouptest-group";
String userName = "brief-grouptest-user";
GroupsResource groups = realm.groups();
try (Response response = groups.add(GroupBuilder.create().name(groupName).build())) {
String groupId = ApiUtil.getCreatedId(response);
GroupResource group = groups.group(groupId);
UsersResource users = realm.users();
UserRepresentation userRepresentation = UserBuilder.create().username(userName).addAttribute("myattribute", "myvalue").build();
Response r = users.create(userRepresentation);
UserResource user = users.get(ApiUtil.getCreatedId(r));
user.joinGroup(groupId);
UserRepresentation defaultRepresentation = group.members(null, null).get(0);
UserRepresentation fullRepresentation = group.members(null, null, false).get(0);
UserRepresentation briefRepresentation = group.members(null, null, true).get(0);
assertEquals("full group member representation includes attributes", fullRepresentation.getAttributes(), userRepresentation.getAttributes());
assertEquals("default group member representation is full", defaultRepresentation.getAttributes(), userRepresentation.getAttributes());
assertNull("brief group member representation omits attributes", briefRepresentation.getAttributes());
group.remove();
user.remove();
}
}
use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.
the class UserPolicyManagementTest method testDeleteUser.
@Test
public void testDeleteUser() {
AuthorizationResource authorization = getClient().authorization();
UserPolicyRepresentation representation = new UserPolicyRepresentation();
representation.setName("Realm User Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addUser("User D");
representation.addUser("User E");
representation.addUser("User F");
assertCreated(authorization, representation);
UsersResource users = getRealm().users();
UserRepresentation user = users.search("User D").get(0);
users.get(user.getId()).remove();
representation = authorization.policies().user().findById(representation.getId()).toRepresentation();
Assert.assertEquals(2, representation.getUsers().size());
Assert.assertFalse(representation.getUsers().contains(user.getId()));
user = users.search("User E").get(0);
users.get(user.getId()).remove();
representation = authorization.policies().user().findById(representation.getId()).toRepresentation();
Assert.assertEquals(1, representation.getUsers().size());
Assert.assertFalse(representation.getUsers().contains(user.getId()));
user = users.search("User F").get(0);
users.get(user.getId()).remove();
try {
authorization.policies().user().findById(representation.getId()).toRepresentation();
fail("User policy should be removed");
} catch (NotFoundException nfe) {
// ignore
}
}
use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.
the class AggregatePolicyManagementTest method configureTest.
@Before
public void configureTest() {
super.configureTest();
RealmResource realmResource = testRealmResource();
RolesResource realmRoles = realmResource.roles();
realmRoles.create(new RoleRepresentation("Role A", "", false));
realmRoles.create(new RoleRepresentation("Role B", "", false));
UsersResource users = realmResource.users();
users.create(UserBuilder.create().username("user a").build());
ClientsResource clients = realmResource.clients();
clients.create(ClientBuilder.create().clientId("client a").build());
realmResource.groups().add(GroupBuilder.create().name("Group A").build());
RolePolicyRepresentation policyA = new RolePolicyRepresentation();
policyA.setName("Policy A");
policyA.addRole("Role A");
AuthorizationResource authorization = realmResource.clients().get(newClient.getId()).authorization();
PoliciesResource policies = authorization.policies();
RolePoliciesResource roles = policies.role();
roles.create(policyA);
RolePolicyRepresentation policyB = new RolePolicyRepresentation();
policyB.setName("Policy B");
policyB.addRole("Role B");
roles.create(policyB);
UserPolicyRepresentation policyC = new UserPolicyRepresentation();
policyC.setName("Policy C");
policyC.addUser("test");
policies.user().create(policyC).close();
}
use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.
the class UserAttributeUpdater method forUserByUsername.
public static UserAttributeUpdater forUserByUsername(RealmResource realm, String userName) {
UsersResource users = realm.users();
List<UserRepresentation> foundUsers = users.search(userName).stream().filter(ur -> userName.equalsIgnoreCase(ur.getUsername())).collect(Collectors.toList());
assertThat(foundUsers, hasSize(1));
UserResource userRes = users.get(foundUsers.get(0).getId());
return new UserAttributeUpdater(userRes, realm);
}
use of org.keycloak.admin.client.resource.UsersResource in project keycloak by keycloak.
the class KcSamlIdPInitiatedSsoTest method testProviderIdpInitiatedLogin.
@Test
public void testProviderIdpInitiatedLogin() throws Exception {
driver.navigate().to(getSamlIdpInitiatedUrl(REALM_PROV_NAME, "samlbroker"));
waitForPage("sign in to", true);
Assert.assertThat("Driver should be on the provider realm page right now", driver.getCurrentUrl(), containsString("/auth/realms/" + REALM_PROV_NAME + "/"));
log.debug("Logging in");
accountLoginPage.login(PROVIDER_REALM_USER_NAME, PROVIDER_REALM_USER_PASSWORD);
waitForPage("update account information", false);
Assert.assertTrue(updateAccountInformationPage.isCurrent());
Assert.assertThat("We must be on consumer realm right now", driver.getCurrentUrl(), containsString("/auth/realms/" + REALM_CONS_NAME + "/"));
log.debug("Updating info on updateAccount page");
updateAccountInformationPage.updateAccountInformation(CONSUMER_CHOSEN_USERNAME, "test@localhost", "Firstname", "Lastname");
UsersResource consumerUsers = adminClient.realm(REALM_CONS_NAME).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 = users.stream().anyMatch(user -> user.getUsername().equals(CONSUMER_CHOSEN_USERNAME) && user.getEmail().equals("test@localhost"));
Assert.assertTrue("There must be user " + CONSUMER_CHOSEN_USERNAME + " in realm " + REALM_CONS_NAME, isUserFound);
Assert.assertThat(driver.findElement(By.tagName("a")).getAttribute("id"), containsString("account"));
}
Aggregations