Search in sources :

Example 11 with User

use of org.irods.jargon.core.pub.domain.User 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

User (org.irods.jargon.core.pub.domain.User)11 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)8 JargonException (org.irods.jargon.core.exception.JargonException)6 UserAO (org.irods.jargon.core.pub.UserAO)6 ArrayList (java.util.ArrayList)3 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)2 DataGridAuthenticationException (com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException)2 HashMap (java.util.HashMap)2 AuthResponse (org.irods.jargon.core.connection.auth.AuthResponse)2 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)2 DataGridGroupBookmark (com.emc.metalnx.core.domain.entity.DataGridGroupBookmark)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridDatabaseException (com.emc.metalnx.core.domain.exceptions.DataGridDatabaseException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 DataGridServerException (com.emc.metalnx.core.domain.exceptions.DataGridServerException)1 DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)1 InvalidUserException (org.irods.jargon.core.exception.InvalidUserException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1