Search in sources :

Example 36 with ResponseEntity

use of org.springframework.http.ResponseEntity in project Activiti by Activiti.

the class UserPictureResource method getUserPicture.

@RequestMapping(value = "/identity/users/{userId}/picture", method = RequestMethod.GET)
public ResponseEntity<byte[]> getUserPicture(@PathVariable String userId, HttpServletRequest request, HttpServletResponse response) {
    User user = getUserFromRequest(userId);
    Picture userPicture = identityService.getUserPicture(user.getId());
    if (userPicture == null) {
        throw new ActivitiObjectNotFoundException("The user with id '" + user.getId() + "' does not have a picture.", Picture.class);
    }
    HttpHeaders responseHeaders = new HttpHeaders();
    if (userPicture.getMimeType() != null) {
        responseHeaders.set("Content-Type", userPicture.getMimeType());
    } else {
        responseHeaders.set("Content-Type", "image/jpeg");
    }
    try {
        return new ResponseEntity<byte[]>(IOUtils.toByteArray(userPicture.getInputStream()), responseHeaders, HttpStatus.OK);
    } catch (Exception e) {
        throw new ActivitiException("Error exporting picture: " + e.getMessage(), e);
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ActivitiException(org.activiti.engine.ActivitiException) User(org.activiti.engine.identity.User) Picture(org.activiti.engine.identity.Picture) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with ResponseEntity

use of org.springframework.http.ResponseEntity in project ORCID-Source by ORCID.

the class PasswordResetController method issuePasswordResetRequest.

@RequestMapping(value = "/reset-password.json", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<EmailRequest> issuePasswordResetRequest(HttpServletRequest request, @RequestBody EmailRequest passwordResetRequest) {
    for (String param : request.getParameterMap().keySet()) {
        if (!RESET_PASSWORD_PARAMS_WHITELIST.contains(param)) {
            // found parameter that has not been white-listed
            return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
        }
    }
    List<String> errors = new ArrayList<>();
    passwordResetRequest.setErrors(errors);
    if (!validateEmailAddress(passwordResetRequest.getEmail())) {
        errors.add(getMessage("Email.resetPasswordForm.invalidEmail"));
        return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK);
    }
    OrcidProfile profile = orcidProfileManager.retrieveOrcidProfileByEmail(passwordResetRequest.getEmail(), LoadOptions.BIO_ONLY);
    if (profile == null) {
        errors.add(getMessage("orcid.frontend.reset.password.email_not_found", passwordResetRequest.getEmail()));
        return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK);
    }
    if (profile.isDeactivated()) {
        errors.add(getMessage("orcid.frontend.reset.password.disabled_account", passwordResetRequest.getEmail()));
        return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK);
    }
    registrationManager.resetUserPassword(passwordResetRequest.getEmail(), profile);
    passwordResetRequest.setSuccessMessage(getMessage("orcid.frontend.reset.password.successfulReset") + " " + passwordResetRequest.getEmail());
    return new ResponseEntity<>(passwordResetRequest, HttpStatus.OK);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) ResponseEntity(org.springframework.http.ResponseEntity) ArrayList(java.util.ArrayList) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 38 with ResponseEntity

use of org.springframework.http.ResponseEntity in project ORCID-Source by ORCID.

the class OrcidOAuth2AuthenticationEntryPoint method handleAsOrcidError.

