use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class ResourcePermissionManagementTest method testUpdate.
@Test
public void testUpdate() {
AuthorizationResource authorization = getClient().authorization();
ResourcePermissionRepresentation representation = new ResourcePermissionRepresentation();
representation.setName("Update Test Resource Permission");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addResource("Resource A");
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.getPolicies().remove("Only Marta Policy");
ResourcePermissionsResource permissions = authorization.permissions().resource();
ResourcePermissionResource permission = permissions.findById(representation.getId());
permission.update(representation);
assertRepresentation(representation, permission);
representation.getResources().clear();
representation.setResourceType("changed");
permission.update(representation);
assertRepresentation(representation, permission);
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class RolePolicyManagementTest method testCreateRealmRolePolicy.
@Test
public void testCreateRealmRolePolicy() {
AuthorizationResource authorization = getClient().authorization();
RolePolicyRepresentation representation = new RolePolicyRepresentation();
representation.setName("Realm Role Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addRole("Role A", false);
representation.addRole("Role B", true);
assertCreated(authorization, representation);
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class ScopePermissionManagementTest method testDelete.
@Test
public void testDelete() {
AuthorizationResource authorization = getClient().authorization();
ScopePermissionRepresentation representation = new ScopePermissionRepresentation();
representation.setName("Test Delete Permission");
representation.addScope("execute");
representation.addPolicy("Only Marta Policy");
assertCreated(authorization, representation);
ScopePermissionsResource permissions = authorization.permissions().scope();
permissions.findById(representation.getId()).remove();
ScopePermissionResource removed = permissions.findById(representation.getId());
try {
removed.toRepresentation();
fail("Permission not removed");
} catch (NotFoundException ignore) {
}
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class ScopePermissionManagementTest method failCreateWithSameName.
@Test
public void failCreateWithSameName() {
AuthorizationResource authorization = getClient().authorization();
ScopePermissionRepresentation permission1 = new ScopePermissionRepresentation();
permission1.setName("Conflicting Name Permission");
permission1.addScope("read");
permission1.addPolicy("Only Marta Policy");
ScopePermissionsResource permissions = authorization.permissions().scope();
permissions.create(permission1).close();
ScopePermissionRepresentation permission2 = new ScopePermissionRepresentation();
permission2.setName(permission1.getName());
try (Response response = permissions.create(permission2)) {
assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatus());
}
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class AggregatePolicyManagementTest method testCreate.
@Test
public void testCreate() {
AuthorizationResource authorization = getClient().authorization();
AggregatePolicyRepresentation representation = new AggregatePolicyRepresentation();
representation.setName("Aggregate Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addPolicy("Only Marta Policy", "Only Kolo Policy");
assertCreated(authorization, representation);
}
Aggregations