use of com.odysseusinc.arachne.commons.api.v1.dto.CommonAuthenticationResponse in project ArachneCentralAPI by OHDSI.
the class BaseAuthenticationController method login.
@ApiOperation("Login with specified credentials.")
@RequestMapping(value = "/api/v1/auth/login", method = RequestMethod.POST)
public JsonResult<CommonAuthenticationResponse> login(@RequestBody CommonAuthenticationRequest authenticationRequest) throws AuthenticationException {
JsonResult<CommonAuthenticationResponse> jsonResult;
String username = authenticationRequest.getUsername();
try {
checkIfUserBlocked(username);
Authentication authentication = authenticate(authenticationRequest);
SecurityContextHolder.getContext().setAuthentication(authentication);
String token = this.tokenUtils.generateToken(username);
CommonAuthenticationResponse authenticationResponse = new CommonAuthenticationResponse(token);
jsonResult = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR, authenticationResponse);
loginAttemptService.loginSucceeded(username);
} catch (Exception ex) {
jsonResult = getJsonResultForUnsuccessfulLogin(username, ex);
}
// Return the token
return jsonResult;
}
Aggregations