public void handleAsOrcidError(HttpServletRequest request, HttpServletResponse response, Exception authException) throws IOException, ServletException {
    try {
        ResponseEntity<OAuth2Exception> result = exceptionTranslator.translate(authException);
        result = enhanceResponse(result, authException);
        OrcidError orcidError = new OrcidError();
        orcidError.setResponseCode(result.getStatusCode().value());
        orcidError.setDeveloperMessage(result.getBody().getLocalizedMessage());
        ResponseEntity<OrcidError> errorResponseEntity = new ResponseEntity<>(orcidError, result.getHeaders(), result.getStatusCode());
        exceptionRenderer.handleHttpEntityResponse(errorResponseEntity, new ServletWebRequest(request, response));
        response.flushBuffer();
    } catch (ServletException e) {
        // (even if there is one)
        if (handlerExceptionResolver.resolveException(request, response, this, e) == null) {
            throw e;
        }
    } catch (IOException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        // Wrap other Exceptions. These are not expected to happen
        throw new RuntimeException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) OrcidError(org.orcid.jaxb.model.error_v2.OrcidError) ResponseEntity(org.springframework.http.ResponseEntity) IOException(java.io.IOException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AccessDeniedException(org.springframework.security.access.AccessDeniedException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) AuthenticationException(org.springframework.security.core.AuthenticationException)

Example 39 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class AccountController method getAccount3.

/**
	 * @api {get} /pages/accounts/study/:studyOid/studysubject/:studySubjectId Retrieve a user account - participant
	 * @apiName getAccount3
	 * @apiPermission Module participate - enabled & admin
	 * @apiVersion 3.8.0
	 * @apiParam {String} studyOid Study Oid.
	 * @apiParam {String} studySubjectId Study Subject Id .
	 * @apiGroup User Account
	 * @apiDescription Retrieves the participant user account with the given studySubjectId and studyOid
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "studyOid": " S_BL101",
	 *                  "studySubjectId": "Sub100"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    HTTP/1.1 200 OK
	 *                    {
	 *                    "lName": "",
	 *                    "mobile": "JTaa7WGRdH5dGs42XyTrgA==",
	 *                    "accessCode": "5s02UFpiMBijWuzaxSOojg==",
	 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
	 *                    "email": "XzJadh3l3V7uUoPCggbSoIfoNW8IQU3qsvrtHfJH7J0=",
	 *                    "userName": "S_BL101.SS_SUB100",
	 *                    "studySubjectId": null,
	 *                    "fName": "pdyGCN1CdAKIGOUEERz/yQ=="
	 *                    }
	 */
@RequestMapping(value = "/study/{studyOid}/studysubject/{studySubjectId}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getAccount3(@PathVariable("studyOid") String studyOid, @PathVariable("studySubjectId") String studySubjectId) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    uDTO = null;
    System.out.println("I'm in getAccount3");
    StudyBean parentStudy = getParentStudy(studyOid);
    String oid = parentStudy.getOid();
    StudySubjectBean studySubjectBean = getStudySubject(studySubjectId, parentStudy);
    if (isStudyASiteLevelStudy(studyOid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (!mayProceed(oid, studySubjectBean))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isStudyDoesNotExist(oid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isStudySubjectDoesNotExist(studySubjectBean))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    // build UserName
    HashMap<String, String> mapValues = buildParticipantUserName(studySubjectBean);
    // Participant User Name
    String pUserName = mapValues.get("pUserName");
    udao = new UserAccountDAO(dataSource);
    UserAccountBean userAccountBean = (UserAccountBean) udao.findByUserName(pUserName);
    if (!userAccountBean.isActive()) {
        uDTO = new UserDTO();
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
    } else {
        buildUserDTO(userAccountBean);
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
    }
}
Also used : Locale(java.util.Locale) ResponseEntity(org.springframework.http.ResponseEntity) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserDTO(org.akaza.openclinica.bean.login.UserDTO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 40 with ResponseEntity

use of org.springframework.http.ResponseEntity in project OpenClinica by OpenClinica.

the class AccountController method getAccount1.

/**
	 * @api {get} /pages/accounts/study/:studyOid/crc/:crcUserName Retrieve a user account - crc
	 * @apiName getAccount1
	 * @apiPermission Module participate - enabled & admin
	 * @apiVersion 3.8.0
	 * @apiParam {String} studyOid Study Oid.
	 * @apiParam {String} crcUserName CRC Username .
	 * @apiGroup User Account
	 * @apiDescription Retrieves the crc user account with the given crcUserName and studyOid
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "studyOid": " S_BL101",
	 *                  "crcUserName": "crc_user"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    HTTP/1.1 200 OK
	 *                    {
	 *                    "lName": "Jackson",
	 *                    "mobile": "",
	 *                    "accessCode": "",
	 *                    "apiKey": "6e8b69f6fb774e899f9a6c349c5adace",
	 *                    "password": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
	 *                    "email": "abc@yahoo.com",
	 *                    "userName": "crc_user",
	 *                    "studySubjectId": null,
	 *                    "fName": "joe"
	 *                    }
	 */
@RequestMapping(value = "/study/{studyOid}/crc/{crcUserName}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getAccount1(@PathVariable("studyOid") String studyOid, @PathVariable("crcUserName") String crcUserName) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    uDTO = null;
    System.out.println("I'm in getAccount1");
    StudyBean parentStudy = getParentStudy(studyOid);
    Integer pStudyId = parentStudy.getId();
    String oid = parentStudy.getOid();
    if (isStudyASiteLevelStudy(studyOid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (!mayProceed(oid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isStudyDoesNotExist(oid))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (isCRCUserAccountDoesNotExist(crcUserName))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    if (doesCRCNotHaveStudyAccessRole(crcUserName, pStudyId))
        return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    UserAccountBean userAccountBean = (UserAccountBean) udao.findByUserName(crcUserName);
    buildUserDTO(userAccountBean);
    return new ResponseEntity<UserDTO>(uDTO, org.springframework.http.HttpStatus.OK);
}
Also used : Locale(java.util.Locale) ResponseEntity(org.springframework.http.ResponseEntity) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserDTO(org.akaza.openclinica.bean.login.UserDTO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean)

Aggregations

ResponseEntity (org.springframework.http.ResponseEntity)279 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)91 HttpHeaders (org.springframework.http.HttpHeaders)89 ApiOperation (io.swagger.annotations.ApiOperation)44 Test (org.junit.Test)39 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)39 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)38 ArrayList (java.util.ArrayList)34 Locale (java.util.Locale)32 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)32 HashMap (java.util.HashMap)30 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)24 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)22 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)16 ApiResponses (io.swagger.annotations.ApiResponses)16 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)16 List (java.util.List)15 InputStream (java.io.InputStream)14 MediaType (org.springframework.http.MediaType)14 IOException (java.io.IOException)13