Search in sources :

Example 1 with ResourcePermissionsResource

use of org.keycloak.admin.client.resource.ResourcePermissionsResource in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testUpdate.

@Test
public void testUpdate() {
    AuthorizationResource authorization = getClient().authorization();
    ResourcePermissionRepresentation representation = new ResourcePermissionRepresentation();
    representation.setName("Update Test Resource Permission");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.addResource("Resource A");
    representation.addPolicy("Only Marta Policy", "Only Kolo Policy");
    assertCreated(authorization, representation);
    representation.setName("changed");
    representation.setDescription("changed");
    representation.setDecisionStrategy(DecisionStrategy.AFFIRMATIVE);
    representation.setLogic(Logic.POSITIVE);
    representation.getResources().remove("Resource A");
    representation.addResource("Resource B");
    representation.getPolicies().remove("Only Marta Policy");
    ResourcePermissionsResource permissions = authorization.permissions().resource();
    ResourcePermissionResource permission = permissions.findById(representation.getId());
    permission.update(representation);
    assertRepresentation(representation, permission);
    representation.getResources().clear();
    representation.setResourceType("changed");
    permission.update(representation);
    assertRepresentation(representation, permission);
}
Also used : ResourcePermissionResource(org.keycloak.admin.client.resource.ResourcePermissionResource) ResourcePermissionsResource(org.keycloak.admin.client.resource.ResourcePermissionsResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 2 with ResourcePermissionsResource

use of org.keycloak.admin.client.resource.ResourcePermissionsResource 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 3 with ResourcePermissionsResource

use of org.keycloak.admin.client.resource.ResourcePermissionsResource in project keycloak by keycloak.

the class ResourcePermissionManagementTest method testDelete.

@Test
public void testDelete() {
    AuthorizationResource authorization = getClient().authorization();
    ResourcePermissionRepresentation representation = new ResourcePermissionRepresentation();
    representation.setName("Test Delete Permission");
    representation.setResourceType("test-resource");
    representation.addPolicy("Only Marta Policy");
    ResourcePermissionsResource permissions = authorization.permissions().resource();
    try (Response response = permissions.create(representation)) {
        ResourcePermissionRepresentation created = response.readEntity(ResourcePermissionRepresentation.class);
        permissions.findById(created.getId()).remove();
        ResourcePermissionResource removed = permissions.findById(created.getId());
        try {
            removed.toRepresentation();
            fail("Permission not removed");
        } catch (NotFoundException ignore) {
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ResourcePermissionResource(org.keycloak.admin.client.resource.ResourcePermissionResource) NotFoundException(javax.ws.rs.NotFoundException) ResourcePermissionsResource(org.keycloak.admin.client.resource.ResourcePermissionsResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 4 with ResourcePermissionsResource

use of org.keycloak.admin.client.resource.ResourcePermissionsResource in project keycloak by keycloak.

the class ResourcePermissionManagementTest method failCreateWithSameName.

@Test
public void failCreateWithSameName() {
    AuthorizationResource authorization = getClient().authorization();
    ResourcePermissionRepresentation permission1 = new ResourcePermissionRepresentation();
    permission1.setName("Conflicting Name Permission");
    permission1.setResourceType("test-resource");
    permission1.addPolicy("Only Marta Policy");
    ResourcePermissionsResource permissions = authorization.permissions().resource();
    permissions.create(permission1).close();
    ResourcePermissionRepresentation permission2 = new ResourcePermissionRepresentation();
    permission2.setName(permission1.getName());
    try (Response response = permissions.create(permission2)) {
        assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
    }
}
Also used : Response(javax.ws.rs.core.Response) ResourcePermissionsResource(org.keycloak.admin.client.resource.ResourcePermissionsResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation) Test(org.junit.Test)

Example 5 with ResourcePermissionsResource

use of org.keycloak.admin.client.resource.ResourcePermissionsResource in project keycloak by keycloak.

the class ResourcePermissionManagementTest method assertCreated.

private void assertCreated(AuthorizationResource authorization, ResourcePermissionRepresentation representation) {
    ResourcePermissionsResource permissions = authorization.permissions().resource();
    try (Response response = permissions.create(representation)) {
        ResourcePermissionRepresentation created = response.readEntity(ResourcePermissionRepresentation.class);
        ResourcePermissionResource permission = permissions.findById(created.getId());
        assertRepresentation(representation, permission);
    }
}
Also used : Response(javax.ws.rs.core.Response) ResourcePermissionResource(org.keycloak.admin.client.resource.ResourcePermissionResource) ResourcePermissionsResource(org.keycloak.admin.client.resource.ResourcePermissionsResource) ResourcePermissionRepresentation(org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)

Aggregations

ResourcePermissionsResource (org.keycloak.admin.client.resource.ResourcePermissionsResource)6 ResourcePermissionRepresentation (org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)6 Test (org.junit.Test)4 Response (javax.ws.rs.core.Response)3 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)3 ResourcePermissionResource (org.keycloak.admin.client.resource.ResourcePermissionResource)3 NotFoundException (javax.ws.rs.NotFoundException)1 ResourcePermission (org.keycloak.testsuite.console.page.clients.authorization.permission.ResourcePermission)1