Search in sources :

Example 11 with Permissions

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

the class ApiSubscriptionsResource method listApiSubscriptions.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscriptions for the API", notes = "User must have the READ_SUBSCRIPTION permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of API's subscriptions", response = PagedResult.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public PagedResult<SubscriptionEntity> listApiSubscriptions(@BeanParam SubscriptionParam subscriptionParam, @Valid @BeanParam Pageable pageable) {
    // Transform query parameters to a subscription query
    SubscriptionQuery subscriptionQuery = subscriptionParam.toQuery();
    Page<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery, pageable.toPageable());
    PagedResult<SubscriptionEntity> result = new PagedResult<>(subscriptions, pageable.getSize());
    result.setMetadata(subscriptionService.getMetadata(subscriptions.getContent()).getMetadata());
    return result;
}
Also used : SubscriptionQuery(io.gravitee.management.model.subscription.SubscriptionQuery) PagedResult(io.gravitee.management.rest.model.PagedResult) Permissions(io.gravitee.management.rest.security.Permissions)

Example 12 with Permissions

use of io.gravitee.management.rest.security.Permissions 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 13 with Permissions

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

the class GroupMembersResource method getMembers.

@GET
@Produces(io.gravitee.common.http.MediaType.APPLICATION_JSON)
@ApiOperation(value = "List Group members")
@ApiResponses({ @ApiResponse(code = 200, message = "List of Group's members", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_GROUP, acls = RolePermissionAction.READ) })
public List<GroupMemberEntity> getMembers(@PathParam("group") String group) {
    // check that group exists
    groupService.findById(group);
    Map<String, List<MemberEntity>> membersWithApplicationRole = membershipService.getMembers(MembershipReferenceType.GROUP, group, RoleScope.APPLICATION).stream().filter(Objects::nonNull).collect(Collectors.groupingBy(MemberEntity::getId));
    Map<String, List<MemberEntity>> membersWithApiRole = membershipService.getMembers(MembershipReferenceType.GROUP, group, RoleScope.API).stream().filter(Objects::nonNull).collect(Collectors.groupingBy(MemberEntity::getId));
    Set<String> ids = new HashSet<>();
    ids.addAll(membersWithApiRole.keySet());
    ids.addAll(membersWithApplicationRole.keySet());
    return ids.stream().map(id -> {
        MemberEntity memberWithApiRole = Objects.isNull(membersWithApiRole.get(id)) ? null : membersWithApiRole.get(id).get(0);
        MemberEntity memberWithApplicationRole = Objects.isNull(membersWithApplicationRole.get(id)) ? null : membersWithApplicationRole.get(id).get(0);
        GroupMemberEntity groupMemberEntity = new GroupMemberEntity(Objects.nonNull(memberWithApiRole) ? memberWithApiRole : memberWithApplicationRole);
        groupMemberEntity.setRoles(new HashMap<>());
        if (Objects.nonNull(memberWithApiRole)) {
            groupMemberEntity.getRoles().put(RoleScope.API.name(), memberWithApiRole.getRole());
        }
        if (Objects.nonNull(memberWithApplicationRole)) {
            groupMemberEntity.getRoles().put(RoleScope.APPLICATION.name(), memberWithApplicationRole.getRole());
        }
        return groupMemberEntity;
    }).sorted(Comparator.comparing(GroupMemberEntity::getId)).collect(Collectors.toList());
}
Also used : GroupMemberEntity(io.gravitee.management.model.GroupMemberEntity) GroupMemberEntity(io.gravitee.management.model.GroupMemberEntity) MemberEntity(io.gravitee.management.model.MemberEntity) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with Permissions

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

the class ApplicationAnalyticsResource method hits.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get Application analytics")
@Permissions({ @Permission(value = RolePermission.APPLICATION_ANALYTICS, acls = RolePermissionAction.READ) })
public Response hits(@PathParam("application") String application, @BeanParam AnalyticsParam analyticsParam) {
    analyticsParam.validate();
    Analytics analytics = null;
    switch(analyticsParam.getTypeParam().getValue()) {
        case DATE_HISTO:
            analytics = executeDateHisto(application, analyticsParam);
            break;
        case GROUP_BY:
            analytics = executeGroupBy(application, analyticsParam);
            break;
        case COUNT:
            analytics = executeCount(application, analyticsParam);
            break;
    }
    return Response.ok(analytics).build();
}
Also used : Analytics(io.gravitee.management.model.analytics.Analytics) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions)

Example 15 with Permissions

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

the class ApplicationLogsResource method applicationLogs.

@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get application logs")
@ApiResponses({ @ApiResponse(code = 200, message = "Application logs"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_LOG, acls = RolePermissionAction.READ) })
public SearchLogResponse applicationLogs(@PathParam("application") String application, @BeanParam LogsParam param) {
    param.validate();
    LogQuery logQuery = new LogQuery();
    logQuery.setQuery(param.getQuery());
    logQuery.setPage(param.getPage());
    logQuery.setSize(param.getSize());
    logQuery.setFrom(param.getFrom());
    logQuery.setTo(param.getTo());
    return logsService.findByApplication(application, logQuery);
}
Also used : LogQuery(io.gravitee.management.model.analytics.query.LogQuery) ApiOperation(io.swagger.annotations.ApiOperation) Permissions(io.gravitee.management.rest.security.Permissions) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Permissions (io.gravitee.management.rest.security.Permissions)21 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)7 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 MemberEntity (io.gravitee.management.model.MemberEntity)4 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)3 Analytics (io.gravitee.management.model.analytics.Analytics)3 LogQuery (io.gravitee.management.model.analytics.query.LogQuery)3 SubscriptionQuery (io.gravitee.management.model.subscription.SubscriptionQuery)3 MediaType (io.gravitee.common.http.MediaType)2 ApiEntity (io.gravitee.management.model.ApiEntity)2 GroupMemberEntity (io.gravitee.management.model.GroupMemberEntity)2 AuditQuery (io.gravitee.management.model.audit.AuditQuery)2 RolePermission (io.gravitee.management.model.permissions.RolePermission)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 PagedResult (io.gravitee.management.rest.model.PagedResult)2 Permission (io.gravitee.management.rest.security.Permission)2 ApplicationService (io.gravitee.management.service.ApplicationService)2 MembershipService (io.gravitee.management.service.MembershipService)2