Search in sources :

Example 26 with RolePolicyRepresentation

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

the class RolePolicyManagementTest method testDelete.

@Test
public void testDelete() 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().delete(expected.getName());
    assertAlertSuccess();
    authorizationPage.navigateTo();
    assertNull(authorizationPage.authorizationTabs().policies().policies().findByName(expected.getName()));
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) Test(org.junit.Test)

Example 27 with RolePolicyRepresentation

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

the class ResourcePermissionManagementTest method testCreateWithChild.

@Test
public void testCreateWithChild() {
    ResourcePermissionRepresentation expected = new ResourcePermissionRepresentation();
    expected.setName(UUID.randomUUID().toString());
    expected.setDescription("description");
    expected.addResource("Resource B");
    expected.addPolicy("Policy C");
    ResourcePermission 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();
    ResourcePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) ResourcePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 28 with RolePolicyRepresentation

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

the class ResourcePermissionManagementTest 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();
    ResourcesResource resources = authorization.resources();
    resources.create(new ResourceRepresentation("Resource A"));
    resources.create(new ResourceRepresentation("Resource B"));
}
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) 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 29 with RolePolicyRepresentation

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

the class AggregatePolicyManagementTest method testUpdateWithChild.

@Test
public void testUpdateWithChild() {
    AggregatePolicyRepresentation expected = new AggregatePolicyRepresentation();
    expected.setName("Test Child Update Aggregate Policy");
    expected.setDescription("description");
    expected.addPolicy("Policy C");
    AggregatePolicy policy = authorizationPage.authorizationTabs().policies().create(expected);
    assertAlertSuccess();
    assertPolicy(expected, policy);
    RolePolicyRepresentation childPolicy = new RolePolicyRepresentation();
    childPolicy.setName(UUID.randomUUID().toString());
    childPolicy.addRole("Role A");
    policy.createPolicy(childPolicy);
    policy.form().save();
    expected.addPolicy(childPolicy.getName());
    authorizationPage.navigateTo();
    AggregatePolicy actual = authorizationPage.authorizationTabs().policies().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) AggregatePolicy(org.keycloak.testsuite.console.page.clients.authorization.policy.AggregatePolicy) AggregatePolicyRepresentation(org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation) Test(org.junit.Test)

Example 30 with RolePolicyRepresentation

use of org.keycloak.representations.idm.authorization.RolePolicyRepresentation 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();
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) UsersResource(org.keycloak.admin.client.resource.UsersResource) ClientsResource(org.keycloak.admin.client.resource.ClientsResource) RolePoliciesResource(org.keycloak.admin.client.resource.RolePoliciesResource) 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) Before(org.junit.Before)

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