Search in sources :

Example 1 with ResourcePermission

use of org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testUpdateResourceType.

@Test
public void testUpdateResourceType() throws InterruptedException {
    authorizationPage.navigateTo();
    ResourcePermissionRepresentation expected = new ResourcePermissionRepresentation();
    expected.setName("testUpdateResourceType Permission");
    expected.setDescription("description");
    expected.setResourceType("test-resource-type");
    expected.addPolicy("Policy A");
    expected.addPolicy("Policy B");
    expected.addPolicy("Policy C");
    expected = createPermission(expected);
    String previousName = expected.getName();
    expected.setName(expected.getName() + " Changed");
    expected.setDescription("Changed description");
    expected.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    expected.setResourceType("changed-resource-type");
    expected.setPolicies(expected.getPolicies().stream().filter(policy -> !policy.equals("Policy B")).collect(Collectors.toSet()));
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(previousName, expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    ResourcePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    expected.setResourceType(null);
    expected.addResource("Resource A");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(expected.getName(), expected);
    assertAlertSuccess();
    ResourcePermissionsResource resourcePermission = testRealmResource().clients().get(newClient.getId()).authorization().permissions().resource();
    ResourcePermissionRepresentation permission = resourcePermission.findByName(expected.getName());
    assertFalse(resourcePermission.findById(permission.getId()).resources().isEmpty());
    expected.setResourceType("test");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(expected.getName(), expected);
    assertAlertSuccess();
    assertTrue(resourcePermission.findById(permission.getId()).resources().isEmpty());
}
Also used : ResourcePermissionsResource(org.keycloak.admin.client.resource.ResourcePermissionsResource) ResourcePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 2 with ResourcePermission

use of org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission in project keycloak by keycloak.

the class ResourcePermissionManagementTest method createPermission.

private ResourcePermissionRepresentation createPermission(ResourcePermissionRepresentation expected) {
    ResourcePermission policy = authorizationPage.authorizationTabs().permissions().create(expected, true);
    assertAlertSuccess();
    return assertPolicy(expected, policy);
}
Also used : ResourcePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission)

Example 3 with ResourcePermission

use of org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testUpdateResource.

@Test
public void testUpdateResource() throws InterruptedException {
    authorizationPage.navigateTo();
    ResourcePermissionRepresentation expected = new ResourcePermissionRepresentation();
    expected.setName("testUpdateResource Permission");
    expected.setDescription("description");
    expected.addResource("Resource A");
    expected.addPolicy("Policy A");
    expected.addPolicy("Policy B");
    expected.addPolicy("Policy C");
    expected = createPermission(expected);
    String previousName = expected.getName();
    expected.setName(expected.getName() + " Changed");
    expected.setDescription("Changed description");
    expected.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    expected.getResources().clear();
    expected.addResource("Resource B");
    expected.getPolicies().clear();
    expected.addPolicy("Policy A", "Policy C");
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(previousName, expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    ResourcePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
    expected.getPolicies().clear();
    authorizationPage.navigateTo();
    authorizationPage.authorizationTabs().permissions().update(expected.getName(), expected);
    assertAlertSuccess();
    authorizationPage.navigateTo();
    actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : ResourcePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 4 with ResourcePermission

use of org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission 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 5 with ResourcePermission

use of org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testCreateWithoutPolicies.

@Test
public void testCreateWithoutPolicies() throws InterruptedException {
    authorizationPage.navigateTo();
    ResourcePermissionRepresentation expected = new ResourcePermissionRepresentation();
    expected.setName("testCreateWithoutPolicies Permission");
    expected.setDescription("description");
    expected.addResource("Resource A");
    expected = createPermission(expected);
    authorizationPage.navigateTo();
    ResourcePermission actual = authorizationPage.authorizationTabs().permissions().name(expected.getName());
    assertPolicy(expected, actual);
}
Also used : ResourcePermission(org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Aggregations

ResourcePermission (org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission)5 Test (org.junit.Test)4 ResourcePermissionRepresentation (org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)4 ResourcePermissionsResource (org.keycloak.admin.client.resource.ResourcePermissionsResource)1 RolePolicyRepresentation (org.keycloak.representations.idm.authorization.RolePolicyRepresentation)1