use of org.springframework.web.bind.annotation.CrossOrigin in project c4sg-services by Code4SocialGood.
the class OrganizationController method retrieveOrganizationLogo.
@CrossOrigin
@RequestMapping(value = "/{id}/logo", method = RequestMethod.GET)
@ApiOperation(value = "Retrieves organization logo")
public String retrieveOrganizationLogo(@ApiParam(value = "Organization id to get logo for", required = true) @PathVariable("id") int id) {
File logo = new File(organizationService.getLogoUploadPath(id));
try {
FileInputStream fileInputStreamReader = new FileInputStream(logo);
byte[] bytes = new byte[(int) logo.length()];
fileInputStreamReader.read(bytes);
fileInputStreamReader.close();
return new String(Base64.encodeBase64(bytes));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
use of org.springframework.web.bind.annotation.CrossOrigin in project ORCID-Source by ORCID.
the class OpenIDController method getUserInfo.
/**
* Manually checks bearer token, looks up user or throws 403.
*
* @return
*/
@CrossOrigin
@RequestMapping(value = "/oauth/userinfo", method = { RequestMethod.GET, RequestMethod.POST }, produces = "application/json")
@ResponseBody
public ResponseEntity<OpenIDConnectUserInfo> getUserInfo(HttpServletRequest request) {
// note we do not support form post per https://tools.ietf.org/html/rfc6750 because it's a MAY and pointless
String authHeader = request.getHeader("Authorization");
if (authHeader != null) {
// lookup token, check it's valid, check scope.
// deal with incorrect bearer case in request (I'm looking at you spring security!)
String tokenValue = authHeader.replaceAll("Bearer|bearer", "").trim();
OAuth2AccessToken tok = tokenStore.readAccessToken(tokenValue);
if (tok != null && !tok.isExpired()) {
boolean hasScope = false;
Set<ScopePathType> requestedScopes = ScopePathType.getScopesFromStrings(tok.getScope());
for (ScopePathType scope : requestedScopes) {
if (scope.hasScope(ScopePathType.AUTHENTICATE)) {
hasScope = true;
}
}
if (hasScope) {
String orcid = tok.getAdditionalInformation().get("orcid").toString();
Person person = personDetailsManagerReadOnly.getPublicPersonDetails(orcid);
return ResponseEntity.ok(new OpenIDConnectUserInfo(orcid, person, path));
}
}
}
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
use of org.springframework.web.bind.annotation.CrossOrigin in project sonarQuest by viadee.
the class TaskController method deleteFromQuest.
@CrossOrigin
@RequestMapping(value = "/{taskId}/deleteFromQuest", method = RequestMethod.DELETE)
public void deleteFromQuest(@PathVariable(value = "taskId") final Long taskId) {
final Task task = this.taskRepository.findOne(taskId);
if (task != null) {
task.setQuest(null);
task.setStatus(TaskStates.CREATED);
this.taskRepository.save(task);
}
}
use of org.springframework.web.bind.annotation.CrossOrigin in project sonarQuest by viadee.
the class TaskController method updateTask.
@CrossOrigin
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public TaskDto updateTask(@PathVariable(value = "id") final Long id, @RequestBody final TaskDto taskDto) {
TaskDto resultTaskDto = null;
final Task task = this.taskRepository.findById(id);
if (task != null) {
task.setTitle(taskDto.getTitle());
task.setGold(taskDto.getGold());
task.setXp(taskDto.getXp());
this.taskRepository.save(task);
resultTaskDto = toTaskDto(task);
}
if (task instanceof SpecialTask) {
((SpecialTask) task).setMessage(((SpecialTaskDto) taskDto).getMessage());
this.taskRepository.save(task);
resultTaskDto = toTaskDto(task);
}
return resultTaskDto;
}
use of org.springframework.web.bind.annotation.CrossOrigin in project sonarQuest by viadee.
the class TaskController method solveSpecialTask.
@CrossOrigin
@RequestMapping(value = "/{taskId}/solveSpecialTask/", method = RequestMethod.PUT)
public TaskDto solveSpecialTask(@PathVariable(value = "taskId") final Long taskId) {
Task task = this.taskRepository.findOne(taskId);
if (task != null && task instanceof SpecialTask) {
task.setStatus(TaskStates.SOLVED);
task = this.taskRepository.save(task);
gratificationService.rewardDeveloperForSolvingTask(task);
questService.updateQuest(task.getQuest());
adventureService.updateAdventure(task.getQuest().getAdventure());
}
return toTaskDto(task);
}
Aggregations