Search in sources :

Example 6 with AggregatePolicyRepresentation

use of org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation in project keycloak by keycloak.

the class AggregatePolicyForm method toRepresentation.

public AggregatePolicyRepresentation toRepresentation() {
    AggregatePolicyRepresentation representation = new AggregatePolicyRepresentation();
    representation.setName(UIUtils.getTextInputValue(name));
    representation.setDescription(UIUtils.getTextInputValue(description));
    representation.setLogic(Logic.valueOf(UIUtils.getTextFromElement(logic.getFirstSelectedOption()).toUpperCase()));
    representation.setPolicies(policySelect.getSelected());
    return representation;
}
Also used : AggregatePolicyRepresentation(org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation)

Example 7 with AggregatePolicyRepresentation

use of org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation 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 8 with AggregatePolicyRepresentation

use of org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation 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 9 with AggregatePolicyRepresentation

use of org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation 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)

Example 10 with AggregatePolicyRepresentation

use of org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation in project keycloak by keycloak.

the class Policies method update.

public void update(String name, AbstractPolicyRepresentation representation) {
    for (WebElement row : policies().rows()) {
        PolicyRepresentation actual = policies().toRepresentation(row);
        if (actual.getName().equalsIgnoreCase(name)) {
            clickLink(row.findElements(tagName("a")).get(0));
            String type = representation.getType();
            if ("role".equals(type)) {
                rolePolicy.form().populate((RolePolicyRepresentation) representation, true);
            } else if ("user".equals(type)) {
                userPolicy.form().populate((UserPolicyRepresentation) representation, true);
            } else if ("aggregate".equals(type)) {
                aggregatePolicy.form().populate((AggregatePolicyRepresentation) representation, true);
            } else if ("js".equals(type)) {
                jsPolicy.form().populate((JSPolicyRepresentation) representation, true);
            } else if ("time".equals(type)) {
                timePolicy.form().populate((TimePolicyRepresentation) representation, true);
            } else if ("client".equals(type)) {
                clientPolicy.form().populate((ClientPolicyRepresentation) representation, true);
            } else if ("group".equals(type)) {
                groupPolicy.form().populate((GroupPolicyRepresentation) representation, true);
            }
            return;
        }
    }
}
Also used : RolePolicyRepresentation(org.keycloak.representations.idm.authorization.RolePolicyRepresentation) AbstractPolicyRepresentation(org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation) GroupPolicyRepresentation(org.keycloak.representations.idm.authorization.GroupPolicyRepresentation) TimePolicyRepresentation(org.keycloak.representations.idm.authorization.TimePolicyRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) AggregatePolicyRepresentation(org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) ClientPolicyRepresentation(org.keycloak.representations.idm.authorization.ClientPolicyRepresentation) UserPolicyRepresentation(org.keycloak.representations.idm.authorization.UserPolicyRepresentation) JSPolicyRepresentation(org.keycloak.representations.idm.authorization.JSPolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Aggregations

AggregatePolicyRepresentation (org.keycloak.representations.idm.authorization.AggregatePolicyRepresentation)14 Test (org.junit.Test)9 RolePolicyRepresentation (org.keycloak.representations.idm.authorization.RolePolicyRepresentation)4 AggregatePolicy (org.keycloak.testsuite.console.page.clients.authorization.policy.AggregatePolicy)4 AggregatePoliciesResource (org.keycloak.admin.client.resource.AggregatePoliciesResource)3 AggregatePolicyResource (org.keycloak.admin.client.resource.AggregatePolicyResource)3 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)3 Response (javax.ws.rs.core.Response)2 ClientPolicyRepresentation (org.keycloak.representations.idm.authorization.ClientPolicyRepresentation)2 GroupPolicyRepresentation (org.keycloak.representations.idm.authorization.GroupPolicyRepresentation)2 JSPolicyRepresentation (org.keycloak.representations.idm.authorization.JSPolicyRepresentation)2 TimePolicyRepresentation (org.keycloak.representations.idm.authorization.TimePolicyRepresentation)2 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)2 NotFoundException (javax.ws.rs.NotFoundException)1 AbstractPolicyRepresentation (org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation)1 PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)1 WebElement (org.openqa.selenium.WebElement)1