Search in sources :

Example 1 with CrossOrigin

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;
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CrossOrigin

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();
}
Also used : ScopePathType(org.orcid.jaxb.model.message.ScopePathType) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OpenIDConnectUserInfo(org.orcid.core.oauth.openid.OpenIDConnectUserInfo) Person(org.orcid.jaxb.model.v3.dev1.record.Person) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with CrossOrigin

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);
    }
}
Also used : SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) Task(com.viadee.sonarQuest.entities.Task) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with CrossOrigin

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;
}
Also used : SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) Task(com.viadee.sonarQuest.entities.Task) SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) SpecialTaskDto(com.viadee.sonarQuest.dtos.SpecialTaskDto) TaskDto(com.viadee.sonarQuest.dtos.TaskDto) TaskDto.toTaskDto(com.viadee.sonarQuest.dtos.TaskDto.toTaskDto) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CrossOrigin

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);
}
Also used : SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) Task(com.viadee.sonarQuest.entities.Task) SpecialTask(com.viadee.sonarQuest.entities.SpecialTask) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)26 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 Task (com.viadee.sonarQuest.entities.Task)8 SpecialTask (com.viadee.sonarQuest.entities.SpecialTask)7 Quest (com.viadee.sonarQuest.entities.Quest)6 ApiOperation (io.swagger.annotations.ApiOperation)5 IOException (java.io.IOException)4 NotFoundException (org.c4sg.exception.NotFoundException)4 UserOrganizationException (org.c4sg.exception.UserOrganizationException)4 SpecialTaskDto (com.viadee.sonarQuest.dtos.SpecialTaskDto)3 TaskDto (com.viadee.sonarQuest.dtos.TaskDto)3 TaskDto.toTaskDto (com.viadee.sonarQuest.dtos.TaskDto.toTaskDto)3 World (com.viadee.sonarQuest.entities.World)3 WikiParsing (infoeval.main.WikiData.WikiParsing)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ArrayList (java.util.ArrayList)3 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)3 OrganizationDTO (org.c4sg.dto.OrganizationDTO)3 BadRequestException (org.c4sg.exception.BadRequestException)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3