Search in sources :

Example 1 with CommonAuthenticationResponse

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;
}
Also used : CommonAuthenticationResponse(com.odysseusinc.arachne.commons.api.v1.dto.CommonAuthenticationResponse) Authentication(org.springframework.security.core.Authentication) SolrServerException(org.apache.solr.client.solrj.SolrServerException) AuthenticationException(org.springframework.security.core.AuthenticationException) UserNotActivatedException(com.odysseusinc.arachne.portal.exception.UserNotActivatedException) UserNotFoundException(com.odysseusinc.arachne.portal.exception.UserNotFoundException) IOException(java.io.IOException) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) PasswordValidationException(com.odysseusinc.arachne.portal.exception.PasswordValidationException) MailSendException(org.springframework.mail.MailSendException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CommonAuthenticationResponse (com.odysseusinc.arachne.commons.api.v1.dto.CommonAuthenticationResponse)1 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)1 PasswordValidationException (com.odysseusinc.arachne.portal.exception.PasswordValidationException)1 PermissionDeniedException (com.odysseusinc.arachne.portal.exception.PermissionDeniedException)1 UserNotActivatedException (com.odysseusinc.arachne.portal.exception.UserNotActivatedException)1 UserNotFoundException (com.odysseusinc.arachne.portal.exception.UserNotFoundException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 IOException (java.io.IOException)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 MailSendException (org.springframework.mail.MailSendException)1 Authentication (org.springframework.security.core.Authentication)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1