Search in sources :

Example 1 with DataGridDatabaseException

use of com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException in project metalnx-web by irods-contrib.

the class IRODSAuthenticationProvider method authenticate.

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();
    String password = authentication.getCredentials().toString();
    AuthResponse authResponse;
    UsernamePasswordAuthenticationToken authObject;
    logger.debug("Setting username {}", username);
    try {
        authResponse = this.authenticateAgainstIRODS(username, password);
        // Settings iRODS account
        this.irodsAccount = authResponse.getAuthenticatedIRODSAccount();
        // Retrieving logging user
        User irodsUser = new User();
        try {
            irodsUser = this.irodsAccessObjectFactory.getUserAO(this.irodsAccount).findByName(username);
        } catch (JargonException e) {
            logger.error("Could not find user: " + e.getMessage());
        }
        GrantedAuthority grantedAuth;
        if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) {
            grantedAuth = new IRODSAdminGrantedAuthority();
        } else {
            grantedAuth = new IRODSUserGrantedAuthority();
        }
        // Settings granted authorities
        List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
        grantedAuths.add(grantedAuth);
        // Returning authentication token with the access object factory injected
        authObject = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
        // Creating UserTokenDetails instance for the current authenticated user
        UserTokenDetails userDetails = new UserTokenDetails();
        userDetails.setIrodsAccount(this.irodsAccount);
        userDetails.setUser(this.user);
        // Settings the user details object into the authentication object
        authObject.setDetails(userDetails);
    } catch (TransactionException e) {
        logger.error("Database not responding");
        throw new DataGridDatabaseException(e.getMessage());
    } catch (InvalidUserException | org.irods.jargon.core.exception.AuthenticationException e) {
        logger.error("Could not authenticate user: ", username);
        throw new DataGridAuthenticationException(e.getMessage());
    } catch (JargonException e) {
        logger.error("Server not responding");
        throw new DataGridServerException(e.getMessage());
    }
    return authObject;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthenticationException(org.springframework.security.core.AuthenticationException) JargonException(org.irods.jargon.core.exception.JargonException) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) InvalidUserException(org.irods.jargon.core.exception.InvalidUserException) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthResponse(org.irods.jargon.core.connection.auth.AuthResponse) DataGridDatabaseException(com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException) TransactionException(org.springframework.transaction.TransactionException) DataGridServerException(com.emc.metalnx.core.domain.exceptions.DataGridServerException)

Aggregations

DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)1 DataGridAuthenticationException (com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException)1 DataGridDatabaseException (com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException)1 DataGridServerException (com.emc.metalnx.core.domain.exceptions.DataGridServerException)1 ArrayList (java.util.ArrayList)1 AuthResponse (org.irods.jargon.core.connection.auth.AuthResponse)1 InvalidUserException (org.irods.jargon.core.exception.InvalidUserException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 User (org.irods.jargon.core.pub.domain.User)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 TransactionException (org.springframework.transaction.TransactionException)1