use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMembersResource method getPermissions.
@GET
@Path("/permissions")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get application members", notes = "User must have the APPLICATION_MEMBER permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Application member's permissions", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.READ) })
public Response getPermissions(@PathParam("application") String application) {
Map<String, char[]> permissions = new HashMap<>();
if (isAuthenticated()) {
final String username = getAuthenticatedUser();
final ApplicationEntity applicationEntity = applicationService.findById(application);
if (isAdmin()) {
final char[] rights = new char[] { CREATE.getId(), READ.getId(), UPDATE.getId(), DELETE.getId() };
for (ApplicationPermission perm : ApplicationPermission.values()) {
permissions.put(perm.getName(), rights);
}
} else {
permissions = membershipService.getMemberPermissions(applicationEntity, username);
}
}
return Response.ok(permissions).build();
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMembersResource method addOrUpdateApplicationMember.
@POST
@ApiOperation(value = "Add or update an application member", notes = "User must have the MANAGE_MEMBERS permission to use this service")
@ApiResponses({ @ApiResponse(code = 201, message = "Member has been added or updated successfully"), @ApiResponse(code = 400, message = "Membership parameter is not valid"), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.CREATE), @Permission(value = RolePermission.APPLICATION_MEMBER, acls = RolePermissionAction.UPDATE) })
public Response addOrUpdateApplicationMember(@PathParam("application") String application, @Valid @NotNull ApplicationMembership applicationMembership) {
if (PRIMARY_OWNER.name().equals(applicationMembership.getRole())) {
throw new SinglePrimaryOwnerException(RoleScope.APPLICATION);
}
applicationService.findById(application);
MemberEntity membership = membershipService.addOrUpdateMember(new MembershipService.MembershipReference(MembershipReferenceType.APPLICATION, application), new MembershipService.MembershipUser(applicationMembership.getId(), applicationMembership.getReference()), new MembershipService.MembershipRole(RoleScope.APPLICATION, applicationMembership.getRole()));
return Response.created(URI.create("/applications/" + application + "/members/" + membership.getId())).build();
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApplicationSubscriptionsResource method listApplicationSubscriptions.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List subscriptions for the application", notes = "User must have the READ_SUBSCRIPTION permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "Paged result of application's subscriptions", response = PagedResult.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.APPLICATION_SUBSCRIPTION, acls = RolePermissionAction.READ) })
public PagedResult<SubscriptionEntity> listApplicationSubscriptions(@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 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());
}
use of io.gravitee.management.rest.security.Permissions in project gravitee-management-rest-api by gravitee-io.
the class ApiSubscriptionsResource 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.API_SUBSCRIPTION, acls = RolePermissionAction.CREATE) })
public Response createSubscription(@PathParam("api") String api, @ApiParam(name = "application", required = true) @NotNull @QueryParam("application") String application, @ApiParam(name = "plan", required = true) @NotNull @QueryParam("plan") String plan) {
// Create subscription
SubscriptionEntity subscription = subscriptionService.create(new NewSubscriptionEntity(plan, application));
if (subscription.getStatus() == SubscriptionStatus.PENDING) {
ProcessSubscriptionEntity process = new ProcessSubscriptionEntity();
process.setId(subscription.getId());
process.setAccepted(true);
process.setStartingAt(new Date());
subscription = subscriptionService.process(process, getAuthenticatedUser());
}
return Response.created(URI.create("/apis/" + api + "/subscriptions/" + subscription.getId())).entity(convert(subscription)).build();
}
Aggregations