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();
});
}
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()));
}
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;
}
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());
}
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());
}
Aggregations