Search in sources :

Example 1 with ApiPermission

use of io.gravitee.management.model.permissions.ApiPermission in project gravitee-management-rest-api by gravitee-io.

the class ApiMembersResource method getPermissions.

@GET
@Path("/permissions")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get API members", notes = "User must have the MANAGE_MEMBERS permission to use this service")
@ApiResponses({ @ApiResponse(code = 200, message = "API member's permissions", response = MemberEntity.class, responseContainer = "List"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getPermissions(@PathParam("api") String api) {
    final ApiEntity apiEntity = apiService.findById(api);
    Map<String, char[]> permissions = new HashMap<>();
    if (isAuthenticated()) {
        final String userId = getAuthenticatedUser();
        if (isAdmin()) {
            final char[] rights = new char[] { CREATE.getId(), READ.getId(), UPDATE.getId(), DELETE.getId() };
            for (ApiPermission perm : ApiPermission.values()) {
                permissions.put(perm.getName(), rights);
            }
        } else {
            permissions = membershipService.getMemberPermissions(apiEntity, userId);
        }
    }
    return Response.ok(permissions).build();
}
Also used : HashMap(java.util.HashMap) ApiPermission(io.gravitee.management.model.permissions.ApiPermission) ApiEntity(io.gravitee.management.model.ApiEntity)

Aggregations

ApiEntity (io.gravitee.management.model.ApiEntity)1 ApiPermission (io.gravitee.management.model.permissions.ApiPermission)1 HashMap (java.util.HashMap)1