Search in sources :

Example 1 with UserGroup

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

the class UserServiceImpl method updateGroupList.

@Override
public boolean updateGroupList(DataGridUser user, List<DataGridGroup> groups) throws DataGridConnectionRefusedException {
    UserGroupAO groupAO = irodsServices.getGroupAO();
    try {
        // List current groups for user
        List<UserGroup> groupsFromIrods = groupAO.findUserGroupsForUser(user.getUsername());
        // Building set with iRODS IDs already on this group
        HashMap<Long, UserGroup> idsFromIrods = new HashMap<Long, UserGroup>();
        for (UserGroup groupFromIrods : groupsFromIrods) {
            idsFromIrods.put(Long.valueOf(groupFromIrods.getUserGroupId()), groupFromIrods);
        }
        // Building set with iRODS IDs coming from UI
        HashMap<Long, DataGridGroup> idsFromUi = new HashMap<Long, DataGridGroup>();
        for (DataGridGroup groupFromUi : groups) {
            idsFromUi.put(groupFromUi.getDataGridId(), groupFromUi);
        }
        // Resolving differences from UI to iRODS
        Set<Long> keysFromUi = idsFromUi.keySet();
        Set<Long> keysFromIrods = idsFromIrods.keySet();
        // Committing changes to iRODS
        for (Long dataGridId : keysFromUi) {
            if (!keysFromIrods.contains(dataGridId)) {
                groupService.attachUserToGroup(user, idsFromUi.get(dataGridId));
            }
        }
        for (Long dataGridId : keysFromIrods) {
            if (!keysFromUi.contains(dataGridId)) {
                DataGridGroup group = new DataGridGroup();
                group.setGroupname(idsFromIrods.get(dataGridId).getUserGroupName());
                if (group.getGroupname().compareTo("public") != 0) {
                    groupService.removeUserFromGroup(user, group);
                }
            }
        }
        return true;
    } catch (Exception e) {
        logger.info("Could not update [" + user.getUsername() + "] group list: ", e);
    }
    return false;
}
Also used : HashMap(java.util.HashMap) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Example 2 with UserGroup

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

the class UserServiceImpl method getGroupIdsForUser.

@Override
public String[] getGroupIdsForUser(DataGridUser user) throws DataGridConnectionRefusedException {
    UserGroupAO userGroupAO = irodsServices.getGroupAO();
    try {
        // Getting list of groups the user belongs to.
        List<UserGroup> groups = userGroupAO.findUserGroupsForUser(user.getUsername());
        // Building Data Grid IDs list
        String[] ids = new String[groups.size()];
        for (int i = 0; i < groups.size(); i++) {
            ids[i] = groups.get(i).getUserGroupId();
        }
        // Returning results
        return ids;
    } catch (JargonException e) {
        logger.error("Could not find group list for user [" + user.getUsername() + "], ", e);
    }
    // If something goes wrong, return empty list.
    return new String[0];
}
Also used : JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Example 3 with UserGroup

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

the class GroupServiceImpl method createGroup.

@Override
public boolean createGroup(DataGridGroup newGroup, List<DataGridUser> usersToBeAttached) throws DataGridConnectionRefusedException {
    UserGroupAO groupAO = irodsServices.getGroupAO();
    // Translating to iRODS model format
    UserGroup irodsGroup = new UserGroup();
    irodsGroup.setUserGroupName(newGroup.getGroupname());
    irodsGroup.setZone(newGroup.getAdditionalInfo());
    try {
        irodsGroup.setUserGroupName(newGroup.getGroupname());
        irodsGroup.setZone(newGroup.getAdditionalInfo());
        // creating group in iRODS
        groupAO.addUserGroup(irodsGroup);
        // Recovering the recently created group to get the data grid id.
        irodsGroup = groupAO.findByName(irodsGroup.getUserGroupName());
        newGroup.setDataGridId(Long.parseLong(irodsGroup.getUserGroupId()));
        // Persisting the new group into our database
        groupDao.save(newGroup);
        // attaching users to this group
        updateMemberList(newGroup, usersToBeAttached);
        return true;
    } catch (DuplicateDataException e) {
        logger.error("UserGroup " + newGroup.getGroupname() + " already exists: ", e);
    } catch (JargonException e) {
        logger.error("Could not execute createGroup() on UserGroupAO class: ", e);
    }
    return false;
}
Also used : DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroupAO(org.irods.jargon.core.pub.UserGroupAO) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Example 4 with UserGroup

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

the class PermissionsServiceImpl method resolveMostPermissiveAccessForUser.

@Override
public void resolveMostPermissiveAccessForUser(DataGridCollectionAndDataObject obj, DataGridUser user) throws DataGridException {
    if (obj == null || user == null)
        return;
    List<UserGroup> userGroups;
    List<UserFilePermission> acl;
    try {
        userGroups = irodsServices.getGroupAO().findUserGroupsForUser(user.getUsername());
        acl = getFilePermissionListForObject(obj.getPath());
    } catch (JargonException e) {
        throw new DataGridException();
    }
    // Building set containing group names for current user
    Set<String> userGroupsSet = new HashSet<>();
    for (UserGroup g : userGroups) {
        userGroupsSet.add(g.getUserGroupName());
    }
    // Instantiating comparison matrix for permissions
    List<String> permissions = new ArrayList<>();
    permissions.add("NONE");
    permissions.add("READ");
    permissions.add("WRITE");
    permissions.add("OWN");
    String resultingPermission = "NONE";
    for (UserFilePermission perm : acl) {
        String permUserName = perm.getUserName();
        // Checking if current permission is related to logged user
        if (permUserName.compareTo(user.getUsername()) == 0 || userGroupsSet.contains(permUserName)) {
            String permissionName = perm.getFilePermissionEnum().name();
            int userOrGroupPerm = permissions.indexOf(permissionName);
            int currentPermission = permissions.indexOf(resultingPermission);
            if (userOrGroupPerm > currentPermission) {
                resultingPermission = permissionName;
            }
        }
        if (resultingPermission.compareToIgnoreCase("OWN") == 0) {
            break;
        }
    }
    obj.setMostPermissiveAccessForCurrentUser(resultingPermission.toLowerCase());
}
Also used : UserFilePermission(org.irods.jargon.core.pub.domain.UserFilePermission) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Aggregations

JargonException (org.irods.jargon.core.exception.JargonException)4 UserGroup (org.irods.jargon.core.pub.domain.UserGroup)4 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)3 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 HashMap (java.util.HashMap)1 DuplicateDataException (org.irods.jargon.core.exception.DuplicateDataException)1 UserFilePermission (org.irods.jargon.core.pub.domain.UserFilePermission)1