use of org.keycloak.representations.idm.authorization.ScopePermissionRepresentation in project keycloak by keycloak.
the class PolicyEnforcerClaimsTest method initAuthorizationSettings.
private void initAuthorizationSettings(ClientResource clientResource) {
if (clientResource.authorization().resources().findByName("Bank Account").isEmpty()) {
JSPolicyRepresentation policy = new JSPolicyRepresentation();
policy.setName("Withdrawal Limit Policy");
StringBuilder code = new StringBuilder();
code.append("var context = $evaluation.getContext();");
code.append("var attributes = context.getAttributes();");
code.append("var withdrawalAmount = attributes.getValue('withdrawal.amount');");
code.append("if (withdrawalAmount && withdrawalAmount.asDouble(0) <= 100) {");
code.append(" $evaluation.grant();");
code.append("}");
policy.setCode(code.toString());
clientResource.authorization().policies().js().create(policy).close();
createResource(clientResource, "Bank Account", "/api/bank/account/{id}/withdrawal", "withdrawal");
ScopePermissionRepresentation permission = new ScopePermissionRepresentation();
permission.setName("Withdrawal Permission");
permission.addScope("withdrawal");
permission.addPolicy(policy.getName());
clientResource.authorization().permissions().scope().create(permission).close();
}
}
use of org.keycloak.representations.idm.authorization.ScopePermissionRepresentation in project keycloak by keycloak.
the class ScopePermissionManagementTest method testCreateResourceScopePermission.
@Test
public void testCreateResourceScopePermission() {
AuthorizationResource authorization = getClient().authorization();
ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
representation.setName("Resource A Scope Permission");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addResource("Resource A");
representation.addScope("read", "execute");
representation.addPolicy("Only Marta Policy", "Only Kolo Policy");
assertCreated(authorization, representation);
}
use of org.keycloak.representations.idm.authorization.ScopePermissionRepresentation in project keycloak by keycloak.
the class ScopePermissionManagementTest method testCreateScopePermission.
@Test
public void testCreateScopePermission() {
AuthorizationResource authorization = getClient().authorization();
ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
representation.setName("Read Permission");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addScope("read", "write");
representation.addPolicy("Only Marta Policy");
assertCreated(authorization, representation);
}
use of org.keycloak.representations.idm.authorization.ScopePermissionRepresentation in project keycloak by keycloak.
the class ScopePermissionManagementTest method testUpdate.
@Test
public void testUpdate() {
AuthorizationResource authorization = getClient().authorization();
ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
representation.setName("Update Test Scope Permission");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addResource("Resource A");
representation.addScope("read", "execute");
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.getResources().remove("Resource A");
representation.addResource("Resource B");
representation.getScopes().remove("execute");
representation.getPolicies().remove("Only Marta Policy");
ScopePermissionsResource permissions = authorization.permissions().scope();
ScopePermissionResource permission = permissions.findById(representation.getId());
permission.update(representation);
assertRepresentation(representation, permission);
}
use of org.keycloak.representations.idm.authorization.ScopePermissionRepresentation in project keycloak by keycloak.
the class Permissions method update.
public void update(String name, AbstractPolicyRepresentation representation, boolean save) {
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 = representation.getType();
if ("resource".equals(type)) {
resourcePermission.form().populate((ResourcePermissionRepresentation) representation, save);
} else if ("scope".equals(type)) {
scopePermission.form().populate((ScopePermissionRepresentation) representation, save);
}
return;
}
}
}
Aggregations