Search in sources :

Example 6 with UserAO

use of org.irods.jargon.core.pub.UserAO in project metalnx-web by irods-contrib.

the class UserServiceImpl method modifyUser.

@Override
public boolean modifyUser(DataGridUser modifyUser) throws DataGridConnectionRefusedException {
    UserAO userAO = irodsServices.getUserAO();
    try {
        User iRodsUser = userAO.findById(String.valueOf(modifyUser.getDataGridId()));
        boolean iRodsFieldsModified = false;
        // check which fields were modified (iRODS)
        if (iRodsUser.getZone().compareTo(modifyUser.getAdditionalInfo()) != 0) {
            iRodsUser.setZone(modifyUser.getAdditionalInfo());
            iRodsFieldsModified = true;
        }
        if (!iRodsUser.getUserType().getTextValue().equals(modifyUser.getUserType())) {
            if (modifyUser.getUserType().compareTo(UserTypeEnum.RODS_ADMIN.getTextValue()) == 0) {
                iRodsUser.setUserType(UserTypeEnum.RODS_ADMIN);
            } else {
                iRodsUser.setUserType(UserTypeEnum.RODS_USER);
            }
            iRodsFieldsModified = true;
        }
        // updating user in iRODS if any field was modified
        if (iRodsFieldsModified) {
            userAO.updateUser(iRodsUser);
        }
        DataGridUser applicationUser = userDao.findByUsernameAndZone(modifyUser.getUsername(), modifyUser.getAdditionalInfo());
        // check which fields were modified (our database)
        if (applicationUser.getAdditionalInfo() == null || applicationUser.getAdditionalInfo().compareTo(modifyUser.getAdditionalInfo()) != 0) {
            applicationUser.setAdditionalInfo(modifyUser.getAdditionalInfo());
        }
        if (applicationUser.getFirstName() == null || applicationUser.getFirstName().compareTo(modifyUser.getFirstName()) != 0) {
            applicationUser.setFirstName(modifyUser.getFirstName());
        }
        if (applicationUser.getLastName() == null || applicationUser.getLastName().compareTo(modifyUser.getLastName()) != 0) {
            applicationUser.setLastName(modifyUser.getLastName());
        }
        if (applicationUser.getEmail() == null || applicationUser.getEmail().compareTo(modifyUser.getEmail()) != 0) {
            applicationUser.setEmail(modifyUser.getEmail());
        }
        if (applicationUser.getCompany() == null || applicationUser.getCompany().compareTo(modifyUser.getCompany()) != 0) {
            applicationUser.setCompany(modifyUser.getCompany());
        }
        if (applicationUser.getDepartment() == null || applicationUser.getDepartment().compareTo(modifyUser.getDepartment()) != 0) {
            applicationUser.setDepartment(modifyUser.getDepartment());
        }
        applicationUser.setUserProfile(modifyUser.getUserProfile());
        applicationUser.setLocale(modifyUser.getLocale());
        applicationUser.setOrganizationalRole(modifyUser.getOrganizationalRole());
        applicationUser.setUserType(modifyUser.getUserType());
        applicationUser.setForceFileOverwriting(modifyUser.isForceFileOverwriting());
        applicationUser.setAdvanceView(modifyUser.isAdvancedView());
        userDao.merge(applicationUser);
        // Changing password if a new password is set
        String newPassword = modifyUser.getPassword();
        if (newPassword != null && !newPassword.isEmpty()) {
            userAO.changeAUserPasswordByAnAdmin(modifyUser.getUsername(), newPassword);
        }
        return true;
    } catch (JargonException e) {
        e.printStackTrace();
    }
    return false;
}
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) JargonException(org.irods.jargon.core.exception.JargonException) UserAO(org.irods.jargon.core.pub.UserAO)

Example 7 with UserAO

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

UserAO (org.irods.jargon.core.pub.UserAO)7 User (org.irods.jargon.core.pub.domain.User)6 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)4 ArrayList (java.util.ArrayList)2 JargonException (org.irods.jargon.core.exception.JargonException)2 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)1 DataGridGroupBookmark (com.emc.metalnx.core.domain.entity.DataGridGroupBookmark)1 DataGridAuthenticationException (com.emc.metalnx.core.domain.exceptions.DataGridAuthenticationException)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 AuthResponse (org.irods.jargon.core.connection.auth.AuthResponse)1