Search in sources :

Example 6 with RolePolicyRepresentation

use of org.keycloak.representations.idm.authorization.RolePolicyRepresentation in project keycloak by keycloak.

the class RolePolicyManagementTest method assertPolicy.

private RolePolicyRepresentation assertPolicy(RolePolicyRepresentation expected, RolePolicy policy) {
    RolePolicyRepresentation actual = policy.toRepresentation();
    assertEquals(expected.getName(), actual.getName());
    assertEquals(expected.getDescription(), actual.getDescription());
    assertEquals(expected.getLogic(), actual.getLogic());
    assertNotNull(actual.getRoles());
    assertEquals(expected.getRoles().size(), actual.getRoles().size());
    assertEquals(0, actual.getRoles().stream().filter(actualDefinition -> !expected.getRoles().stream().filter(roleDefinition -> actualDefinition.getId().contains(roleDefinition.getId().indexOf("/") != -1 ? roleDefinition.getId().split("/")[1] : roleDefinition.getId()) && actualDefinition.isRequired() == roleDefinition.isRequired()).findFirst().isPresent()).count());
    return actual;
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation)

Example 7 with RolePolicyRepresentation

use of org.keycloak.representations.idm.authorization.RolePolicyRepresentation in project keycloak by keycloak.

the class RolePolicyManagementTest method testDeleteFromList.

@Test
public void testDeleteFromList() throws InterruptedException {
    authorizationPage.navigateTo();
    RolePolicyRepresentation expected = new RolePolicyRepresentation();
    expected.setName("Test Delete Role Policy");
    expected.setDescription("description");
    expected.addRole("Realm Role A");
    expected.addRole("Realm Role B");
    expected.addRole("Realm Role C");
    expected = createPolicy(expected);
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().deleteFromList(expected.getName());
    authorizationPage.navigateTo();
    assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) Test(org.junit.Test)

Example 8 with RolePolicyRepresentation

use of org.keycloak.representations.idm.authorization.RolePolicyRepresentation in project keycloak by keycloak.

the class RolePolicyManagementTest method testUpdateClientRoles.

@Test
public void testUpdateClientRoles() throws InterruptedException {
    authorizationPage.navigateTo();
    RolePolicyRepresentation expected = new RolePolicyRepresentation();
    expected.setName("Test Update Client Role Policy");
    expected.setDescription("description");
    String clientId = newClient.getClientId();
    expected.addClientRole(clientId, "Client Role A");
    expected.addClientRole(clientId, "Client Role B");
    expected.addClientRole(clientId, "Client Role C");
    expected = createPolicy(expected);
    String previousName = expected.getName();
    expected.setName("Changed Test Update Client Role Policy");
    expected.setDescription("Changed description");
    expected.setRoles(expected.getRoles().stream().filter(roleDefinition -> !roleDefinition.getId().contains("Client Role B")).collect(Collectors.toSet()));
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().update(previousName, expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    RolePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
    expected = assertPolicy(expected, actual);
    expected.getRoles().iterator().next().setRequired(true);
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().update(expected.getName(), expected);
    assertAlertSuccess();
    expected = assertPolicy(expected, actual);
    expected.getRoles().clear();
    expected.addClientRole(clientId, "Client Role B", true);
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().policies().update(expected.getName(), expected);
    assertAlertSuccess();
    assertPolicy(expected, actual);
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) RolePolicy(org.keycloak.testsuite.console.page.clients.authorization.policy.RolePolicy) Test(org.junit.Test)

Example 9 with RolePolicyRepresentation

use of org.keycloak.representations.idm.authorization.RolePolicyRepresentation in project keycloak by keycloak.

the class ScopePermissionManagementTest method configureTest.

@Before
public void configureTest() {
    super.configureTest();
    RolesResource realmRoles = testRealmResource().roles();
    realmRoles.create(new RoleRepresentation("Role A", "", false));
    realmRoles.create(new RoleRepresentation("Role B", "", false));
    RolePolicyRepresentation policyA = new RolePolicyRepresentation();
    policyA.setName("Policy A");
    policyA.addRole("Role A");
    AuthorizationResource authorization = testRealmResource().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();
    authorization.scopes().create(new ScopeRepresentation("Scope A"));
    authorization.scopes().create(new ScopeRepresentation("Scope B"));
    authorization.scopes().create(new ScopeRepresentation("Scope C"));
    ResourcesResource resources = authorization.resources();
    resources.create(new ResourceRepresentation("Resource A", "Scope A"));
    resources.create(new ResourceRepresentation("Resource B", "Scope B", "Scope C"));
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) PoliciesResource(org.keycloak.admin.client.resource.PoliciesResource) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) RolesResource(org.keycloak.admin.client.resource.RolesResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcesResource(org.keycloak.admin.client.resource.ResourcesResource) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) Before(org.junit.Before)

