Search in sources :

Example 1 with ScopePermissionResource

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

the class ScopePermissionManagementTest method testDelete.

@Test
public void testDelete() {
    AuthorizationResource authorization = getClient().authorization();
    ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
    representation.setName("Test Delete Permission");
    representation.addScope("execute");
    representation.addPolicy("Only Marta Policy");
    assertCreated(authorization, representation);
    ScopePermissionsResource permissions = authorization.permissions().scope();
    permissions.findById(representation.getId()).remove();
    ScopePermissionResource removed = permissions.findById(representation.getId());
    try {
        removed.toRepresentation();
        fail("Permission not removed");
    } catch (NotFoundException ignore) {
    }
}
Also used : ScopePermissionResource(org.keycloak.admin.client.resource.ScopePermissionResource) NotFoundException(javax.ws.rs.NotFoundException) ScopePermissionsResource(org.keycloak.admin.client.resource.ScopePermissionsResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Example 2 with ScopePermissionResource

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

the class ScopePermissionManagementTest method assertCreated.

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

Example 3 with ScopePermissionResource

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

the class ScopePermissionManagementTest method testUpdate.

@Test
public void testUpdate() {
    AuthorizationResource authorization = getClient().authorization();
    ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
    representation.setName("Update Test Scope Permission");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.addResource("Resource A");
    representation.addScope("read", "execute");
    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.getScopes().remove("execute");
    representation.getPolicies().remove("Only Marta Policy");
    ScopePermissionsResource permissions = authorization.permissions().scope();
    ScopePermissionResource permission = permissions.findById(representation.getId());
    permission.update(representation);
    assertRepresentation(representation, permission);
}
Also used : ScopePermissionResource(org.keycloak.admin.client.resource.ScopePermissionResource) ScopePermissionsResource(org.keycloak.admin.client.resource.ScopePermissionsResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) ScopePermissionRepresentation(org.keycloak.representations.idm.authorization.ScopePermissionRepresentation) Test(org.junit.Test)

Aggregations

ScopePermissionResource (org.keycloak.admin.client.resource.ScopePermissionResource)3 ScopePermissionsResource (org.keycloak.admin.client.resource.ScopePermissionsResource)3 ScopePermissionRepresentation (org.keycloak.representations.idm.authorization.ScopePermissionRepresentation)3 Test (org.junit.Test)2 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)2 NotFoundException (javax.ws.rs.NotFoundException)1 Response (javax.ws.rs.core.Response)1