Search in sources :

Example 1 with UserInfo

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;
    }
}
Also used : UserInfo(org.ohdsi.authenticator.model.UserInfo) UsernamePasswordCredentials(org.pac4j.core.credentials.UsernamePasswordCredentials) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserInfo

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;
}
Also used : UserInfo(org.ohdsi.authenticator.model.UserInfo) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) NoDefaultTenantException(com.odysseusinc.arachne.portal.exception.NoDefaultTenantException) 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) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException) IOException(java.io.IOException) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) PasswordValidationException(com.odysseusinc.arachne.portal.exception.PasswordValidationException) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

UserInfo (org.ohdsi.authenticator.model.UserInfo)2 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 NoDefaultTenantException (com.odysseusinc.arachne.portal.exception.NoDefaultTenantException)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 UsernamePasswordCredentials (org.pac4j.core.credentials.UsernamePasswordCredentials)1 AuthenticationServiceException (org.springframework.security.authentication.AuthenticationServiceException)1 BadCredentialsException (org.springframework.security.authentication.BadCredentialsException)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1