use of org.ohdsi.authenticator.model.UserInfo in project ArachneCentralAPI by OHDSI.
the class AuthenticationServiceImpl method authenticateAndGetAuthToken.
@Transactional(rollbackFor = Exception.class, readOnly = false)
public String authenticateAndGetAuthToken(CommonAuthenticationRequest authenticationRequest) {
String username = authenticationRequest.getUsername();
String password = authenticationRequest.getPassword();
try {
UserInfo userInfo = authenticator.authenticate(authMethodName, new UsernamePasswordCredentials(username, password));
authenticate(userInfo.getUsername(), password);
return userInfo.getToken();
} catch (Exception e) {
SecurityContextHolder.clearContext();
throw e;
}
}
use of org.ohdsi.authenticator.model.UserInfo in project ArachneCentralAPI by OHDSI.
the class BaseAuthenticationController method refresh.
@ApiOperation("Refresh session token.")
@RequestMapping(value = "/api/v1/auth/refresh", method = RequestMethod.POST)
public JsonResult<String> refresh(HttpServletRequest request) {
JsonResult<String> result;
try {
String token = request.getHeader(this.tokenHeader);
UserInfo userInfo = authenticator.refreshToken(token);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
if (userInfo == null || userInfo.getToken() == null) {
throw new AuthenticationServiceException("Cannot refresh token user info is either null or does not contain token");
}
result.setResult(userInfo.getToken());
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
result = new JsonResult<>(JsonResult.ErrorCode.UNAUTHORIZED);
}
return result;
}
Aggregations