Search in sources :

Example 46 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser 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)

Example 47 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class UserDaoImpl method findByDataGridId.

@Override
public DataGridUser findByDataGridId(long id) {
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where data_grid_id=(:id)");
    q.setParameter("id", id);
    List<DataGridUser> users = q.list();
    return users.size() > 0 ? users.get(0) : null;
}
Also used : Query(org.hibernate.Query) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser)

Example 48 with DataGridUser

use of com.emc.metalnx.core.domain.entity.DataGridUser in project metalnx-web by irods-contrib.

the class UserDaoImpl method findByUsername.

@Override
public List<DataGridUser> findByUsername(String username) {
    List<DataGridUser> users = null;
    Query q = sessionFactory.getCurrentSession().createQuery("from DataGridUser where username = :username");
    q.setString("username", username);
    users = q.list();
    return users;
}
Also used : Query(org.hibernate.Query) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser)

Aggregations

DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)48 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)28 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 JargonException (org.irods.jargon.core.exception.JargonException)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)5 User (org.irods.jargon.core.pub.domain.User)5 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)4 HashMap (java.util.HashMap)4 Query (org.hibernate.Query)4 UserAO (org.irods.jargon.core.pub.UserAO)4 Authentication (org.springframework.security.core.Authentication)4 UserProfile (com.emc.metalnx.core.domain.entity.UserProfile)3 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)2 DataGridUserFavorite (com.emc.metalnx.core.domain.entity.DataGridUserFavorite)2 URLMap (com.emc.metalnx.modelattribute.enums.URLMap)2 GroupForm (com.emc.metalnx.modelattribute.group.GroupForm)2