use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class AuthenticationTokenFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException, AuthenticationException {
try {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String authToken = httpRequest.getHeader(tokenHeader);
if (authToken == null && httpRequest.getCookies() != null) {
for (Cookie cookie : httpRequest.getCookies()) {
if (cookie.getName().equalsIgnoreCase(tokenHeader)) {
authToken = cookie.getValue();
}
}
}
if (authToken != null) {
String username = this.tokenUtils.getUsernameFromToken(authToken);
if (tokenUtils.isExpired(authToken)) {
if (((HttpServletRequest) request).getRequestURI().startsWith("/api")) {
if (username != null) {
throw new BadCredentialsException("token expired");
}
}
}
if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
if (this.tokenUtils.validateToken(authToken, userDetails)) {
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(httpRequest));
SecurityContextHolder.getContext().setAuthentication(authentication);
TenantContext.setCurrentTenant(((ArachneUser) userDetails).getActiveTenantId());
}
}
}
chain.doFilter(request, response);
} catch (AuthenticationException ex) {
logger.debug(ex.getMessage(), ex);
((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
JsonResult<Boolean> result = new JsonResult<>(JsonResult.ErrorCode.UNAUTHORIZED);
result.setResult(Boolean.FALSE);
response.getOutputStream().write(objectMapper.writeValueAsString(result).getBytes());
response.setContentType("application/json");
}
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseAuthenticationController method logout.
@ApiOperation("Logout.")
@RequestMapping(value = "/api/v1/auth/logout", method = RequestMethod.POST)
public JsonResult logout(HttpServletRequest request) {
JsonResult result;
try {
String token = request.getHeader(tokenHeader);
if (token != null) {
tokenUtils.addInvalidateToken(token);
}
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(true);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.SYSTEM_ERROR);
result.setResult(false);
result.setErrorMessage(ex.getMessage());
}
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method create.
@ApiOperation("Create analysis.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = POST)
public JsonResult<D> create(Principal principal, @RequestBody @Valid A_C_DTO analysisDTO, BindingResult bindingResult) throws PermissionDeniedException, NotExistException, NotUniqueException {
JsonResult<D> result;
IUser user = getUser(principal);
if (bindingResult.hasErrors()) {
return setValidationErrors(bindingResult);
} else {
T analysis = conversionService.convert(analysisDTO, getAnalysisClass());
analysis.setAuthor(user);
analysis = analysisService.create(analysis);
afterCreate(analysis, analysisDTO);
result = new JsonResult<>(NO_ERROR);
result.setResult(conversionService.convert(analysis, getAnalysisDTOClass()));
}
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method list.
@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
JsonResult<List<D>> result;
IUser user = userService.getByEmail(principal.getName());
if (user == null) {
result = new JsonResult<>(PERMISSION_DENIED);
return result;
}
Iterable<T> analyses = analysisService.list(user, studyId);
result = new JsonResult<>(NO_ERROR);
List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
result.setResult(analysisDTOs);
return result;
}
use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method updateCommonEntityInAnalysis.
@ApiOperation("update common entity in analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities/{fileUuid}", method = PUT)
public JsonResult updateCommonEntityInAnalysis(@PathVariable("analysisId") Long analysisId, @PathVariable("fileUuid") String fileUuid, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws IOException, JMSException, PermissionDeniedException, URISyntaxException {
final IUser user = getUser(principal);
final AnalysisFile analysisFile = analysisService.getAnalysisFile(analysisId, fileUuid);
T analysis = (T) analysisFile.getAnalysis();
final DataReference dataReference = analysisFile.getDataReference();
final DataReferenceDTO entityReference = new DataReferenceDTO(dataReference.getDataNode().getId(), dataReference.getGuid());
final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataReference.getDataNode(), analysisType);
analysisService.findAnalysisFilesByDataReference(analysis, dataReference).forEach(af -> {
analysisService.deleteAnalysisFile(analysis, af);
analysis.getFiles().remove(af);
});
doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
return new JsonResult(NO_ERROR);
}
Aggregations