Search in sources :

Example 11 with ForbiddenException

use of javax.ws.rs.ForbiddenException in project mica2 by obiba.

the class DataAccessRequestResource method submit.

// 
// Private methods
// 
private Response submit(String id) {
    DataAccessRequest request = dataAccessRequestService.findById(id);
    boolean fromOpened = request.getStatus() == DataAccessRequest.Status.OPENED;
    boolean fromConditionallyApproved = request.getStatus() == DataAccessRequest.Status.CONDITIONALLY_APPROVED;
    if (fromOpened && !subjectAclService.isCurrentUser(request.getApplicant())) {
        // only applicant can submit an opened request
        throw new ForbiddenException();
    }
    dataAccessRequestService.updateStatus(id, DataAccessRequest.Status.SUBMITTED);
    if (fromOpened || fromConditionallyApproved) {
        // applicant cannot edit, nor delete request anymore + status cannot be changed
        subjectAclService.removePermission("/data-access-request", "EDIT,DELETE", id);
        subjectAclService.removePermission("/data-access-request/" + id, "EDIT", "_status");
        // data access officers can change the status of this request
        subjectAclService.addGroupPermission(Roles.MICA_DAO, "/data-access-request/" + id, "EDIT", "_status");
    }
    return Response.noContent().build();
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest)

Aggregations

ForbiddenException (javax.ws.rs.ForbiddenException)11 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 BadRequestException (javax.ws.rs.BadRequestException)4 NotFoundException (javax.ws.rs.NotFoundException)4 Path (javax.ws.rs.Path)4 ApiResponses (io.swagger.annotations.ApiResponses)3 Produces (javax.ws.rs.Produces)3 SystemJob (org.graylog2.system.jobs.SystemJob)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotAuthorizedException (javax.ws.rs.NotAuthorizedException)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 SystemJobConcurrencyException (org.graylog2.system.jobs.SystemJobConcurrencyException)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 AuthenticationException (io.dropwizard.auth.AuthenticationException)1 GeneralSecurityException (java.security.GeneralSecurityException)1