Search in sources :

Example 1 with User

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

the class GroupBookmarkServiceImpl method countTotalGroupBookmarks.

@Override
public Integer countTotalGroupBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, DataNotFoundException, JargonException {
    Integer totalGroupBookmarks = 0;
    if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) {
        logger.error("Could not get groups bookmarks. Username or zone empty");
        return 0;
    }
    logger.info("Get groups bookmarks for {}", user);
    UserAO userAO = adminServices.getUserAO();
    User iRodsUser = userAO.findByName(user);
    if (iRodsUser != null) {
        String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo);
        totalGroupBookmarks = groupBookmarkDao.countGroupBookmarksByGroupsIds(groupIds).intValue();
    }
    return totalGroupBookmarks;
}
Also used : User(org.irods.jargon.core.pub.domain.User) UserAO(org.irods.jargon.core.pub.UserAO)

Example 2 with User

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

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

the class SyncJobs method executeUsersSync.

private void executeUsersSync() {
    try {
        // Gets all users existing in iRODS
        List<User> irodsUsers = this.findAllIRODSUsers();
        HashMap<Long, User> hashMapIRodsUsers = new HashMap<Long, User>();
        for (User user : irodsUsers) {
            if (user.getUserType() != UserTypeEnum.RODS_GROUP) {
                hashMapIRodsUsers.put(Long.valueOf(user.getId()), user);
            }
        }
        // Gets all users existing in our database
        List<DataGridUser> dbUsers = userDao.findAll(DataGridUser.class);
        HashMap<Long, DataGridUser> hashMapDBUsers = new HashMap<Long, DataGridUser>();
        for (DataGridUser dataGridUser : dbUsers) {
            hashMapDBUsers.put(dataGridUser.getDataGridId(), dataGridUser);
        }
        Set<Long> irodsUserIDs = hashMapIRodsUsers.keySet();
        Set<Long> dbDataGridUserIDs = hashMapDBUsers.keySet();
        // action: remove this user from our database
        for (Long id : dbDataGridUserIDs) {
            if (!irodsUserIDs.contains(id)) {
                String usernameDeleted = hashMapDBUsers.get(id).getUsername();
                long userID = hashMapDBUsers.get(id).getId();
                long dataGridID = hashMapDBUsers.get(id).getDataGridId();
                userDao.deleteByDataGridId(id);
                logger.info("[DELETE] User " + usernameDeleted + " (iRODS id: " + userID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
            }
        }
        // action: add this user to our database
        for (Long id : irodsUserIDs) {
            if (!dbDataGridUserIDs.contains(id)) {
                User irodsUserMissingInDB = hashMapIRodsUsers.get(id);
                DataGridUser userMissingInDB = new DataGridUser();
                userMissingInDB.setDataGridId(Long.valueOf(irodsUserMissingInDB.getId()));
                userMissingInDB.setUsername(irodsUserMissingInDB.getName());
                userMissingInDB.setAdditionalInfo(irodsUserMissingInDB.getZone());
                userMissingInDB.setUserType(irodsUserMissingInDB.getUserType().getTextValue());
                userMissingInDB.setEnabled(true);
                userDao.save(userMissingInDB);
                logger.info("[INSERT] User " + userMissingInDB.getUsername() + " (iRODS id: " + userMissingInDB.getDataGridId() + ") " + " was added to database.");
            }
        }
    } catch (Exception e) {
        logger.error("Could not synchronize database and iRODS (users): ", e);
    }
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) HashMap(java.util.HashMap) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException)

Example 4 with User

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

the class GroupServiceImpl method getMemberList.

@Override
public String[] getMemberList(DataGridGroup group) throws DataGridConnectionRefusedException {
    UserGroupAO userGroupAO = irodsServices.getGroupAO();
    try {
        List<User> groupMembers = userGroupAO.listUserGroupMembers(group.getGroupname());
        String[] dataGridIds = new String[groupMembers.size()];
        for (int i = 0; i < groupMembers.size(); i++) {
            dataGridIds[i] = groupMembers.get(i).getId();
        }
        return dataGridIds;
    } catch (JargonException e) {
        logger.error("Could not get members list for group [" + group.getGroupname() + "]: ", e);
    }
    return new String[0];
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO)

Example 5 with User

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

the class SyncJobs method executeGroupSync.

private void executeGroupSync() {
    try {
        // Gets all groups existing in iRODS
        // OBS: we're using User to find Groups because UserGroup doesn't
        // have the get type
        // method and if we don't use such method we'll get a list of users
        // and groups,
        // rather than list containing only groups
        List<User> irodsGroups = this.findAllIRODSUsers();
        HashMap<Long, User> hashMapIRodsGroups = new HashMap<Long, User>();
        for (User group : irodsGroups) {
            if (group.getUserType() == UserTypeEnum.RODS_GROUP) {
                hashMapIRodsGroups.put(Long.valueOf(group.getId()), group);
            }
        }
        // Gets all groups existing in our database
        List<DataGridGroup> dbGroups = groupDao.findAll(DataGridGroup.class);
        HashMap<Long, DataGridGroup> hashMapDBGroups = new HashMap<Long, DataGridGroup>();
        for (DataGridGroup dataGridGroup : dbGroups) {
            hashMapDBGroups.put(dataGridGroup.getDataGridId(), dataGridGroup);
        }
        Set<Long> irodsGroupIDs = hashMapIRodsGroups.keySet();
        Set<Long> dbDataGridGroupIDs = hashMapDBGroups.keySet();
        // action: remove this Group from our database
        for (Long id : dbDataGridGroupIDs) {
            if (!irodsGroupIDs.contains(id)) {
                String groupnameDeleted = hashMapDBGroups.get(id).getGroupname();
                long groupID = hashMapDBGroups.get(id).getId();
                long dataGridID = hashMapDBGroups.get(id).getDataGridId();
                groupDao.deleteByDataGridGroupId(id);
                logger.info("[DELETE] Group " + groupnameDeleted + " (iRODS id: " + groupID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
            }
        }
        // action: add this Group to our database
        for (Long id : irodsGroupIDs) {
            if (!dbDataGridGroupIDs.contains(id)) {
                // users and groups are dealt the same way by iRODS
                User irodsGroupMissingInDB = hashMapIRodsGroups.get(id);
                DataGridGroup groupMissingInDB = new DataGridGroup();
                groupMissingInDB.setDataGridId(Long.valueOf(irodsGroupMissingInDB.getId()));
                groupMissingInDB.setGroupname(irodsGroupMissingInDB.getName());
                groupMissingInDB.setAdditionalInfo(irodsGroupMissingInDB.getZone());
                groupDao.save(groupMissingInDB);
                logger.info("[INSERT] Group " + groupMissingInDB.getGroupname() + " (iRODS id: " + groupMissingInDB.getDataGridId() + ") " + " was added to database");
            }
        }
    } catch (Exception e) {
        logger.error("Could not synchronize database and iRODS (Groups): ", e);
    }
}
Also used : DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) User(org.irods.jargon.core.pub.domain.User) HashMap(java.util.HashMap) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) JargonException(org.irods.jargon.core.exception.JargonException)

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