use of io.gravitee.rest.api.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAnalyticsResource method getApplicationAnalyticsHits.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get application analytics", notes = "User must have the APPLICATION_ANALYTICS[READ] permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Application analytics"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_ANALYTICS, acls = RolePermissionAction.READ) })
public Response getApplicationAnalyticsHits(@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;
case STATS:
analytics = executeStats(application, analyticsParam);
break;
}
return Response.ok(analytics).build();
}
use of io.gravitee.rest.api.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationSubscribedResource method getApiSubscribed.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List APIs subscribed by the application", notes = "User must have the APPLICATION_SUBSCRIPTION permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of subscribed APIs", response = ApplicationEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public Collection<SubscribedApi> getApiSubscribed() {
SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
subscriptionQuery.setApplication(application);
Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
return subscriptions.stream().map(SubscriptionEntity::getApi).distinct().map(api -> apiService.findById(api)).map(apiEntity -> new SubscribedApi(apiEntity.getId(), apiEntity.getName())).sorted((o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName())).collect(Collectors.toList());
}
use of io.gravitee.rest.api.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationsResource method createApplication.
/**
* Create a new application for the authenticated user.
*
* @param application
* @return
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an application", notes = "User must have MANAGEMENT_APPLICATION[CREATE] permission to create an application.")
@ApiResponses({ @ApiResponse(code = 201, message = "Application successfully created", response = ApplicationEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE) })
public Response createApplication(@ApiParam(name = "application", required = true) @Valid @NotNull(message = "An application must be provided") final NewApplicationEntity application) {
// To preserve backward compatibility, ensure that we have at least default settings for simple application type
if (application.getSettings() == null || (application.getSettings().getoAuthClient() == null && application.getSettings().getApp() == null)) {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings simpleAppSettings = new SimpleApplicationSettings();
simpleAppSettings.setType(application.getType());
simpleAppSettings.setClientId(application.getClientId());
settings.setApp(simpleAppSettings);
application.setSettings(settings);
}
ApplicationEntity newApplication = applicationService.create(application, getAuthenticatedUser());
if (newApplication != null) {
return Response.created(this.getLocationHeader(newApplication.getId())).entity(newApplication).build();
}
return Response.serverError().build();
}
use of io.gravitee.rest.api.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method updateApiPage.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public PageEntity updateApiPage(@ApiParam(name = "page", required = true) @Valid @NotNull UpdatePageEntity updatePageEntity) {
PageEntity existingPage = pageService.findById(page);
if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
throw new PageSystemFolderActionException("Update");
} else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
throw new PageMarkdownTemplateActionException("Update");
}
updatePageEntity.setLastContributor(getAuthenticatedUser());
return pageService.update(page, updatePageEntity);
}
use of io.gravitee.rest.api.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApiPageResource method partialUpdateApiPage.
@PATCH
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update a page", notes = "User must have the MANAGE_PAGES permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully updated", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.API_DOCUMENTATION, acls = RolePermissionAction.UPDATE) })
public PageEntity partialUpdateApiPage(@ApiParam(name = "page") UpdatePageEntity updatePageEntity) {
PageEntity existingPage = pageService.findById(page);
if (existingPage.getType().equals(PageType.SYSTEM_FOLDER.name())) {
throw new PageSystemFolderActionException("Update");
} else if (existingPage.getType().equals(PageType.MARKDOWN_TEMPLATE.name())) {
throw new PageMarkdownTemplateActionException("Update");
}
updatePageEntity.setLastContributor(getAuthenticatedUser());
return pageService.update(page, updatePageEntity, true);
}
Aggregations