Search in sources :

Example 1 with Resource

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());
}
Also used : Resource(io.gravitee.am.model.uma.Resource) Test(org.junit.Test)

Example 2 with Resource

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());
}
Also used : Resource(io.gravitee.am.model.uma.Resource) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 3 with Resource

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());
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) CriteriaDefinition(org.springframework.data.relational.core.query.CriteriaDefinition) Completable(io.reactivex.Completable) Maybe(io.reactivex.Maybe) Query(org.springframework.data.relational.core.query.Query) Autowired(org.springframework.beans.factory.annotation.Autowired) Criteria.where(org.springframework.data.relational.core.query.Criteria.where) Single(io.reactivex.Single) AbstractJdbcRepository(io.gravitee.am.repository.jdbc.management.AbstractJdbcRepository) Flowable(io.reactivex.Flowable) Sort(org.springframework.data.domain.Sort) Repository(org.springframework.stereotype.Repository) SpringResourceScopeRepository(io.gravitee.am.repository.jdbc.management.api.spring.resources.SpringResourceScopeRepository) Page(io.gravitee.am.model.common.Page) CriteriaDefinition.from(org.springframework.data.relational.core.query.CriteriaDefinition.from) JdbcResource(io.gravitee.am.repository.jdbc.management.api.model.JdbcResource) TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) PageRequest(org.springframework.data.domain.PageRequest) Mono(reactor.core.publisher.Mono) Resource(io.gravitee.am.model.uma.Resource) RandomString(io.gravitee.am.common.utils.RandomString) ResourceRepository(io.gravitee.am.repository.management.api.ResourceRepository) Flux(reactor.core.publisher.Flux) List(java.util.List) RxJava2Adapter(reactor.adapter.rxjava.RxJava2Adapter) SpringResourceRepository(io.gravitee.am.repository.jdbc.management.api.spring.resources.SpringResourceRepository) JdbcResource(io.gravitee.am.repository.jdbc.management.api.model.JdbcResource) RandomString(io.gravitee.am.common.utils.RandomString)

Example 4 with Resource

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));
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Resource(io.gravitee.am.model.uma.Resource) NewResource(io.gravitee.am.service.model.NewResource) Client(io.gravitee.am.model.oidc.Client)

Example 5 with Resource

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));
}
Also used : ResourceService(io.gravitee.am.service.ResourceService) ResourceNotFoundException(io.gravitee.am.service.exception.ResourceNotFoundException) Json(io.vertx.core.json.Json) HttpHeaders(io.gravitee.common.http.HttpHeaders) JWT(io.gravitee.am.common.jwt.JWT) ResourceResponse(io.gravitee.am.gateway.handler.uma.resources.response.ResourceResponse) Client(io.gravitee.am.model.oidc.Client) ConstantKeys(io.gravitee.am.common.utils.ConstantKeys) Domain(io.gravitee.am.model.Domain) Resource(io.gravitee.am.model.uma.Resource) Single(io.reactivex.Single) RoutingContext(io.vertx.reactivex.ext.web.RoutingContext) HttpStatusCode(io.gravitee.common.http.HttpStatusCode) UriBuilderRequest(io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest) JsonArray(io.vertx.core.json.JsonArray) InvalidRequestException(io.gravitee.am.common.exception.oauth2.InvalidRequestException) MediaType(io.gravitee.common.http.MediaType) UMAConstants(io.gravitee.am.gateway.handler.uma.constants.UMAConstants) JsonObject(io.vertx.core.json.JsonObject) NewResource(io.gravitee.am.service.model.NewResource) Handler(io.vertx.core.Handler) JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client)

Aggregations

Resource (io.gravitee.am.model.uma.Resource)42 Test (org.junit.Test)30 NewResource (io.gravitee.am.service.model.NewResource)14 JsonObject (io.vertx.core.json.JsonObject)12 PermissionRequest (io.gravitee.am.model.uma.PermissionRequest)10 PermissionTicket (io.gravitee.am.model.uma.PermissionTicket)10 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)9 Single (io.reactivex.Single)6 Page (io.gravitee.am.model.common.Page)5 ResourceService (io.gravitee.am.service.ResourceService)5 InvalidPermissionRequestException (io.gravitee.am.service.exception.InvalidPermissionRequestException)5 JWT (io.gravitee.am.common.jwt.JWT)4 Maybe (io.reactivex.Maybe)4 InvalidRequestException (io.gravitee.am.common.exception.oauth2.InvalidRequestException)3 Client (io.gravitee.am.model.oidc.Client)3 List (java.util.List)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 ConstantKeys (io.gravitee.am.common.utils.ConstantKeys)2 RandomString (io.gravitee.am.common.utils.RandomString)2 UriBuilderRequest (io.gravitee.am.gateway.handler.common.vertx.utils.UriBuilderRequest)2