Search in sources :

Example 1 with ScopeRepresentation

use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.

the class AbstractPolicyManagementTest method createResourcesAndScopes.

private void createResourcesAndScopes() throws IOException {
    Set<ScopeRepresentation> scopes = new HashSet<>();
    scopes.add(new ScopeRepresentation("read"));
    scopes.add(new ScopeRepresentation("write"));
    scopes.add(new ScopeRepresentation("execute"));
    List<ResourceRepresentation> resources = new ArrayList<>();
    resources.add(new ResourceRepresentation("Resource A", scopes));
    resources.add(new ResourceRepresentation("Resource B", scopes));
    resources.add(new ResourceRepresentation("Resource C", scopes));
    resources.forEach(resource -> {
        Response response = getClient().authorization().resources().create(resource);
        response.close();
    });
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) HashSet(java.util.HashSet) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation)

Example 2 with ScopeRepresentation

use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.

the class GenericPolicyManagementTest method assertAssociatedScope.

private void assertAssociatedScope(String scopeName, PolicyRepresentation policy) {
    ScopeRepresentation scope = findScopeByName(scopeName);
    scope = getClientResource().authorization().scopes().scope(scope.getId()).toRepresentation();
    assertNotNull(scope);
    List<ScopeRepresentation> scopes = getClientResource().authorization().policies().policy(policy.getId()).scopes();
    assertTrue(scopes.stream().map((Function<ScopeRepresentation, String>) rep -> rep.getId()).collect(Collectors.toList()).contains(scope.getId()));
    List<PolicyRepresentation> permissions = getClientResource().authorization().scopes().scope(scope.getId()).permissions();
    assertEquals(1, permissions.size());
    assertTrue(permissions.stream().map(PolicyRepresentation::getId).collect(Collectors.toList()).contains(policy.getId()));
}
Also used : PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) Function(java.util.function.Function) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation)

Example 3 with ScopeRepresentation

use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.

the class ResourceManagementWithAuthzClientTest method toResourceRepresentation.

private ResourceRepresentation toResourceRepresentation(ResourceRepresentation newResource) {
    ResourceRepresentation resource = new ResourceRepresentation();
    resource.setId(newResource.getId());
    resource.setName(newResource.getName());
    resource.setIconUri(newResource.getIconUri());
    if (newResource.getUris() != null && !newResource.getUris().isEmpty()) {
        resource.setUris(newResource.getUris());
    } else {
        resource.setUri(newResource.getUri());
    }
    resource.setType(newResource.getType());
    if (newResource.getOwner() != null) {
        resource.setOwner(newResource.getOwner().getId());
    }
    resource.setScopes(newResource.getScopes().stream().map(scopeRepresentation -> {
        ScopeRepresentation scope = new ScopeRepresentation();
        scope.setName(scopeRepresentation.getName());
        scope.setIconUri(scopeRepresentation.getIconUri());
        return scope;
    }).collect(Collectors.toSet()));
    resource.setAttributes(newResource.getAttributes());
    return resource;
}
Also used : ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation)

Example 4 with ScopeRepresentation

use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.

the class ScopeManagementTest method testCreate.

@Test
public void testCreate() {
    ScopeRepresentation newScope = createDefaultScope().toRepresentation();
    assertEquals("Test Scope", newScope.getName());
    assertEquals("Scope Icon", newScope.getIconUri());
}
Also used : ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) Test(org.junit.Test)

Example 5 with ScopeRepresentation

use of org.keycloak.representations.idm.authorization.ScopeRepresentation in project keycloak by keycloak.

the class ScopeManagementTest method testUpdate.

@Test
public void testUpdate() {
    ResourceScopeResource scopeResource = createDefaultScope();
    ScopeRepresentation scope = scopeResource.toRepresentation();
    scope.setName("changed");
    scope.setIconUri("changed");
    scopeResource.update(scope);
    scope = scopeResource.toRepresentation();
    assertEquals("changed", scope.getName());
    assertEquals("changed", scope.getIconUri());
}
Also used : ResourceScopeResource(org.keycloak.admin.client.resource.ResourceScopeResource) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) Test(org.junit.Test)

Aggregations

ScopeRepresentation (org.keycloak.representations.idm.authorization.ScopeRepresentation)48 ResourceRepresentation (org.keycloak.representations.idm.authorization.ResourceRepresentation)27 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)14 List (java.util.List)12 Response (javax.ws.rs.core.Response)11 HashSet (java.util.HashSet)10 AuthorizationResource (org.keycloak.admin.client.resource.AuthorizationResource)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Set (java.util.Set)8 AuthzClient (org.keycloak.authorization.client.AuthzClient)8 Arrays (java.util.Arrays)7 AuthorizationRequest (org.keycloak.representations.idm.authorization.AuthorizationRequest)7 PolicyRepresentation (org.keycloak.representations.idm.authorization.PolicyRepresentation)7 Collection (java.util.Collection)6 Collectors (java.util.stream.Collectors)6 ResourceScopesResource (org.keycloak.admin.client.resource.ResourceScopesResource)5 HttpResponseException (org.keycloak.authorization.client.util.HttpResponseException)5 WebElement (org.openqa.selenium.WebElement)5