Search in sources :

Example 21 with PolicyRepresentation

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

the class DefaultAuthorizationSettingsTest method assertDefaultSettings.

private void assertDefaultSettings() {
    AuthorizationSettingsForm settings = authorizationPage.settings();
    assertEquals(PolicyEnforcerConfig.EnforcementMode.ENFORCING, settings.getEnforcementMode());
    assertEquals(true, settings.isAllowRemoteResourceManagement());
    assertEquals(DecisionStrategy.UNANIMOUS, settings.getDecisionStrategy());
    assertEquals(true, settings.isAllowRemoteResourceManagement());
    Resources resources = authorizationPage.authorizationTabs().resources();
    ResourceRepresentation resource = resources.resources().findByName("Default Resource");
    assertNotNull(resource);
    assertEquals("urn:oidc-confidetial:resources:default", resource.getType());
    assertEquals("/*", resource.getUri());
    assertEquals(newClient.getClientId(), resource.getOwner().getName());
    Scopes scopes = authorizationPage.authorizationTabs().scopes();
    assertTrue(scopes.scopes().getTableRows().isEmpty());
    Permissions permissions = authorizationPage.authorizationTabs().permissions();
    PolicyRepresentation permission = permissions.permissions().findByName("Default Permission");
    assertNotNull(permission);
    assertEquals("resource", permission.getType());
    Policies policies = authorizationPage.authorizationTabs().policies();
    PolicyRepresentation policy = policies.policies().findByName("Default Policy");
    assertNotNull(policy);
    assertEquals("js", policy.getType());
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) Policies(org.keycloak.testsuite.console.page.clients.authorization.policy.Policies) Scopes(org.keycloak.testsuite.console.page.clients.authorization.scope.Scopes) Permissions(org.keycloak.testsuite.console.page.clients.authorization.permission.Permissions) Resources(org.keycloak.testsuite.console.page.clients.authorization.resource.Resources) AuthorizationSettingsForm(org.keycloak.testsuite.console.page.clients.authorization.AuthorizationSettingsForm) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation)

Example 22 with PolicyRepresentation

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

the class Policies method deleteFromList.

public void deleteFromList(String name) {
    for (WebElement row : policies().rows()) {
        PolicyRepresentation actual = policies().toRepresentation(row);
        if (actual.getName().equalsIgnoreCase(name)) {
            row.findElements(tagName("td")).get(4).click();
            modalDialog.confirmDeletion();
            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) WebElement(org.openqa.selenium.WebElement)

Example 23 with PolicyRepresentation

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

the class Policies method name.

public <P extends PolicyTypeUI> P name(String name) {
    for (WebElement row : policies().rows()) {
        PolicyRepresentation actual = policies().toRepresentation(row);
        if (actual.getName().equalsIgnoreCase(name)) {
            clickLink(row.findElements(tagName("a")).get(0));
            String type = actual.getType();
            if ("role".equals(type)) {
                return (P) rolePolicy;
            } else if ("user".equals(type)) {
                return (P) userPolicy;
            } else if ("aggregate".equals(type)) {
                return (P) aggregatePolicy;
            } else if ("js".equals(type)) {
                return (P) jsPolicy;
            } else if ("time".equals(type)) {
                return (P) timePolicy;
            } else if ("client".equals(type)) {
                return (P) clientPolicy;
            } else if ("group".equals(type)) {
                return (P) groupPolicy;
            }
        }
    }
    return null;
}
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) WebElement(org.openqa.selenium.WebElement)

Example 24 with PolicyRepresentation

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

the class Permissions method delete.

public void delete(String name) {
    for (WebElement row : permissions().rows()) {
        PolicyRepresentation actual = permissions().toRepresentation(row);
        if (actual.getName().equalsIgnoreCase(name)) {
            clickLink(row.findElements(tagName("a")).get(0));
            WaitUtils.waitForPageToLoad();
            String type = actual.getType();
            if ("resource".equals(type)) {
                resourcePermission.form().delete();
            } else if ("scope".equals(type)) {
                scopePermission.form().delete();
            }
            return;
        }
    }
}
Also used : AbstractPolicyRepresentation(org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Example 25 with PolicyRepresentation

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

the class PoliciesTable method toRepresentation.

public PolicyRepresentation toRepresentation(WebElement row) {
    PolicyRepresentation representation = null;
    List<WebElement> tds = row.findElements(tagName("td"));
    if (!(tds.isEmpty() || getTextFromElement(tds.get(1)).isEmpty())) {
        representation = new PolicyRepresentation();
        representation.setName(getTextFromElement(tds.get(1)));
        representation.setDescription(getTextFromElement(tds.get(2)));
        representation.setType(getTextFromElement(tds.get(3)));
    }
    return representation;
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) WebElement(org.openqa.selenium.WebElement)

Aggregations

PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)58 Test (org.junit.Test)26 HashMap (java.util.HashMap)20 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)19 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)18 Response (javax.ws.rs.core.Response)15 List (java.util.List)12 Map (java.util.Map)12 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Collectors (java.util.stream.Collectors)10 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)10 AbstractPolicyRepresentation (org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation)10 ScopeRepresentation (org.keycloak.representations.idm.authorization.ScopeRepresentation)10 UserPolicyRepresentation (org.keycloak.representations.idm.authorization.UserPolicyRepresentation)10 WebElement (org.openqa.selenium.WebElement)10 Set (java.util.Set)9 Policy (org.keycloak.authorization.model.Policy)9 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)9 UserRepresentation (org.keycloak.representations.idm.UserRepresentation)8