use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class UserPolicyManagementTest method testCreate.
@Test
public void testCreate() {
AuthorizationResource authorization = getClient().authorization();
UserPolicyRepresentation representation = new UserPolicyRepresentation();
representation.setName("Realm User Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.addUser("User A");
representation.addUser("User B");
assertCreated(authorization, representation);
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class AbstractResourceServerTest method addResource.
protected ResourceRepresentation addResource(String resourceName, String owner, boolean ownerManagedAccess, String... scopeNames) throws Exception {
ClientResource client = getClient(getRealm());
AuthorizationResource authorization = client.authorization();
ResourceRepresentation resource = new ResourceRepresentation(resourceName);
if (owner != null) {
resource.setOwner(new ResourceOwnerRepresentation(owner));
}
resource.setOwnerManagedAccess(ownerManagedAccess);
resource.addScope(scopeNames);
Response response = authorization.resources().create(resource);
ResourceRepresentation temp = response.readEntity(ResourceRepresentation.class);
resource.setId(temp.getId());
response.close();
return resource;
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class ResourceServerManagementTest method testCreateAndDeleteResourceServer.
@Test
public void testCreateAndDeleteResourceServer() throws Exception {
ClientsResource clientsResource = testRealmResource().clients();
clientsResource.create(JsonSerialization.readValue(getClass().getResourceAsStream("/authorization-test/client-with-authz-settings.json"), ClientRepresentation.class)).close();
List<ClientRepresentation> clients = clientsResource.findByClientId("authz-client");
assertFalse(clients.isEmpty());
String clientId = clients.get(0).getId();
AuthorizationResource settings = clientsResource.get(clientId).authorization();
assertEquals(PolicyEnforcementMode.PERMISSIVE, settings.exportSettings().getPolicyEnforcementMode());
assertEquals(DecisionStrategy.UNANIMOUS, settings.exportSettings().getDecisionStrategy());
assertFalse(settings.resources().findByName("Resource 1").isEmpty());
assertFalse(settings.resources().findByName("Resource 15").isEmpty());
assertFalse(settings.resources().findByName("Resource 20").isEmpty());
assertNotNull(settings.permissions().resource().findByName("Resource 15 Permission"));
assertNotNull(settings.policies().role().findByName("Resource 1 Policy"));
clientsResource.get(clientId).remove();
clients = clientsResource.findByClientId("authz-client");
assertTrue(clients.isEmpty());
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class TimePolicyManagementTest method testCreate.
@Test
public void testCreate() {
AuthorizationResource authorization = getClient().authorization();
assertCreated(authorization, createRepresentation("Time Policy"));
}
use of org.keycloak.admin.client.resource.AuthorizationResource in project keycloak by keycloak.
the class JSPolicyManagementTest method testCreate.
@Test
public void testCreate() {
AuthorizationResource authorization = getClient().authorization();
JSPolicyRepresentation representation = new JSPolicyRepresentation();
representation.setName("JS Policy");
representation.setDescription("description");
representation.setDecisionStrategy(DecisionStrategy.CONSENSUS);
representation.setLogic(Logic.NEGATIVE);
representation.setCode("$evaluation.grant();");
assertCreated(authorization, representation);
}
Aggregations