Search in sources :

Example 6 with RequirePortalAuth

use of io.gravitee.rest.api.portal.rest.security.RequirePortalAuth in project gravitee-management-rest-api by gravitee-io.

the class CategoryResource method picture.

@GET
@Path("picture")
@RequirePortalAuth
public Response picture(@Context Request request, @PathParam("categoryId") String categoryId) {
    categoryService.findNotHiddenById(categoryId);
    InlinePictureEntity image = categoryService.getPicture(categoryId);
    return createPictureResponse(request, image);
}
Also used : InlinePictureEntity(io.gravitee.rest.api.model.InlinePictureEntity) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 7 with RequirePortalAuth

use of io.gravitee.rest.api.portal.rest.security.RequirePortalAuth in project gravitee-management-rest-api by gravitee-io.

the class CategoryResource method get.

@GET
@Produces(APPLICATION_JSON)
@RequirePortalAuth
public Response get(@PathParam("categoryId") String categoryId) {
    CategoryEntity category = categoryService.findNotHiddenById(categoryId);
    // FIXME: retrieve all the apis of the user can be heavy because it involves a lot of data fetching. Find a way to just retrieve only necessary data.
    Set<ApiEntity> apis = apiService.findPublishedByUser(getAuthenticatedUserOrNull());
    category.setTotalApis(categoryService.getTotalApisByCategory(apis, category));
    return Response.ok(categoryMapper.convert(category, uriInfo.getBaseUriBuilder())).build();
}
Also used : ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) CategoryEntity(io.gravitee.rest.api.model.CategoryEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 8 with RequirePortalAuth

use of io.gravitee.rest.api.portal.rest.security.RequirePortalAuth in project gravitee-management-rest-api by gravitee-io.

the class ApiInformationsResource method getApiInformations.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@RequirePortalAuth
public Response getApiInformations(@Context Request request, @PathParam("apiId") String apiId) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
    if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
        List<ApiHeaderEntity> all = apiService.getPortalHeaders(apiId);
        List<ApiInformation> information = all.stream().map(apiHeaderEntity -> {
            ApiInformation ai = new ApiInformation();
            ai.setName(apiHeaderEntity.getName());
            ai.setValue(apiHeaderEntity.getValue());
            return ai;
        }).collect(Collectors.toList());
        return Response.ok(information).build();
    }
    throw new ApiNotFoundException(apiId);
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) PathParam(javax.ws.rs.PathParam) Context(javax.ws.rs.core.Context) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Collection(java.util.Collection) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth) Collectors(java.util.stream.Collectors) ApiService(io.gravitee.rest.api.service.ApiService) Inject(javax.inject.Inject) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) ApiInformation(io.gravitee.rest.api.portal.rest.model.ApiInformation) Response(javax.ws.rs.core.Response) Request(javax.ws.rs.core.Request) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) Collections(java.util.Collections) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiHeaderEntity(io.gravitee.rest.api.model.api.header.ApiHeaderEntity) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ApiInformation(io.gravitee.rest.api.portal.rest.model.ApiInformation) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 9 with RequirePortalAuth

use of io.gravitee.rest.api.portal.rest.security.RequirePortalAuth in project gravitee-management-rest-api by gravitee-io.

the class ApiMetricsResource method getApiMetricsByApiId.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@RequirePortalAuth
public Response getApiMetricsByApiId(@Context Request request, @PathParam("apiId") String apiId) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    Collection<ApiEntity> userApis = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
    if (userApis.stream().anyMatch(a -> a.getId().equals(apiId))) {
        Number healthRatio = getHealthRatio(apiId);
        Number nbHits = getNbHits(apiId);
        Number subscribers = getApiNbSubscribers(apiId);
        ApiMetrics metrics = new ApiMetrics();
        metrics.setHealth(healthRatio);
        metrics.setHits(nbHits);
        metrics.setSubscribers(subscribers);
        return Response.ok(metrics).build();
    }
    throw new ApiNotFoundException(apiId);
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) ApiMetrics(io.gravitee.rest.api.portal.rest.model.ApiMetrics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Example 10 with RequirePortalAuth

use of io.gravitee.rest.api.portal.rest.security.RequirePortalAuth in project gravitee-management-rest-api by gravitee-io.

the class ApiPageResource method getPageByApiIdAndPageId.

@GET
@Produces(MediaType.APPLICATION_JSON)
@RequirePortalAuth
public Response getPageByApiIdAndPageId(@HeaderParam("Accept-Language") String acceptLang, @PathParam("apiId") String apiId, @PathParam("pageId") String pageId, @QueryParam("include") List<String> include) {
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    if (accessControlService.canAccessApiFromPortal(apiId)) {
        final String acceptedLocale = HttpHeadersUtil.getFirstAcceptedLocaleName(acceptLang);
        PageEntity pageEntity = pageService.findById(pageId, acceptedLocale);
        if (accessControlService.canAccessPageFromPortal(apiId, pageEntity)) {
            pageService.transformSwagger(pageEntity, apiId);
            if (!isAuthenticated() && pageEntity.getMetadata() != null) {
                pageEntity.getMetadata().clear();
            }
            Page page = pageMapper.convert(uriInfo.getBaseUriBuilder(), apiId, pageEntity);
            if (include.contains(INCLUDE_CONTENT)) {
                page.setContent(pageEntity.getContent());
            }
            page.setLinks(pageMapper.computePageLinks(PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, pageId), PortalApiLinkHelper.apiPagesURL(uriInfo.getBaseUriBuilder(), apiId, page.getParent())));
            return Response.ok(page).build();
        } else {
            throw new UnauthorizedAccessException();
        }
    }
    throw new ApiNotFoundException(apiId);
}
Also used : PageEntity(io.gravitee.rest.api.model.PageEntity) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) UnauthorizedAccessException(io.gravitee.rest.api.service.exceptions.UnauthorizedAccessException) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) Page(io.gravitee.rest.api.portal.rest.model.Page) RequirePortalAuth(io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)

Aggregations

RequirePortalAuth (io.gravitee.rest.api.portal.rest.security.RequirePortalAuth)12 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)9 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)9 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)7 MediaType (io.gravitee.common.http.MediaType)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 GET (javax.ws.rs.GET)4 Response (javax.ws.rs.core.Response)4 PageEntity (io.gravitee.rest.api.model.PageEntity)3 Page (io.gravitee.rest.api.portal.rest.model.Page)3 UnauthorizedAccessException (io.gravitee.rest.api.service.exceptions.UnauthorizedAccessException)3 Collections (java.util.Collections)3 List (java.util.List)3 Produces (javax.ws.rs.Produces)3 Context (javax.ws.rs.core.Context)3 PageQuery (io.gravitee.rest.api.model.documentation.PageQuery)2 PageMapper (io.gravitee.rest.api.portal.rest.mapper.PageMapper)2 PlanMapper (io.gravitee.rest.api.portal.rest.mapper.PlanMapper)2 PaginationParam (io.gravitee.rest.api.portal.rest.resource.param.PaginationParam)2