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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations