Search in sources :

Example 16 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DACUserResource method describe.

@GET
@Path("/{email}")
@Produces("application/json")
@PermitAll
public User describe(@Auth AuthUser authUser, @PathParam("email") String email) {
    User searchUser = userService.findUserByEmail(email);
    validateAuthedRoleUser(Stream.of(UserRoles.ADMIN, UserRoles.CHAIRPERSON, UserRoles.MEMBER).collect(Collectors.toList()), findByAuthUser(authUser), searchUser.getDacUserId());
    return searchUser;
}
Also used : GoogleUser(org.broadinstitute.consent.http.authentication.GoogleUser) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Example 17 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DacResource method removeDacMember.

@DELETE
@Path("{dacId}/member/{userId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response removeDacMember(@Auth AuthUser authUser, @PathParam("dacId") Integer dacId, @PathParam("userId") Integer userId) {
    Role role = dacService.getMemberRole();
    User user = findDacUser(userId);
    Dac dac = findDacById(dacId);
    checkUserRoleInDac(dac, authUser);
    try {
        dacService.removeDacMember(role, user, dac);
        return Response.ok().build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : Role(org.broadinstitute.consent.http.models.Role) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed)

Example 18 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DacResource method addDacChair.

@POST
@Path("{dacId}/chair/{userId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response addDacChair(@Auth AuthUser authUser, @PathParam("dacId") Integer dacId, @PathParam("userId") Integer userId) {
    checkUserExistsInDac(dacId, userId);
    Role role = dacService.getChairpersonRole();
    User user = findDacUser(userId);
    Dac dac = findDacById(dacId);
    checkUserRoleInDac(dac, authUser);
    try {
        User member = dacService.addDacMember(role, user, dac);
        return Response.ok().entity(member).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : Role(org.broadinstitute.consent.http.models.Role) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST)

Example 19 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DacResource method checkUserRoleInDac.

/**
 * - Admins can make any modifications to any Dac chairs or members
 * - Chairpersons can only make modifications to chairs and members in a DAC that they are a
 * chairperson in.
 *
 * @param dac The Dac
 * @param authUser The AuthUser
 * @throws NotAuthorizedException Not authorized
 */
private void checkUserRoleInDac(Dac dac, AuthUser authUser) throws NotAuthorizedException {
    User user = userService.findUserByEmail(authUser.getEmail());
    if (user.getRoles().stream().anyMatch(ur -> ur.getRoleId().equals(UserRoles.ADMIN.getRoleId()))) {
        return;
    }
    NotAuthorizedException e = new NotAuthorizedException("User not authorized");
    if (Objects.isNull(dac.getChairpersons()) || dac.getChairpersons().isEmpty()) {
        throw e;
    }
    Optional<User> chair = dac.getChairpersons().stream().filter(u -> u.getDacUserId().equals(user.getDacUserId())).findFirst();
    if (chair.isEmpty()) {
        throw e;
    }
}
Also used : PathParam(javax.ws.rs.PathParam) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Inject(com.google.inject.Inject) Path(javax.ws.rs.Path) Auth(io.dropwizard.auth.Auth) DatasetDTO(org.broadinstitute.consent.http.models.dto.DatasetDTO) UserRoles(org.broadinstitute.consent.http.enumeration.UserRoles) Level(java.util.logging.Level) QueryParam(javax.ws.rs.QueryParam) Gson(com.google.gson.Gson) UserService(org.broadinstitute.consent.http.service.UserService) AuthUser(org.broadinstitute.consent.http.models.AuthUser) BadRequestException(javax.ws.rs.BadRequestException) Role(org.broadinstitute.consent.http.models.Role) DELETE(javax.ws.rs.DELETE) POST(javax.ws.rs.POST) Set(java.util.Set) User(org.broadinstitute.consent.http.models.User) Logger(java.util.logging.Logger) NotFoundException(javax.ws.rs.NotFoundException) Dac(org.broadinstitute.consent.http.models.Dac) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) DacService(org.broadinstitute.consent.http.service.DacService) Optional(java.util.Optional) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) PUT(javax.ws.rs.PUT) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) NotAuthorizedException(javax.ws.rs.NotAuthorizedException)

Example 20 with AuthUser

use of org.broadinstitute.consent.http.models.AuthUser in project consent by DataBiosphere.

the class DacResource method removeDacChair.

@DELETE
@Path("{dacId}/chair/{userId}")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response removeDacChair(@Auth AuthUser authUser, @PathParam("dacId") Integer dacId, @PathParam("userId") Integer userId) {
    Role role = dacService.getChairpersonRole();
    User user = findDacUser(userId);
    Dac dac = findDacById(dacId);
    checkUserRoleInDac(dac, authUser);
    try {
        dacService.removeDacMember(role, user, dac);
        return Response.ok().build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : Role(org.broadinstitute.consent.http.models.Role) AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) Dac(org.broadinstitute.consent.http.models.Dac) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed)

Aggregations

AuthUser (org.broadinstitute.consent.http.models.AuthUser)198 User (org.broadinstitute.consent.http.models.User)181 Test (org.junit.Test)111 Response (javax.ws.rs.core.Response)99 NotFoundException (javax.ws.rs.NotFoundException)61 Produces (javax.ws.rs.Produces)55 Path (javax.ws.rs.Path)48 RolesAllowed (javax.annotation.security.RolesAllowed)46 GoogleUser (org.broadinstitute.consent.http.authentication.GoogleUser)41 UserRole (org.broadinstitute.consent.http.models.UserRole)38 BadRequestException (javax.ws.rs.BadRequestException)35 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)32 Consumes (javax.ws.rs.Consumes)26 ForbiddenException (javax.ws.rs.ForbiddenException)26 DarCollection (org.broadinstitute.consent.http.models.DarCollection)26 Gson (com.google.gson.Gson)24 GET (javax.ws.rs.GET)24 Vote (org.broadinstitute.consent.http.models.Vote)21 PaginationResponse (org.broadinstitute.consent.http.models.PaginationResponse)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19