Search in sources :

Example 91 with PermissionDeniedCacheException

use of diskCacheV111.util.PermissionDeniedCacheException in project dcache by dCache.

the class Storage method removeSubdirectories.

private void removeSubdirectories(Subject subject, Restriction restriction, FsPath path) throws SRMException {
    PnfsHandler pnfs = new PnfsHandler(_pnfs, subject, restriction);
    FileAttributes parentAttributes;
    FileAttributes attributes;
    try {
        parentAttributes = pnfs.getFileAttributes(path.parent().toString(), attributesRequiredForRmdir);
        attributes = pnfs.getFileAttributes(path.toString(), attributesRequiredForRmdir);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Name space timeout", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (CacheException e) {
        throw new SRMException("Name space failure (" + e.getMessage() + ")");
    }
    checkValidPath(attributes.getFileType() == FileType.DIR, "Not a directory");
    if (permissionHandler.canDeleteDir(subject, parentAttributes, attributes) != AccessType.ACCESS_ALLOWED) {
        throw new SRMAuthorizationException("Permission denied");
    }
    List<FsPath> directories = new ArrayList<>();
    listSubdirectoriesRecursivelyForDelete(subject, restriction, path, attributes, directories);
    for (FsPath directory : directories) {
        try {
            pnfs.deletePnfsEntry(directory.toString(), EnumSet.of(FileType.DIR));
        } catch (TimeoutCacheException e) {
            throw new SRMInternalErrorException("Name space timeout", e);
        } catch (FileNotFoundCacheException ignored) {
        // Somebody removed the directory before we could.
        } catch (PermissionDeniedCacheException | NotDirCacheException e) {
            // have permission to delete them.
            throw new SRMException(directory + " (directory tree was modified concurrently)");
        } catch (CacheException e) {
            // Could be because the directory is no longer empty (concurrent modification),
            // but could also be some other error.
            _log.error("Failed to delete {}: {}", directory, e.getMessage());
            throw new SRMException(directory + " (" + 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) ArrayList(java.util.ArrayList) PnfsHandler(diskCacheV111.util.PnfsHandler) 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) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FsPath(diskCacheV111.util.FsPath)

Example 92 with PermissionDeniedCacheException

use of diskCacheV111.util.PermissionDeniedCacheException in project dcache by dCache.

the class Storage method getFileMetaData.

private FileMetaData getFileMetaData(DcacheUser user, boolean checkReadPermissions, FsPath path) throws SRMException {
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        /* Fetch file attributes.
             */
        Set<FileAttribute> requestedAttributes = EnumSet.of(TYPE, LOCATIONS);
        requestedAttributes.addAll(DcacheFileMetaData.getKnownAttributes());
        requestedAttributes.addAll(PoolMonitorV5.getRequiredAttributesForFileLocality());
        Set<AccessMask> accessMask = checkReadPermissions ? EnumSet.of(AccessMask.READ_DATA) : EnumSet.noneOf(AccessMask.class);
        FileAttributes attributes = handler.getFileAttributes(path.toString(), requestedAttributes, accessMask, false);
        FileMetaData fmd = new DcacheFileMetaData(attributes);
        /* Determine file locality.
             */
        if (attributes.getFileType() != FileType.DIR) {
            FileLocality locality = _poolMonitor.getFileLocality(attributes, config.getSrmHost());
            fmd.locality = locality.toTFileLocality();
            fmd.isCached = locality.isCached();
        }
        /* Determine space tokens.
             */
        if (_isSpaceManagerEnabled) {
            try {
                GetFileSpaceTokensMessage msg = new GetFileSpaceTokensMessage(attributes.getPnfsId());
                msg = _spaceManagerStub.sendAndWait(msg);
                if (msg.getSpaceTokens() != null) {
                    fmd.spaceTokens = new long[msg.getSpaceTokens().length];
                    System.arraycopy(msg.getSpaceTokens(), 0, fmd.spaceTokens, 0, msg.getSpaceTokens().length);
                }
            } catch (NoRouteToCellException e) {
                /* SpaceManager is optional, so we don't classify this
                     * as an error.
                     */
                _log.info(e.getMessage());
            }
        }
        return fmd;
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException(e.getMessage(), e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (CacheException e) {
        throw new SRMException("Could not get storage info by path: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    }
}
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) AccessMask(org.dcache.acl.enums.AccessMask) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) GetFileSpaceTokensMessage(diskCacheV111.services.space.message.GetFileSpaceTokensMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FileLocality(diskCacheV111.util.FileLocality) FileMetaData(org.dcache.srm.FileMetaData) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 93 with PermissionDeniedCacheException

use of diskCacheV111.util.PermissionDeniedCacheException in project dcache by dCache.

the class Storage method listDirectory.

@Override
public List<FileMetaData> listDirectory(SRMUser user, URI surl, final boolean verbose, int offset, int count) throws SRMException {
    try {
        FsPath path = getPath(surl);
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FmdListPrinter printer = verbose ? new VerboseListPrinter() : new FmdListPrinter();
        Range<Integer> range = offset < Integer.MAX_VALUE - count ? Range.closedOpen(offset, offset + count) : Range.atLeast(offset);
        _listSource.printDirectory(subject, restriction, printer, path, null, range);
        return printer.getResult();
    } 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) 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) 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) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 94 with PermissionDeniedCacheException

use of diskCacheV111.util.PermissionDeniedCacheException in project dcache by dCache.

the class DcacheUserManager method login.

protected LoginReply login(CertPath path, String remoteIP) throws SRMInternalErrorException, SRMAuthorizationException {
    try {
        Subject subject = new Subject();
        subject.getPublicCredentials().add(path);
        try {
            subject.getPrincipals().add(new Origin(remoteIP));
        } catch (UnknownHostException e) {
            LOGGER.info("Could not add origin {}: {}", remoteIP, e.getMessage());
        }
        return loginStrategy.login(subject);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException(e.getMessage(), e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    }
}
Also used : Origin(org.dcache.auth.Origin) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) UnknownHostException(java.net.UnknownHostException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Subject(javax.security.auth.Subject)

Aggregations

PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)87 CacheException (diskCacheV111.util.CacheException)68 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)54 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)47 NotDirCacheException (diskCacheV111.util.NotDirCacheException)41 FsPath (diskCacheV111.util.FsPath)40 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)34 NotFileCacheException (diskCacheV111.util.NotFileCacheException)33 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)30 FileAttributes (org.dcache.vehicles.FileAttributes)28 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)26 Subject (javax.security.auth.Subject)21 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)18 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)17 FileAttribute (org.dcache.namespace.FileAttribute)17 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)15 PnfsHandler (diskCacheV111.util.PnfsHandler)15 IOException (java.io.IOException)15 LockedCacheException (diskCacheV111.util.LockedCacheException)14 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)14