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);
}
}
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);
}
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);
}
}
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);
}
}
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);
}
Aggregations