Search in sources :

Example 6 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method checkWritePrivileges.

/**
 * Ensures that the user has write privileges for a path. That includes checking lookup
 * privileges. The file must exist for the call to succeed.
 *
 * @param user The user ID
 * @param surl The path to the file
 * @throws SRMAuthorizationException if the user lacks write privileges for this path.
 * @throws SRMInvalidPathException   if the file does not exist
 * @throws SRMInternalErrorException for transient errors
 * @throws SRMException              for other errors
 */
private void checkWritePrivileges(SRMUser user, URI surl) throws SRMException {
    try {
        DcacheUser dCacheUser = asDcacheUser(user);
        FsPath path = getPath(surl);
        PnfsHandler handler = new PnfsHandler(_pnfs, dCacheUser.getSubject(), dCacheUser.getRestriction());
        handler.getFileAttributes(path.toString(), EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.WRITE_DATA), false);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("Parent path does not exist", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        throw new SRMException(String.format("Operation failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMException(org.dcache.srm.SRMException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PnfsHandler(diskCacheV111.util.PnfsHandler) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 7 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method setFileMetaData.

@Override
public void setFileMetaData(SRMUser abstractUser, URI surl, FileMetaData fmd) throws SRMException {
    DcacheUser user = asDcacheUser(abstractUser);
    FsPath path = getPath(surl);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        if (!(fmd instanceof DcacheFileMetaData)) {
            throw new SRMException("Storage.setFileMetaData: " + "metadata in not dCacheMetaData");
        }
        int mode = ((DcacheFileMetaData) fmd).permMode;
        handler.setFileAttributes(path, FileAttributes.ofMode(mode));
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("PnfsManager is unavailable: " + e.getMessage(), e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        throw new SRMException("SetFileMetaData failed for " + fmd.SURL + "; return code=" + e.getRc() + " reason=" + e.getMessage());
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 8 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method listDirectory.

@Override
public List<URI> listDirectory(SRMUser user, URI surl, FileMetaData fileMetaData) throws SRMException {
    final FsPath path = getPath(surl);
    final List<URI> result = new ArrayList<>();
    final String base = addTrailingSlash(surl.toString());
    Subject subject = asDcacheUser(user).getSubject();
    Restriction restriction = asDcacheUser(user).getRestriction();
    DirectoryListPrinter printer = new DirectoryListPrinter() {

        @Override
        public Set<FileAttribute> getRequiredAttributes() {
            return EnumSet.noneOf(FileAttribute.class);
        }

        @Override
        public void print(FsPath dir, FileAttributes dirAttr, DirectoryEntry entry) {
            result.add(URI.create(base + entry.getName()));
        }
    };
    try {
        _listSource.printDirectory(subject, restriction, printer, path, null, Range.<Integer>all());
        return result;
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("List aborted by administrator", e);
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException("Not a directory", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied", e);
    } catch (CacheException e) {
        throw new SRMException(String.format("List failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) DirectoryListPrinter(org.dcache.util.list.DirectoryListPrinter) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ArrayList(java.util.ArrayList) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) DirectoryEntry(org.dcache.util.list.DirectoryEntry) URI(java.net.URI) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 9 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method listSubdirectoriesRecursivelyForDelete.

/**
 * Adds transitive subdirectories of {@code dir} to {@code result}.
 *
 * @param subject    Issuer of rmdir
 * @param dir        Path to directory
 * @param attributes File attributes of {@code dir}
 * @param result     List that subdirectories are added to
 * @throws SRMAuthorizationException     if {@code subject} is not authorized to list {@code
 *                                       dir} or not authorized to list or delete any of its
 *                                       transitive subdirectories.
 * @throws SRMNonEmptyDirectoryException if {@code dir} or any of its transitive subdirectories
 *                                       contains non-directory entries.
 * @throws SRMInternalErrorException     in case of transient errors.
 * @throws SRMInvalidPathException       if {@code dir} is not a directory.
 * @throws SRMException                  in case of other errors.
 */
private void listSubdirectoriesRecursivelyForDelete(Subject subject, Restriction restriction, FsPath dir, FileAttributes attributes, List<FsPath> result) throws SRMException {
    List<DirectoryEntry> children = new ArrayList<>();
    try (DirectoryStream list = _listSource.list(subject, restriction, dir, null, Range.<Integer>all(), attributesRequiredForRmdir)) {
        for (DirectoryEntry child : list) {
            FileAttributes childAttributes = child.getFileAttributes();
            AccessType canDelete = permissionHandler.canDeleteDir(subject, attributes, childAttributes);
            if (canDelete != AccessType.ACCESS_ALLOWED) {
                throw new SRMAuthorizationException(dir + "/" + child.getName() + " (permission denied)");
            }
            if (childAttributes.getFileType() != FileType.DIR) {
                throw new SRMNonEmptyDirectoryException(dir + "/" + child.getName() + " (not empty)");
            }
            children.add(child);
        }
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException(dir + " (not a directory)", e);
    } catch (FileNotFoundCacheException ignored) {
    // Somebody removed the directory before we could.
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException(dir + " (permission denied)", e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Name space timeout", e);
    } catch (CacheException e) {
        throw new SRMException(dir + " (" + e.getMessage() + ")");
    }
    // Result list uses post-order so directories will be deleted bottom-up.
    for (DirectoryEntry child : children) {
        FsPath path = dir.child(child.getName());
        listSubdirectoriesRecursivelyForDelete(subject, restriction, path, child.getFileAttributes(), result);
        result.add(path);
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMNonEmptyDirectoryException(org.dcache.srm.SRMNonEmptyDirectoryException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) ArrayList(java.util.ArrayList) DirectoryStream(org.dcache.util.list.DirectoryStream) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) DirectoryEntry(org.dcache.util.list.DirectoryEntry) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) AccessType(org.dcache.acl.enums.AccessType) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FsPath(diskCacheV111.util.FsPath)

Example 10 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method createDirectory.

@Override
public void createDirectory(SRMUser abstractUser, URI surl) throws SRMException {
    _log.debug("Storage.createDirectory");
    DcacheUser user = asDcacheUser(abstractUser);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        handler.createPnfsDirectory(getPath(surl).toString());
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException("Parent path is not a directory", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("Parent path does not exist", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException("File exists");
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        _log.error("Failed to create directory {}: {}", surl, e.getMessage());
        throw new SRMException(String.format("Failed to create directory [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)46 SRMException (org.dcache.srm.SRMException)34 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)26 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)21 CacheException (diskCacheV111.util.CacheException)20 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)19 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)18 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)17 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)17 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)17 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)17 NotDirCacheException (diskCacheV111.util.NotDirCacheException)17 FsPath (diskCacheV111.util.FsPath)13 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)13 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)10 Subject (javax.security.auth.Subject)10 URI (java.net.URI)9 PnfsHandler (diskCacheV111.util.PnfsHandler)8 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)7 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)6