use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class PlatformEventsResource method listEvents.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_PLATFORM, acls = RolePermissionAction.READ) })
public Page<EventEntity> listEvents(@BeanParam EventSearchParam eventSearchParam) {
eventSearchParam.validate();
Map<String, Object> properties = new HashMap<>();
if (eventSearchParam.getApiIdsParam() != null && eventSearchParam.getApiIdsParam().getIds() != null && !eventSearchParam.getApiIdsParam().getIds().isEmpty()) {
properties.put(Event.EventProperties.API_ID.getValue(), eventSearchParam.getApiIdsParam().getIds());
}
Page<EventEntity> events = eventService.search(eventSearchParam.getEventTypeListParam().getEventTypes(), properties, eventSearchParam.getFrom(), eventSearchParam.getTo(), eventSearchParam.getPage(), eventSearchParam.getSize());
events.getContent().forEach(event -> {
Map<String, String> properties1 = event.getProperties();
// Event relative to API
if (properties1 != null && properties1.containsKey(Event.EventProperties.API_ID.getValue())) {
// Remove payload content from response since it's not required anymore
event.setPayload(null);
// Retrieve additional data
String apiId = properties1.get(Event.EventProperties.API_ID.getValue());
ApiEntity api = apiService.findById(apiId);
properties1.put("api_name", api.getName());
properties1.put("api_version", api.getVersion());
}
});
return events;
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class PortalPagesResource method createPage.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a page", notes = "User must be ADMIN to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Page successfully created", response = PageEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.PORTAL_DOCUMENTATION, acls = RolePermissionAction.CREATE) })
public Response createPage(@ApiParam(name = "page", required = true) @Valid @NotNull NewPageEntity newPageEntity) {
int order = pageService.findMaxPortalPageOrder() + 1;
newPageEntity.setOrder(order);
newPageEntity.setLastContributor(getAuthenticatedUser());
PageEntity newPage = pageService.createPortalPage(newPageEntity);
if (newPage != null) {
return Response.created(URI.create("/portal/pages/" + newPage.getId())).entity(newPage).build();
}
return Response.serverError().build();
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationSubscriptionsResource method createSubscription.
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Subscribe to a plan", notes = "User must have the MANAGE_SUBSCRIPTIONS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Subscription successfully created", response = Subscription.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.CREATE) })
public Response createSubscription(@PathParam("application") String application, @ApiParam(name = "plan", required = true) @NotNull @QueryParam("plan") String plan, NewSubscriptionEntity newSubscriptionEntity) {
newSubscriptionEntity.setApplication(application);
newSubscriptionEntity.setPlan(plan);
Subscription subscription = convert(subscriptionService.create(newSubscriptionEntity));
return Response.created(URI.create("/applications/" + application + "/subscriptions/" + subscription.getId())).entity(subscription).build();
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class AuditResource method list.
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_AUDIT, acls = RolePermissionAction.READ) })
public MetadataPage<AuditEntity> list(@BeanParam AuditParam param) {
AuditQuery query = new AuditQuery();
query.setFrom(param.getFrom());
query.setTo(param.getTo());
query.setPage(param.getPage());
query.setSize(param.getSize());
if (param.isManagementLogsOnly()) {
query.setManagementLogsOnly(true);
} else {
if (param.getApiId() != null) {
query.setApiIds(Collections.singletonList(param.getApiId()));
}
if (param.getApplicationId() != null) {
query.setApplicationIds(Collections.singletonList(param.getApplicationId()));
}
}
if (param.getEvent() != null) {
query.setEvents(Collections.singletonList(param.getEvent()));
}
return auditService.search(query);
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class GroupMembersResource method addOrUpdateMember.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add or update a group member")
@ApiResponses({ @ApiResponse(code = 201, message = "Member has been added"), @ApiResponse(code = 200, message = "Member has been updated"), @ApiResponse(code = 400, message = "Membership is not valid"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.MANAGEMENT_GROUP, acls = RolePermissionAction.CREATE), @Permission(value = RolePermission.MANAGEMENT_GROUP, acls = RolePermissionAction.UPDATE) })
public Response addOrUpdateMember(@PathParam("group") String group, @Valid @NotNull final GroupMembership membership) {
// Check that group exists
groupService.findById(group);
RoleEntity previousApiRole = null, previousApplicationRole = null;
if (membership.getId() != null) {
previousApiRole = membershipService.getRole(MembershipReferenceType.GROUP, group, membership.getId(), RoleScope.API);
previousApplicationRole = membershipService.getRole(MembershipReferenceType.GROUP, group, membership.getId(), RoleScope.APPLICATION);
}
// Process add / update before delete to avoid having a user without role
if (membership.getRoles() != null && !membership.getRoles().isEmpty()) {
MemberRoleEntity apiRole = membership.getRoles().stream().filter(r -> r.getRoleScope().equals(io.gravitee.management.model.permissions.RoleScope.API) && !r.getRoleName().isEmpty()).findFirst().orElse(null);
MemberRoleEntity applicationRole = membership.getRoles().stream().filter(r -> r.getRoleScope().equals(io.gravitee.management.model.permissions.RoleScope.APPLICATION) && !r.getRoleName().isEmpty()).findFirst().orElse(null);
MemberEntity updatedMembership = null;
// Add / Update
if (apiRole != null) {
updatedMembership = membershipService.addOrUpdateMember(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, group), new MembershipService.MembershipUser(membership.getId(), membership.getReference()), new MembershipService.MembershipRole(RoleScope.API, apiRole.getRoleName()));
}
if (applicationRole != null) {
updatedMembership = membershipService.addOrUpdateMember(new MembershipService.MembershipReference(MembershipReferenceType.GROUP, group), new MembershipService.MembershipUser(membership.getId(), membership.getReference()), new MembershipService.MembershipRole(RoleScope.APPLICATION, applicationRole.getRoleName()));
}
// Delete
if (apiRole == null && previousApiRole != null) {
membershipService.removeRole(MembershipReferenceType.GROUP, group, updatedMembership.getId(), RoleScope.API);
}
if (applicationRole == null && previousApplicationRole != null) {
membershipService.removeRole(MembershipReferenceType.GROUP, group, updatedMembership.getId(), RoleScope.APPLICATION);
}
}
return Response.ok().build();
}
Aggregations