Search in sources :

Example 66 with PolicyRepresentation

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

the class PermissionsTable 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)

Example 67 with PolicyRepresentation

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

the class KeycloakTestResource method configureHttpResponseClaimBasedPermission.

private static void configureHttpResponseClaimBasedPermission(ResourceServerRepresentation settings) {
    PolicyRepresentation policy = createJSPolicy("Http Response Claim-Based Policy", "var context = $evaluation.getContext();\n" + "var attributes = context.getAttributes();\n" + "\n" + "if (attributes.containsValue('user-name', 'alice')) {\n" + "    $evaluation.grant();\n" + "}", settings);
    createPermission(settings, createResource(settings, "Http Response Claim Protected Resource", "/api/permission/http-response-claim-protected"), policy);
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation)

Example 68 with PolicyRepresentation

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

the class KeycloakTestResource method createPermission.

private static void createPermission(ResourceServerRepresentation settings, ResourceRepresentation resource, PolicyRepresentation policy) {
    PolicyRepresentation permission = new PolicyRepresentation();
    permission.setName(resource.getName() + " Permission");
    permission.setType("resource");
    permission.setResources(new HashSet<>());
    permission.getResources().add(resource.getName());
    permission.setPolicies(new HashSet<>());
    permission.getPolicies().add(policy.getName());
    settings.getPolicies().add(permission);
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation)

Example 69 with PolicyRepresentation

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

the class KeycloakTestResource method configureBodyClaimBasedPermission.

private static void configureBodyClaimBasedPermission(ResourceServerRepresentation settings) {
    PolicyRepresentation policy = createJSPolicy("Body Claim-Based Policy", "var context = $evaluation.getContext();\n" + "print(context.getAttributes().toMap());" + "var attributes = context.getAttributes();\n" + "\n" + "if (attributes.containsValue('from-body', 'grant')) {\n" + "    $evaluation.grant();\n" + "}", settings);
    createPermission(settings, createResource(settings, "Body Claim Protected Resource", "/api/permission/body-claim"), policy);
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation)

Example 70 with PolicyRepresentation

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

the class KeycloakTestResource method configurePermissionResourcePermission.

private static void configurePermissionResourcePermission(ResourceServerRepresentation settings) {
    PolicyRepresentation policy = createJSPolicy("Confidential Policy", "var identity = $evaluation.context.identity;\n" + "\n" + "if (identity.hasRealmRole(\"confidential\")) {\n" + "$evaluation.grant();\n" + "}", settings);
    createPermission(settings, createResource(settings, "Permission Resource", "/api/permission"), policy);
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation)

Aggregations

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