Search in sources :

Example 1 with ApplicationPermission

use of io.gravitee.management.model.permissions.ApplicationPermission 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();
}
Also used : HashMap(java.util.HashMap) ApplicationEntity(io.gravitee.management.model.ApplicationEntity) ApplicationPermission(io.gravitee.management.model.permissions.ApplicationPermission) Permissions(io.gravitee.management.rest.security.Permissions)

Aggregations

ApplicationEntity (io.gravitee.management.model.ApplicationEntity)1 ApplicationPermission (io.gravitee.management.model.permissions.ApplicationPermission)1 Permissions (io.gravitee.management.rest.security.Permissions)1 HashMap (java.util.HashMap)1