Search in sources :

Example 1 with JSPolicyResource

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

the class JSPolicyManagementTest method testUpdate.

@Test
public void testUpdate() {
    AuthorizationResource authorization = getClient().authorization();
    JSPolicyRepresentation representation = new JSPolicyRepresentation();
    representation.setName("Update JS Policy");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    representation.setCode("$evaluation.grant();");
    assertCreated(authorization, representation);
    representation.setName("changed");
    representation.setDescription("changed");
    representation.setDecisionStrategy(DecisionStrategy.AFFIRMATIVE);
    representation.setLogic(Logic.POSITIVE);
    representation.setCode("$evaluation.deny()");
    JSPoliciesResource policies = authorization.policies().js();
    JSPolicyResource permission = policies.findById(representation.getId());
    permission.update(representation);
    assertRepresentation(representation, permission);
}
Also used : JSPoliciesResource(org.keycloak.admin.client.resource.JSPoliciesResource) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) JSPolicyResource(org.keycloak.admin.client.resource.JSPolicyResource) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 2 with JSPolicyResource

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

the class JSPolicyManagementTest method testDelete.

@Test
public void testDelete() {
    AuthorizationResource authorization = getClient().authorization();
    JSPolicyRepresentation representation = new JSPolicyRepresentation();
    representation.setName("Test Delete Policy");
    representation.setCode("$evaluation.grant()");
    JSPoliciesResource policies = authorization.policies().js();
    try (Response response = policies.create(representation)) {
        JSPolicyRepresentation created = response.readEntity(JSPolicyRepresentation.class);
        policies.findById(created.getId()).remove();
        JSPolicyResource removed = policies.findById(created.getId());
        try {
            removed.toRepresentation();
            fail("Permission not removed");
        } catch (NotFoundException ignore) {
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) JSPoliciesResource(org.keycloak.admin.client.resource.JSPoliciesResource) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) JSPolicyResource(org.keycloak.admin.client.resource.JSPolicyResource) NotFoundException(javax.ws.rs.NotFoundException) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 3 with JSPolicyResource

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

the class JSPolicyManagementTest method assertCreated.

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

Aggregations

JSPoliciesResource (org.keycloak.admin.client.resource.JSPoliciesResource)3 JSPolicyResource (org.keycloak.admin.client.resource.JSPolicyResource)3 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)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