Example 10 with RolePolicyRepresentation

use of org.keycloak.representations.idm.authorization.RolePolicyRepresentation in project keycloak by keycloak.

the class ScopePermissionManagementTest method testCreateUpdateWithChild.

@Test
public void testCreateUpdateWithChild() {
    ScopePermissionRepresentation expected = new ScopePermissionRepresentation();
    expected.setName(UUID.randomUUID().toString());
    expected.setDescription("description");
    expected.addScope("Scope C");
    expected.addPolicy("Policy C");
    ScopePermission policy = authorizationPage.authorizationTabs().permissions().create(expected, false);
    RolePolicyRepresentation childPolicy = new RolePolicyRepresentation();
    childPolicy.setName(UUID.randomUUID().toString());
    childPolicy.addRole("Role A");
    policy.createPolicy(childPolicy);
    policy.form().save();
    assertAlertSuccess();
    expected.addPolicy(childPolicy.getName());
    authorizationPage.navigateTo();
    ScopePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    RolePolicyRepresentation childPolicy2 = new RolePolicyRepresentation();
    childPolicy2.setName(UUID.randomUUID().toString());
    childPolicy2.addRole("Role A");
    policy.createPolicy(childPolicy2);
    policy.form().save();
    assertAlertSuccess();
    expected.addPolicy(childPolicy2.getName());
    authorizationPage.navigateTo();
    actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    expected.addResource("Resource B");
    expected.getScopes().clear();
    expected.addScope("Scope B", "Scope C");
    expected.getScopes().remove("Policy C");
    RolePolicyRepresentation childPolicy3 = new RolePolicyRepresentation();
    childPolicy3.setName(UUID.randomUUID().toString());
    childPolicy3.addRole("Role A");
    policy.update(expected, false);
    policy.createPolicy(childPolicy3);
    policy.form().save();
    assertAlertSuccess();
    expected.addPolicy(childPolicy3.getName());
    authorizationPage.navigateTo();
    actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : ScopePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ScopePermission) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Aggregations

RolePolicyRepresentation (org.keycloak.representations.idm.authorization.RolePolicyRepresentation)30 Test (org.junit.Test)16 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)8 RolePoliciesResource (org.keycloak.admin.client.resource.RolePoliciesResource)8 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)7 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)6 RolesResource (org.keycloak.admin.client.resource.RolesResource)5 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)5 RolePolicyResource (org.keycloak.admin.client.resource.RolePolicyResource)4 AggregatePolicyRepresentation (org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation)4 ClientPolicyRepresentation (org.keycloak.representations.idm.authorization.ClientPolicyRepresentation)4 GroupPolicyRepresentation (org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)4 Response (javax.ws.rs.core.Response)3 Before (org.junit.Before)3 PoliciesResource (org.keycloak.admin.client.resource.PoliciesResource)3 Policy (org.keycloak.authorization.model.Policy)3 AbstractPolicyRepresentation (org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation)3 AggregatePolicy (org.keycloak.testsuite.console.page.clients.authorization.policy.AggregatePolicy)3 RolePolicy (org.keycloak.testsuite.console.page.clients.authorization.policy.RolePolicy)3 ResourcesResource (org.keycloak.admin.client.resource.ResourcesResource)2