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;
}
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();
}
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());
}
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();
}
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);
}
Aggregations