Search in sources :

Example 56 with Permission

use of io.gravitee.am.model.permissions.Permission in project gravitee-access-management by gravitee-io.

the class GroupMemberResource method addMember.

@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Add a group member", notes = "User must have the ORGANIZATION_GROUP[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 200, message = "Member has been added successfully"), @ApiResponse(code = 400, message = "User does not exist"), @ApiResponse(code = 500, message = "Internal server error") })
public void addMember(@PathParam("organizationId") String organizationId, @PathParam("group") String group, @PathParam("member") String userId, @Suspended final AsyncResponse response) {
    final io.gravitee.am.identityprovider.api.User authenticatedUser = getAuthenticatedUser();
    checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_GROUP, Acl.UPDATE).andThen(groupService.findById(ReferenceType.ORGANIZATION, organizationId, group).flatMap(group1 -> userService.findById(ReferenceType.ORGANIZATION, organizationId, userId).flatMap(user -> {
        if (group1.getMembers() != null && group1.getMembers().contains(userId)) {
            return Single.error(new MemberAlreadyExistsException(userId));
        }
        List<String> groupMembers = group1.getMembers() != null ? new ArrayList(group1.getMembers()) : new ArrayList();
        groupMembers.add(userId);
        UpdateGroup updateGroup = new UpdateGroup();
        updateGroup.setName(group1.getName());
        updateGroup.setDescription(group1.getDescription());
        updateGroup.setRoles(group1.getRoles());
        updateGroup.setMembers(groupMembers);
        return groupService.update(ReferenceType.ORGANIZATION, organizationId, group, updateGroup, authenticatedUser);
    }))).subscribe(response::resume, response::resume);
}
Also used : UserService(io.gravitee.am.management.service.UserService) PathParam(javax.ws.rs.PathParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) AsyncResponse(javax.ws.rs.container.AsyncResponse) Permission(io.gravitee.am.model.permissions.Permission) Autowired(org.springframework.beans.factory.annotation.Autowired) MemberAlreadyExistsException(io.gravitee.am.service.exception.MemberAlreadyExistsException) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) UpdateGroup(io.gravitee.am.service.model.UpdateGroup) Single(io.reactivex.Single) Suspended(javax.ws.rs.container.Suspended) ArrayList(java.util.ArrayList) Acl(io.gravitee.am.model.Acl) MemberNotFoundException(io.gravitee.am.service.exception.MemberNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) MediaType(io.gravitee.common.http.MediaType) ApiResponse(io.swagger.annotations.ApiResponse) ReferenceType(io.gravitee.am.model.ReferenceType) GroupService(io.gravitee.am.service.GroupService) DELETE(javax.ws.rs.DELETE) MemberAlreadyExistsException(io.gravitee.am.service.exception.MemberAlreadyExistsException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) PathParam(javax.ws.rs.PathParam) UpdateGroup(io.gravitee.am.service.model.UpdateGroup) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Permission (io.gravitee.am.model.permissions.Permission)56 Acl (io.gravitee.am.model.Acl)49 AsyncResponse (javax.ws.rs.container.AsyncResponse)49 Suspended (javax.ws.rs.container.Suspended)49 Autowired (org.springframework.beans.factory.annotation.Autowired)49 User (io.gravitee.am.identityprovider.api.User)47 MediaType (io.gravitee.common.http.MediaType)47 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)44 Response (javax.ws.rs.core.Response)41 javax.ws.rs (javax.ws.rs)40 Maybe (io.reactivex.Maybe)39 ResourceContext (javax.ws.rs.container.ResourceContext)39 Context (javax.ws.rs.core.Context)39 DomainService (io.gravitee.am.service.DomainService)38 DomainNotFoundException (io.gravitee.am.service.exception.DomainNotFoundException)37 Valid (javax.validation.Valid)36 NotNull (javax.validation.constraints.NotNull)36 ReferenceType (io.gravitee.am.model.ReferenceType)30 ApiOperation (io.swagger.annotations.ApiOperation)30 ApiResponses (io.swagger.annotations.ApiResponses)30