use of org.keycloak.admin.client.resource.RoleScopeResource in project keycloak by keycloak.
the class SAMLServletAdapterTest method employeeSigTestUnicodeCharacters.
@Test
public // https://issues.jboss.org/browse/KEYCLOAK-3971
void employeeSigTestUnicodeCharacters() {
final String username = "ěščřžýáíRoàåéèíñòøöùüßÅÄÖÜ";
UserRepresentation user = UserBuilder.edit(createUserRepresentation(username, "xyz@redhat.com", "ěščřžýáí", "RoàåéèíñòøöùüßÅÄÖÜ", true)).addPassword(PASSWORD).build();
try (Creator<UserResource> u = Creator.create(testRealmResource(), user)) {
final RoleScopeResource realmRoleRes = u.resource().roles().realmLevel();
List<RoleRepresentation> availableRoles = realmRoleRes.listAvailable();
realmRoleRes.add(availableRoles.stream().filter(r -> r.getName().equalsIgnoreCase("manager")).collect(Collectors.toList()));
UserRepresentation storedUser = u.resource().toRepresentation();
Assert.assertThat(storedUser, notNullValue());
Assert.assertThat("Database seems to be unable to store Unicode for username. Refer to KEYCLOAK-3439 and related issues.", storedUser.getUsername(), equalToIgnoringCase(username));
assertSuccessfulLogin(employeeSigServletPage, user, testRealmSAMLRedirectLoginPage, "principal=" + storedUser.getUsername());
employeeSigServletPage.logout();
checkLoggedOut(employeeSigServletPage, testRealmSAMLRedirectLoginPage);
}
}
use of org.keycloak.admin.client.resource.RoleScopeResource in project keycloak by keycloak.
the class SAMLServletAdapterTest method salesPostSigTestUnicodeCharacters.
@Test
public // https://issues.jboss.org/browse/KEYCLOAK-3971
void salesPostSigTestUnicodeCharacters() {
final String username = "ěščřžýáíRoàåéèíñòøöùüßÅÄÖÜ";
UserRepresentation user = UserBuilder.edit(createUserRepresentation(username, "xyz@redhat.com", "ěščřžýáí", "RoàåéèíñòøöùüßÅÄÖÜ", true)).addPassword(PASSWORD).build();
try (Creator<UserResource> u = Creator.create(testRealmResource(), user)) {
final RoleScopeResource realmRoleRes = u.resource().roles().realmLevel();
List<RoleRepresentation> availableRoles = realmRoleRes.listAvailable();
realmRoleRes.add(availableRoles.stream().filter(r -> r.getName().equalsIgnoreCase("manager")).collect(Collectors.toList()));
UserRepresentation storedUser = u.resource().toRepresentation();
Assert.assertThat(storedUser, notNullValue());
Assert.assertThat("Database seems to be unable to store Unicode for username. Refer to KEYCLOAK-3439 and related issues.", storedUser.getUsername(), equalToIgnoringCase(username));
assertSuccessfulLogin(salesPostSigServletPage, user, testRealmSAMLPostLoginPage, "principal=" + storedUser.getUsername());
salesPostSigServletPage.logout();
checkLoggedOut(salesPostSigServletPage, testRealmSAMLPostLoginPage);
}
}
use of org.keycloak.admin.client.resource.RoleScopeResource in project keycloak by keycloak.
the class PermissionsTest method manageAccountRoleRequired.
@Test
public void manageAccountRoleRequired() throws Exception {
// remove realm level roles (no "default-roles-test") and any roles in the account client
testUserResource().roles().realmLevel().remove(testUserResource().roles().realmLevel().listAll());
String accountClientId = testRealmResource().clients().findByClientId(ACCOUNT_MANAGEMENT_CLIENT_ID).get(0).getId();
RoleScopeResource roleScopes = testUserResource().roles().clientLevel(accountClientId);
List<RoleRepresentation> roles = roleScopes.listAll();
if (!roles.isEmpty()) {
roleScopes.remove(roles);
}
welcomeScreen.header().clickLoginBtn();
loginToAccount();
// no forbidden at welcome screen yet
welcomeScreen.assertCurrent();
welcomeScreen.clickPersonalInfoLink();
forbiddenPage.assertCurrent();
signingInPage.navigateToUsingSidebar();
forbiddenPage.assertCurrent();
// still possible to sign out
forbiddenPage.header().clickLogoutBtn();
welcomeScreen.assertCurrent();
welcomeScreen.header().assertLoginBtnVisible(true);
welcomeScreen.header().assertLogoutBtnVisible(false);
}
use of org.keycloak.admin.client.resource.RoleScopeResource in project keycloak by keycloak.
the class AbstractServletAuthzAdapterTest method testRequiredRole.
@Test
public void testRequiredRole() throws Exception {
performTests(() -> {
login("jdoe", "jdoe");
navigateToUserPremiumPage();
assertWasNotDenied();
RolesResource rolesResource = getClientResource(RESOURCE_SERVER_ID).roles();
rolesResource.create(new RoleRepresentation("required-role", "", false));
RolePolicyRepresentation policy = new RolePolicyRepresentation();
policy.setName("Required Role Policy");
policy.addRole("user_premium", false);
policy.addRole(RESOURCE_SERVER_ID + "/required-role", false);
RolePoliciesResource rolePolicy = getAuthorizationResource().policies().role();
rolePolicy.create(policy);
policy = rolePolicy.findByName(policy.getName());
updatePermissionPolicies("Premium Resource Permission", policy.getName());
login("jdoe", "jdoe");
navigateToUserPremiumPage();
assertWasNotDenied();
policy.getRoles().clear();
policy.addRole("user_premium", false);
policy.addRole(RESOURCE_SERVER_ID + "/required-role", true);
rolePolicy.findById(policy.getId()).update(policy);
login("jdoe", "jdoe");
navigateToUserPremiumPage();
assertWasDenied();
UsersResource users = realmsResouce().realm(REALM_NAME).users();
UserRepresentation user = users.search("jdoe").get(0);
RoleScopeResource roleScopeResource = users.get(user.getId()).roles().clientLevel(getClientResource(RESOURCE_SERVER_ID).toRepresentation().getId());
RoleRepresentation requiredRole = rolesResource.get("required-role").toRepresentation();
roleScopeResource.add(Arrays.asList(requiredRole));
login("jdoe", "jdoe");
navigateToUserPremiumPage();
assertWasNotDenied();
policy.getRoles().clear();
policy.addRole("user_premium", false);
policy.addRole(RESOURCE_SERVER_ID + "/required-role", false);
rolePolicy.findById(policy.getId()).update(policy);
login("jdoe", "jdoe");
navigateToUserPremiumPage();
assertWasNotDenied();
roleScopeResource.remove(Arrays.asList(requiredRole));
login("jdoe", "jdoe");
navigateToUserPremiumPage();
assertWasNotDenied();
});
}
Aggregations