Search in sources :

Example 1 with ResourcePermissionResource

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

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

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

ResourcePermissionResource (org.keycloak.admin.client.resource.ResourcePermissionResource)3 ResourcePermissionsResource (org.keycloak.admin.client.resource.ResourcePermissionsResource)3 ResourcePermissionRepresentation (org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)2 NotFoundException (javax.ws.rs.NotFoundException)1