use of org.keycloak.representations.idm.authorization.ResourceRepresentation 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.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class ResourceManagementWithAuthzClientTest method testUpdateUri.
@Test
public void testUpdateUri() {
doCreateResource(new ResourceRepresentation("/api/v1/*", Collections.emptySet(), "/api/v1/*", null));
AuthzClient authzClient = getAuthzClient();
List<ResourceRepresentation> resources = authzClient.protection().resource().findByMatchingUri("/api/v1/servers");
assertNotNull(resources);
assertEquals(1, resources.size());
assertEquals("/api/v1/*", resources.get(0).getUri());
resources.get(0).getUris().clear();
resources.get(0).getUris().add("/api/v2/*");
authzClient.protection().resource().update(resources.get(0));
resources = authzClient.protection().resource().findByMatchingUri("/api/v1/servers");
assertNotNull(resources);
assertEquals(0, resources.size());
resources = authzClient.protection().resource().findByMatchingUri("/api/v2");
assertNotNull(resources);
assertEquals(1, resources.size());
assertEquals("/api/v2/*", resources.get(0).getUri());
}
use of org.keycloak.representations.idm.authorization.ResourceRepresentation 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.ResourceRepresentation in project keycloak by keycloak.
the class ResourceManagementWithAuthzClientTest method testFindDeep.
@Test
public void testFindDeep() {
ResourceRepresentation resource1 = new ResourceRepresentation("/*", new HashSet<>());
resource1.addScope("a", "b", "c");
resource1.setType("type");
Map<String, List<String>> attributes = new HashMap<>();
attributes.put("a", Arrays.asList("a"));
attributes.put("b", Arrays.asList("b"));
attributes.put("c", Arrays.asList("c"));
resource1.setAttributes(attributes);
resource1.setIconUri("icon");
resource1.setUris(new HashSet<>(Arrays.asList("/a", "/b", "/c")));
ResourceRepresentation resource = doCreateResource(resource1);
AuthzClient authzClient = getAuthzClient();
List<ResourceRepresentation> representations = authzClient.protection().resource().find(resource.getId(), null, null, null, null, null, false, true, null, null);
assertEquals(1, representations.size());
assertEquals(resource.getId(), representations.get(0).getId());
assertEquals(resource.getName(), representations.get(0).getName());
assertEquals(resource.getIconUri(), representations.get(0).getIconUri());
assertThat(resource.getUris(), Matchers.containsInAnyOrder(representations.get(0).getUris().toArray()));
assertThat(resource.getAttributes().entrySet(), Matchers.containsInAnyOrder(representations.get(0).getAttributes().entrySet().toArray()));
}
use of org.keycloak.representations.idm.authorization.ResourceRepresentation in project keycloak by keycloak.
the class PolicyEnforcerTest method createResource.
private ResourceRepresentation createResource(ClientResource clientResource, String name, String uri, String... scopes) {
ResourceRepresentation representation = new ResourceRepresentation();
representation.setName(name);
representation.setUri(uri);
representation.setScopes(Arrays.asList(scopes).stream().map(ScopeRepresentation::new).collect(Collectors.toSet()));
javax.ws.rs.core.Response response = clientResource.authorization().resources().create(representation);
representation.setId(response.readEntity(ResourceRepresentation.class).getId());
response.close();
return representation;
}
Aggregations