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() + ")");
}
}
}
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);
}
}
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()));
}
}
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);
}
}
Aggregations