Search in sources :

Example 1 with AuthResponse

use of org.irods.jargon.core.connection.auth.AuthResponse 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)

Example 2 with AuthResponse

use of org.irods.jargon.core.connection.auth.AuthResponse in project metalnx-web by irods-contrib.

the class SyncJobs method authenticateIRODSAccount.

private void authenticateIRODSAccount() throws JargonException {
    AuthResponse authResponse = null;
    if (this.irodsAccount == null) {
        // Getting iRODS protocol set
        IRODSAccount tempAccount = IRODSAccount.instance(irodsHost, Integer.parseInt(irodsPort), irodsJobUser, irodsJobPassword, "", irodsZone, "demoResc");
        tempAccount.setAuthenticationScheme(AuthScheme.findTypeByString(irodsAuthScheme));
        authResponse = irodsAccessObjectFactory.authenticateIRODSAccount(tempAccount);
        if (authResponse.isSuccessful()) {
            this.irodsAccount = authResponse.getAuthenticatedIRODSAccount();
        }
    }
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) AuthResponse(org.irods.jargon.core.connection.auth.AuthResponse)

Example 3 with AuthResponse

use of org.irods.jargon.core.connection.auth.AuthResponse in project metalnx-web by irods-contrib.

the class AdminServicesImpl method authenticateIRODSAccount.

private void authenticateIRODSAccount() throws JargonException {
    String host = configService.getIrodsHost();
    int port = Integer.parseInt(configService.getIrodsPort());
    String zone = configService.getIrodsZone();
    String user = configService.getIrodsJobUser();
    String password = configService.getIrodsJobPassword();
    String authScheme = configService.getIrodsAuthScheme();
    String resc = "demoResc";
    String homeDir = "";
    if (irodsAccount == null) {
        IRODSAccount tempAccount = IRODSAccount.instance(host, port, user, password, homeDir, zone, resc);
        tempAccount.setAuthenticationScheme(AuthScheme.findTypeByString(authScheme));
        AuthResponse authResponse = irodsAccessObjectFactory.authenticateIRODSAccount(tempAccount);
        if (authResponse.isSuccessful()) {
            irodsAccount = authResponse.getAuthenticatedIRODSAccount();
        }
    }
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) AuthResponse(org.irods.jargon.core.connection.auth.AuthResponse)

Example 4 with AuthResponse

use of org.irods.jargon.core.connection.auth.AuthResponse in project metalnx-web by irods-contrib.

the class IRODSAuthenticationProvider method authenticateAgainstIRODS.

private AuthResponse authenticateAgainstIRODS(String username, String password) throws JargonException {
    if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
        throw new DataGridAuthenticationException("Username or password invalid: null or empty value(s) provided");
    } else if (username.equalsIgnoreCase(IRODS_ANONYMOUS_ACCOUNT)) {
        throw new DataGridAuthenticationException("Cannot log in as anonymous");
    }
    AuthResponse authResponse;
    // Getting iRODS protocol set
    logger.debug("Creating IRODSAccount object.");
    this.irodsAccount = IRODSAccount.instance(this.irodsHost, Integer.parseInt(this.irodsPort), username, password, "", this.irodsZoneName, "demoResc");
    this.irodsAccount.setAuthenticationScheme(AuthScheme.findTypeByString(this.irodsAuthScheme));
    logger.debug("Done.");
    logger.debug("Authenticating IRODSAccount:\n\tusername: {}\n\tpassword: ***********\n\tirodsHost: {}\n\tirodsZone: {}", username, this.irodsHost, this.irodsZoneName);
    authResponse = this.irodsAccessObjectFactory.authenticateIRODSAccount(this.irodsAccount);
    logger.debug("Done.");
    if (authResponse.isSuccessful()) {
        if (StringUtils.isEmpty(authResponse.getAuthMessage())) {
            logger.debug("AuthMessage: {}", authResponse.getAuthMessage());
        }
        // Settings iRODS account
        this.irodsAccount = authResponse.getAuthenticatingIRODSAccount();
        // Retrieving logging user
        UserAO userAO = this.irodsAccessObjectFactory.getUserAO(this.irodsAccount);
        User irodsUser = userAO.findByName(username);
        // If the user is found and has administrator permissions
        if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN) || irodsUser.getUserType().equals(UserTypeEnum.RODS_USER)) {
            // If the user is not yet persisted in our database
            DataGridUser user = this.userDao.findByUsernameAndZone(irodsUser.getName(), irodsUser.getZone());
            if (user == null) {
                user = new DataGridUser();
                user.setUsername(irodsUser.getName());
                user.setAdditionalInfo(irodsUser.getZone());
                user.setDataGridId(Long.parseLong(irodsUser.getId()));
                user.setEnabled(true);
                user.setFirstName("");
                user.setLastName("");
                if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) {
                    user.setUserType(UserTypeEnum.RODS_ADMIN.getTextValue());
                } else {
                    user.setUserType(UserTypeEnum.RODS_USER.getTextValue());
                }
                this.userDao.save(user);
            }
            this.user = user;
        }
    }
    return authResponse;
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) UserAO(org.irods.jargon.core.pub.UserAO) DataGridAuthenticationException(com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException) AuthResponse(org.irods.jargon.core.connection.auth.AuthResponse)

Aggregations

AuthResponse (org.irods.jargon.core.connection.auth.AuthResponse)4 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)2 DataGridAuthenticationException (com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException)2 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)2 User (org.irods.jargon.core.pub.domain.User)2 DataGridDatabaseException (com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException)1 DataGridServerException (com.emc.metalnx.core.domain.exceptions.DataGridServerException)1 ArrayList (java.util.ArrayList)1 InvalidUserException (org.irods.jargon.core.exception.InvalidUserException)1 JargonException (org.irods.jargon.core.exception.JargonException)1 UserAO (org.irods.jargon.core.pub.UserAO)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