use of io.gravitee.am.model.uma.Resource in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpointTest method get_withResource.
@Test
public void get_withResource() {
when(service.findByDomainAndClientAndUserAndResource(DOMAIN_ID, CLIENT_ID, USER_ID, RESOURCE_ID)).thenReturn(Maybe.just(new Resource().setId(RESOURCE_ID)));
endpoint.get(context);
verify(response, times(1)).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
verify(response, times(1)).setStatusCode(intCaptor.capture());
Assert.assertEquals("Should be ok", 200, intCaptor.getValue().intValue());
}
use of io.gravitee.am.model.uma.Resource in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpointTest method update_withResource.
@Test
public void update_withResource() {
when(context.getBodyAsJson()).thenReturn(new JsonObject("{\"id\":\"rs_id\",\"resource_scopes\":[\"scope\"]}"));
when(service.update(any(), eq(DOMAIN_ID), eq(CLIENT_ID), eq(USER_ID), eq(RESOURCE_ID))).thenReturn(Single.just(new Resource()));
endpoint.update(context);
verify(response, times(1)).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
verify(response, times(1)).setStatusCode(intCaptor.capture());
Assert.assertEquals("Should be ok", 200, intCaptor.getValue().intValue());
}
use of io.gravitee.am.model.uma.Resource in project gravitee-access-management by gravitee-io.
the class JdbcResourceRepository method update.
@Override
public Single<Resource> update(Resource item) {
LOGGER.debug("update Resource with id {}", item.getId());
TransactionalOperator trx = TransactionalOperator.create(tm);
Mono<Integer> deleteScopes = template.delete(JdbcResource.Scope.class).matching(Query.query(where("resource_id").is(item.getId()))).all();
Mono<Integer> updateResource = template.update(toJdbcEntity(item)).map(__ -> 1);
final List<String> resourceScopes = item.getResourceScopes();
if (resourceScopes != null && !resourceScopes.isEmpty()) {
updateResource = updateResource.then(Flux.fromIterable(resourceScopes).concatMap(scope -> insertScope(item, scope)).reduce(Integer::sum));
}
return monoToSingle(deleteScopes.then(updateResource).as(trx::transactional)).flatMap((i) -> this.findById(item.getId()).toSingle());
}
use of io.gravitee.am.model.uma.Resource in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpoint method handle.
@Override
public void handle(RoutingContext context) {
JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
this.resourceService.listByDomainAndClientAndUser(domain.getId(), client.getId(), accessToken.getSub()).map(Resource::getId).collect(JsonArray::new, JsonArray::add).subscribe(buffer -> context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).setStatusCode(buffer.isEmpty() ? HttpStatusCode.NO_CONTENT_204 : HttpStatusCode.OK_200).end(Json.encodePrettily(buffer)), error -> context.fail(error));
}
use of io.gravitee.am.model.uma.Resource in project gravitee-access-management by gravitee-io.
the class ResourceRegistrationEndpoint method create.
public void create(RoutingContext context) {
JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
String basePath = UriBuilderRequest.resolveProxyRequest(context);
this.extractRequest(context).flatMap(request -> this.resourceService.create(request, domain.getId(), client.getId(), accessToken.getSub())).subscribe(resource -> {
final String resourceLocation = resourceLocation(basePath, resource);
context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).putHeader(HttpHeaders.LOCATION, resourceLocation).setStatusCode(HttpStatusCode.CREATED_201).end(Json.encodePrettily(ResourceResponse.from(resource, resourceLocation)));
}, error -> context.fail(error));
}
Aggregations