Search in sources :

Example 1 with AggregatePoliciesResource

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

the class AggregatePolicyManagementTest method testUpdate.

@Test
public void testUpdate() {
    AuthorizationResource authorization = getClient().authorization();
    AggregatePolicyRepresentation representation = new AggregatePolicyRepresentation();
    representation.setName("Update Aggregate Policy");
    representation.setDescription("description");
    representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
    representation.setLogic(Logic.NEGATIVE);
    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.getPolicies().clear();
    representation.addPolicy("Only Kolo Policy");
    AggregatePoliciesResource policies = authorization.policies().aggregate();
    AggregatePolicyResource policy = policies.findById(representation.getId());
    policy.update(representation);
    assertRepresentation(representation, policy);
}
Also used : AggregatePoliciesResource(org.keycloak.admin.client.resource.AggregatePoliciesResource) AggregatePolicyResource(org.keycloak.admin.client.resource.AggregatePolicyResource) AggregatePolicyRepresentation(org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation) AuthorizationResource(org.keycloak.admin.client.resource.AuthorizationResource) Test(org.junit.Test)

Example 2 with AggregatePoliciesResource

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

the class AggregatePolicyManagementTest method assertCreated.

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

Example 3 with AggregatePoliciesResource

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

the class AggregatePolicyManagementTest method testDelete.

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

Aggregations

AggregatePoliciesResource (org.keycloak.admin.client.resource.AggregatePoliciesResource)3 AggregatePolicyResource (org.keycloak.admin.client.resource.AggregatePolicyResource)3 AggregatePolicyRepresentation (org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation)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