Search in sources :

Example 6 with Permission

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

the class PlatformAnalyticsResource method platformAnalytics.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = MANAGEMENT_PLATFORM, acls = READ) })
public Response platformAnalytics(@BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    // add filter by Apis or Applications
    String extraFilter = null;
    if (!isAdmin()) {
        if ("api".equals(analyticsParam.getField())) {
            extraFilter = getExtraFilter(analyticsParam.getField(), apiService.findByUser(getAuthenticatedUser()).stream().filter(api -> permissionService.hasPermission(API_ANALYTICS, api.getId(), READ)).map(ApiEntity::getId).collect(Collectors.toList()));
        } else if ("application".equals(analyticsParam.getField())) {
            extraFilter = getExtraFilter(analyticsParam.getField(), applicationService.findByUser(getAuthenticatedUser()).stream().filter(app -> permissionService.hasPermission(APPLICATION_ANALYTICS, app.getId(), READ)).map(ApplicationEntity::getId).collect(Collectors.toList()));
        }
    }
    switch(analyticsParam.getTypeParam().getValue()) {
        case DATE_HISTO:
            analytics = executeDateHisto(analyticsParam, extraFilter);
            break;
        case GROUP_BY:
            analytics = executeGroupBy(analyticsParam, extraFilter);
            break;
        case COUNT:
            analytics = executeCount(analyticsParam, extraFilter);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.management.model.analytics.Analytics) io.gravitee.management.model.analytics.query(io.gravitee.management.model.analytics.query) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiEntity(io.gravitee.management.model.ApiEntity) ApiService(io.gravitee.management.service.ApiService) RolePermission(io.gravitee.management.model.permissions.RolePermission) Aggregation(io.gravitee.management.rest.resource.param.Aggregation) AnalyticsService(io.gravitee.management.service.AnalyticsService) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Function(java.util.function.Function) Inject(javax.inject.Inject) Map(java.util.Map) Api(io.swagger.annotations.Api) Permission(io.gravitee.management.rest.security.Permission) AnalyticsParam(io.gravitee.management.rest.resource.param.AnalyticsParam) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) API_ANALYTICS(io.gravitee.management.model.permissions.RolePermission.API_ANALYTICS) MANAGEMENT_PLATFORM(io.gravitee.management.model.permissions.RolePermission.MANAGEMENT_PLATFORM) Range(io.gravitee.management.rest.resource.param.Range) Permissions(io.gravitee.management.rest.security.Permissions) PermissionService(io.gravitee.management.service.PermissionService) Collectors(java.util.stream.Collectors) ApplicationService(io.gravitee.management.service.ApplicationService) BeanParam(javax.ws.rs.BeanParam) READ(io.gravitee.management.model.permissions.RolePermissionAction.READ) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) Response(javax.ws.rs.core.Response) APPLICATION_ANALYTICS(io.gravitee.management.model.permissions.RolePermission.APPLICATION_ANALYTICS) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Analytics(io.gravitee.management.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Permissions(io.gravitee.management.rest.security.Permissions)

Example 7 with Permission

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

the class ApiSubscribersResource method listApiSubscribers.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscribers for the API", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of API subscribers", response = ApplicationEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public Collection<ApplicationEntity> listApiSubscribers(@PathParam("api") String api) {
    SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
    subscriptionQuery.setApi(api);
    Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
    return subscriptions.stream().map(SubscriptionEntity::getApplication).distinct().map(application -> applicationService.findById(application)).sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())).collect(Collectors.toList());
}
Also used : SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) Permission(io.gravitee.management.rest.security.Permission) PathParam(javax.ws.rs.PathParam) Context(javax.ws.rs.core.Context) SubscriptionService(io.gravitee.management.service.SubscriptionService) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Collection(java.util.Collection) RolePermission(io.gravitee.management.model.permissions.RolePermission) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Permissions(io.gravitee.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ApplicationService(io.gravitee.management.service.ApplicationService) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(io.gravitee.common.http.MediaType) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) SubscriptionEntity(io.gravitee.management.model.SubscriptionEntity) Api(io.swagger.annotations.Api) SubscriptionEntity(io.gravitee.management.model.SubscriptionEntity) SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Permission (io.gravitee.management.rest.security.Permission)7 RolePermission (io.gravitee.management.model.permissions.RolePermission)6 Principal (java.security.Principal)5 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)4 UriInfo (javax.ws.rs.core.UriInfo)4 ApiEntity (io.gravitee.management.model.ApiEntity)3 RoleEntity (io.gravitee.management.model.RoleEntity)3 MediaType (io.gravitee.common.http.MediaType)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 Permissions (io.gravitee.management.rest.security.Permissions)2 ApplicationService (io.gravitee.management.service.ApplicationService)2 Api (io.swagger.annotations.Api)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 SubscriptionEntity (io.gravitee.management.model.SubscriptionEntity)1 Analytics (io.gravitee.management.model.analytics.Analytics)1