use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class GroupPolicyManagementTest method testCreateWithoutGroupsClaim.
@Test
public void testCreateWithoutGroupsClaim() {
AuthorizationResource authorization = getClient().authorization();
GroupPolicyRepresentation representation = new GroupPolicyRepresentation();
representation.setName(KeycloakModelUtils.generateId());
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addGroupPath("/Group A/Group B/Group C", true);
representation.addGroupPath("Group F");
assertCreated(authorization, representation);
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class JSPolicyManagementTest method testUpdate.
@Test
public void testUpdate() {
AuthorizationResource authorization = getClient().authorization();
JSPolicyRepresentation representation = new JSPolicyRepresentation();
representation.setName("Update JS Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.setCode("$evaluation.grant();");
assertCreated(authorization, representation);
representation.setName("changed");
representation.setDescription("changed");
representation.setDecisionStrategy(DecisionStrategy.AFFIRMATIVE);
representation.setLogic(Logic.POSITIVE);
representation.setCode("$evaluation.deny()");
JSPoliciesResource policies = authorization.policies().js();
JSPolicyResource permission = policies.findById(representation.getId());
permission.update(representation);
assertRepresentation(representation, permission);
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class JSPolicyManagementTest method testDelete.
@Test
public void testDelete() {
AuthorizationResource authorization = getClient().authorization();
JSPolicyRepresentation representation = new JSPolicyRepresentation();
representation.setName("Test Delete Policy");
representation.setCode("$evaluation.grant()");
JSPoliciesResource policies = authorization.policies().js();
try (Response response = policies.create(representation)) {
JSPolicyRepresentation created = response.readEntity(JSPolicyRepresentation.class);
policies.findById(created.getId()).remove();
JSPolicyResource removed = policies.findById(created.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 ClientPolicyManagementTest method testDeleteClient.
@Test
public void testDeleteClient() {
AuthorizationResource authorization = getClient().authorization();
ClientPolicyRepresentation representation = new ClientPolicyRepresentation();
representation.setName("Update Test Client Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addClient("Client D");
representation.addClient("Client E");
representation.addClient("Client F");
assertCreated(authorization, representation);
ClientsResource clients = getRealm().clients();
ClientRepresentation client = clients.findByClientId("Client D").get(0);
clients.get(client.getId()).remove();
representation = authorization.policies().client().findById(representation.getId()).toRepresentation();
Assert.assertEquals(2, representation.getClients().size());
Assert.assertFalse(representation.getClients().contains(client.getId()));
client = clients.findByClientId("Client E").get(0);
clients.get(client.getId()).remove();
representation = authorization.policies().client().findById(representation.getId()).toRepresentation();
Assert.assertEquals(1, representation.getClients().size());
Assert.assertFalse(representation.getClients().contains(client.getId()));
client = clients.findByClientId("Client F").get(0);
clients.get(client.getId()).remove();
try {
authorization.policies().client().findById(representation.getId()).toRepresentation();
fail("Client policy should be removed");
} catch (NotFoundException nfe) {
// ignore
}
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class ClientPolicyManagementTest method testDelete.
@Test
public void testDelete() {
AuthorizationResource authorization = getClient().authorization();
ClientPolicyRepresentation representation = new ClientPolicyRepresentation();
representation.setName("Test Delete Permission");
representation.addClient("Client A");
ClientPoliciesResource policies = authorization.policies().client();
try (Response response = policies.create(representation)) {
ClientPolicyRepresentation created = response.readEntity(ClientPolicyRepresentation.class);
policies.findById(created.getId()).remove();
ClientPolicyResource removed = policies.findById(created.getId());
try {
removed.toRepresentation();
fail("Permission not removed");
} catch (NotFoundException ignore) {
}
}
}
Aggregations