Search in sources :

Example 1 with DataGridFilePermission

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

the class PermissionsController method getPermissionDetails.

/**
 * Gives permission details related to a collection or file that is passed as a
 * parameter
 *
 * @param model
 * @param path
 * @return
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 * @throws FileNotFoundException
 */
@RequestMapping(value = "/getPermissionDetails/", method = RequestMethod.POST)
public String getPermissionDetails(final Model model, @RequestParam("path") final String path) throws DataGridConnectionRefusedException {
    logger.debug("Getting permission info for {}", path);
    DataGridCollectionAndDataObject obj = null;
    List<DataGridFilePermission> permissions;
    List<DataGridGroupPermission> groupPermissions;
    List<DataGridUserPermission> userPermissions;
    List<DataGridGroupBookmark> bookmarks;
    List<DataGridUserBookmark> userBookmarks;
    Set<String> groupsWithBookmarks;
    Set<String> usersWithBookmarks;
    boolean userCanModify = false;
    boolean isCollection = false;
    try {
        loggedUser = luu.getLoggedDataGridUser();
        permissions = ps.getPathPermissionDetails(path);
        groupPermissions = ps.getGroupsWithPermissions(permissions);
        userPermissions = ps.getUsersWithPermissions(permissions);
        bookmarks = gBMS.findBookmarksOnPath(path);
        userBookmarks = uBMS.findBookmarksOnPath(path);
        userCanModify = loggedUser.isAdmin() || ps.canLoggedUserModifyPermissionOnPath(path);
        groupsWithBookmarks = new HashSet<>();
        for (DataGridGroupBookmark bookmark : bookmarks) {
            groupsWithBookmarks.add(bookmark.getGroup().getGroupname());
        }
        usersWithBookmarks = new HashSet<>();
        for (DataGridUserBookmark userBookmark : userBookmarks) {
            usersWithBookmarks.add(userBookmark.getUser().getUsername());
        }
        obj = cs.findByName(path);
        ps.resolveMostPermissiveAccessForUser(obj, loggedUser);
    } catch (Exception e) {
        logger.error("Could not get permission details {}: {}", path, e.getMessage());
        groupPermissions = new ArrayList<>();
        userPermissions = new ArrayList<>();
        groupsWithBookmarks = new HashSet<>();
        usersWithBookmarks = new HashSet<>();
    }
    model.addAttribute("usersWithBookmarks", usersWithBookmarks);
    model.addAttribute("groupsWithBookmark", groupsWithBookmarks);
    model.addAttribute("groupPermissions", groupPermissions);
    model.addAttribute("userPermissions", userPermissions);
    model.addAttribute("userCanModify", userCanModify);
    model.addAttribute("permissions", PERMISSIONS);
    model.addAttribute("permissionsWithoutNone", PERMISSIONS_WITHOUT_NONE);
    model.addAttribute("collectionAndDataObject", obj);
    model.addAttribute("isCollection", isCollection);
    model.addAttribute("permissionOnCurrentPath", cs.getPermissionsForPath(path));
    model.addAttribute("permissionFlag", true);
    System.out.println("permissionOnCurrentPath =======" + cs.getPermissionsForPath(path));
    System.out.println("------Permission Conroller - /getPermissionDetail/ ends------");
    return "permissions/permissionDetails :: permissionDetails";
}
Also used : DataGridGroupPermission(com.emc.metalnx.core.domain.entity.DataGridGroupPermission) DataGridUserPermission(com.emc.metalnx.core.domain.entity.DataGridUserPermission) DataGridGroupBookmark(com.emc.metalnx.core.domain.entity.DataGridGroupBookmark) ArrayList(java.util.ArrayList) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) DataGridFilePermission(com.emc.metalnx.core.domain.entity.DataGridFilePermission) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DataGridFilePermission

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

the class CollectionServiceImpl method listCollectionsWithPermissionsForEntity.

/**
 * Auxiliary method that filters the directories with the specified permission
 * level for the given entity, that can be an user or a group
 *
 * @param path
 *            The path for which we would like to list the objects with
 *            permissions
 * @param entityName
 *            The entity name
 * @param permissionType
 *            The permission stype
 * @param entityType
 *            The entity type that can be user or group
 * @return
 * @throws DataGridConnectionRefusedException
 */
private Set<String> listCollectionsWithPermissionsForEntity(String path, String entityName, FilePermissionEnum permissionType, String entityType) throws DataGridConnectionRefusedException {
    logger.info("listCollectionsWithPermissionsForEntity()");
    Set<String> collections = new HashSet<String>();
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    try {
        List<CollectionAndDataObjectListingEntry> collList = collectionAndDataObjectListAndSearchAO.listDataObjectsAndCollectionsUnderPath(path);
        logger.info("Getting permissions and bookmarks for path {}", path);
        for (CollectionAndDataObjectListingEntry collEntry : collList) {
            String filePath = "";
            if (collEntry.isCollection()) {
                filePath = collEntry.getPathOrName();
            } else {
                filePath = collEntry.getParentPath() + IRODS_PATH_SEPARATOR + collEntry.getPathOrName();
                if (collEntry.getParentPath().compareTo(IRODS_PATH_SEPARATOR) == 0) {
                    filePath = collEntry.getParentPath() + collEntry.getPathOrName();
                }
            }
            List<DataGridFilePermission> permissions = permissionsService.getPathPermissionDetails(filePath, entityName);
            // Deciding whether we should get permissions for users or groups
            if (entityType.compareTo("user") == 0) {
                // Filtering permissions for users
                List<DataGridUserPermission> userPermissions = permissionsService.getUsersWithPermissions(permissions);
                // Adding collections with permissions into the result list
                for (DataGridUserPermission dataGridUserPermission : userPermissions) {
                    if (dataGridUserPermission.getPermission().equalsIgnoreCase(permissionType.name())) {
                        collections.add(filePath);
                    }
                }
            } else {
                // Filtering permissions for groups
                List<DataGridGroupPermission> groupPermissions = permissionsService.getGroupsWithPermissions(permissions);
                // Adding collections with permissions into the result list
                for (DataGridGroupPermission dataGridGroupPermission : groupPermissions) {
                    if (dataGridGroupPermission.getPermission().equalsIgnoreCase(permissionType.name())) {
                        collections.add(filePath);
                    }
                }
            }
        }
    } catch (JargonException e) {
        logger.error("Could not get permissions: ", e);
    }
    return collections;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) DataGridUserPermission(com.emc.metalnx.core.domain.entity.DataGridUserPermission) DataGridGroupPermission(com.emc.metalnx.core.domain.entity.DataGridGroupPermission) JargonException(org.irods.jargon.core.exception.JargonException) CollectionAndDataObjectListingEntry(org.irods.jargon.core.query.CollectionAndDataObjectListingEntry) DataGridFilePermission(com.emc.metalnx.core.domain.entity.DataGridFilePermission) HashSet(java.util.HashSet)

Aggregations

DataGridFilePermission (com.emc.metalnx.core.domain.entity.DataGridFilePermission)2 DataGridGroupPermission (com.emc.metalnx.core.domain.entity.DataGridGroupPermission)2 DataGridUserPermission (com.emc.metalnx.core.domain.entity.DataGridUserPermission)2 HashSet (java.util.HashSet)2 JargonException (org.irods.jargon.core.exception.JargonException)2 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)1 DataGridGroupBookmark (com.emc.metalnx.core.domain.entity.DataGridGroupBookmark)1 DataGridUserBookmark (com.emc.metalnx.core.domain.entity.DataGridUserBookmark)1 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)1 ArrayList (java.util.ArrayList)1 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)1 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)1 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1