Search in sources :

Example 1 with UserFilePermission

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

the class FilePropertyServiceImpl method populateVisibilityForCurrentUser.

private void populateVisibilityForCurrentUser(List<DataGridCollectionAndDataObject> objectList) throws DataGridConnectionRefusedException {
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    String currentUser = getLoggedDataGridUser().getUsername();
    for (DataGridCollectionAndDataObject obj : objectList) {
        List<UserFilePermission> permissions = null;
        try {
            if (obj.isCollection()) {
                permissions = collectionAO.listPermissionsForCollection(obj.getPath());
            } else {
                permissions = dataObjectAO.listPermissionsForDataObject(obj.getPath());
            }
        } catch (JargonException e) {
            logger.error("Could not get permission list for object {}", obj.getPath(), e);
        }
        obj.setVisibleToCurrentUser(false);
        if (permissions != null) {
            for (UserFilePermission permission : permissions) {
                if (permission.getUserName().compareTo(currentUser) == 0) {
                    obj.setVisibleToCurrentUser(true);
                    break;
                }
            }
        }
    }
}
Also used : UserFilePermission(org.irods.jargon.core.pub.domain.UserFilePermission) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 2 with UserFilePermission

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

the class PermissionsServiceImpl method mapListToListDataGridFilePermission.

/**
 * Maps a list of UserFilePermission instances to a list of DataGridFilePermission
 * objects.
 *
 * @param filePermissionList
 * @return list of instances of {@link DataGridFilePermission}
 */
private List<DataGridFilePermission> mapListToListDataGridFilePermission(List<UserFilePermission> filePermissionList) {
    logger.debug("Mapping list of UserFilePermissions to List of DataGridFilePermission");
    List<DataGridFilePermission> dgFilePermissionList = new ArrayList<DataGridFilePermission>();
    for (UserFilePermission ufp : filePermissionList) {
        DataGridFilePermission dgfp = mapToDataGridFilePermission(ufp);
        dgFilePermissionList.add(dgfp);
    }
    return dgFilePermissionList;
}
Also used : UserFilePermission(org.irods.jargon.core.pub.domain.UserFilePermission)

Example 3 with UserFilePermission

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

the class PermissionsServiceImpl method getFilePermissionListForObject.

/**
 * Gets the list of file permissions on the requested object for a particular user. The object
 * can be a collection as a single data object.
 *
 * @param path     the path to the object
 * @param username user name to get the permissions on the given path. If no user name is required,
 *                 an empty String or null should be provided
 * @return list of {@link UserFilePermission}
 * @throws FileNotFoundException
 * @throws JargonException
 * @throws DataGridConnectionRefusedException
 */
private List<UserFilePermission> getFilePermissionListForObject(String path, String username) throws DataGridConnectionRefusedException, JargonException {
    Object obj = irodsServices.getCollectionAndDataObjectListAndSearchAO().getFullObjectForType(path);
    List<UserFilePermission> filePermissionList = new ArrayList<UserFilePermission>();
    List<UserFilePermission> dataGridfilePermissionList = null;
    // If the object is a collection
    if (obj instanceof Collection) {
        logger.debug("Getting permission info for collection {}", path);
        dataGridfilePermissionList = irodsServices.getCollectionAO().listPermissionsForCollection(path);
    } else // If the object is a data object
    {
        logger.debug("Getting permission info for data object {}", path);
        dataGridfilePermissionList = irodsServices.getDataObjectAO().listPermissionsForDataObject(path);
    }
    // as the parameter
    if (username != null && !username.isEmpty()) {
        for (UserFilePermission userFilePermission : dataGridfilePermissionList) {
            if (userFilePermission.getUserName().equalsIgnoreCase(username)) {
                filePermissionList.add(userFilePermission);
            }
        }
    } else {
        filePermissionList = dataGridfilePermissionList;
    }
    return filePermissionList;
}
Also used : UserFilePermission(org.irods.jargon.core.pub.domain.UserFilePermission) Collection(org.irods.jargon.core.pub.domain.Collection)

Example 4 with UserFilePermission

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

UserFilePermission (org.irods.jargon.core.pub.domain.UserFilePermission)4 JargonException (org.irods.jargon.core.exception.JargonException)2 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)1 CollectionAO (org.irods.jargon.core.pub.CollectionAO)1 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)1 Collection (org.irods.jargon.core.pub.domain.Collection)1 UserGroup (org.irods.jargon.core.pub.domain.UserGroup)1