use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class LsFileRequest method getMetaDataPathDetail.
protected final TMetaDataPathDetail getMetaDataPathDetail(URI surl, int depth, long offset, long count, int recursionDepth, boolean longFormat) throws SRMException, URISyntaxException {
FileMetaData fmd = getStorage().getFileMetaData(getUser(), surl, false);
TMetaDataPathDetail aMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(surl, fmd, longFormat);
if (!getContainerRequest().increaseResultsNumAndContinue()) {
return aMetaDataPathDetail;
}
if (fmd.isDirectory && depth < recursionDepth) {
if (recursionDepth == 1) {
//
// for simplicity break up code into two blocks - one block
// works for the simple case recursionDepth=1, the other
// block works for recursionDepth>1
// there is a bit of code duplication, but code is
// relatively straightforward this way
//
getMetaDataPathDetail(aMetaDataPathDetail, offset, count, longFormat);
} else {
getRecursiveMetaDataPathDetail(aMetaDataPathDetail, fmd, depth, offset, count, recursionDepth, longFormat);
}
}
return aMetaDataPathDetail;
}
use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class LsFileRequest method getRecursiveMetaDataPathDetail.
private void getRecursiveMetaDataPathDetail(TMetaDataPathDetail metaDataPathDetail, FileMetaData fmd, int depth, long offset, long count, int recursionDepth, boolean longFormat) throws SRMException, URISyntaxException {
if (!fmd.isDirectory || depth >= recursionDepth) {
return;
}
List<FileMetaData> directoryList;
URI surl = new URI(null, null, metaDataPathDetail.getPath(), null);
// rely on our own counting
if (offset == 0) {
//
// if offset=0, trivial case, just grab information w/ verbosity level
// provided by the user
//
directoryList = getStorage().listDirectory(getUser(), surl, longFormat, 0, (int) count);
} else {
//
// if offset!=0, we loop over direntries in non-verbose mode until
// we hit offset, then start getting information with verbosity
// level specified by the user by calling getStorage().getFileMetaData on
// each entry
//
directoryList = getStorage().listDirectory(getUser(), surl, false, 0, Integer.MAX_VALUE);
}
//
// sort list such that directories are at the end of the list after
// sorting. The intent is to leave the recursion calls at the
// end of the tree, so we have less chance to even get there
//
Collections.sort(directoryList, DIRECTORY_LAST_ORDER);
List<TMetaDataPathDetail> metadataPathDetailList = new LinkedList<>();
for (FileMetaData md : directoryList) {
URI subpath = new URI(null, null, md.SURL, null);
TMetaDataPathDetail dirMetaDataPathDetail;
if (offset == 0) {
dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, md, longFormat);
} else {
FileMetaData fileMetaData = md;
if (!getContainerRequest().shouldSkipThisRecord()) {
if (longFormat) {
fileMetaData = getStorage().getFileMetaData(getUser(), subpath, false);
}
dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, fileMetaData, longFormat);
} else {
//
// skip this record - meaning count it, and request only minimal details, do not store it
//
dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, fileMetaData, false);
}
}
if (!getContainerRequest().shouldSkipThisRecord()) {
metadataPathDetailList.add(dirMetaDataPathDetail);
try {
if (!getContainerRequest().increaseResultsNumAndContinue()) {
break;
}
} catch (SRMTooManyResultsException e) {
metaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage()));
break;
}
}
//
// increment global entries counter
//
getContainerRequest().incrementGlobalEntryCounter();
if (md.isDirectory) {
try {
getRecursiveMetaDataPathDetail(dirMetaDataPathDetail, md, depth + 1, offset, count, recursionDepth, longFormat);
} catch (SRMException e) {
String msg = e.getMessage();
if (e instanceof SRMAuthorizationException) {
dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, msg));
} else if (e instanceof SRMInvalidPathException) {
dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_INVALID_PATH, msg));
} else {
dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, msg));
}
}
}
}
metaDataPathDetail.setArrayOfSubPaths(new ArrayOfTMetaDataPathDetail(metadataPathDetailList.toArray(TMetaDataPathDetail[]::new)));
}
use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class SrmSetPermission method srmSetPermission.
private SrmSetPermissionResponse srmSetPermission() throws SRMException {
URI surl = URI.create(request.getSURL().toString());
FileMetaData fmd = storage.getFileMetaData(user, surl, false);
TPermissionType permissionType = request.getPermissionType();
if (permissionType == TPermissionType.REMOVE) {
/* [ SRM 2.2, 3.1.2 ]
*
* h) If TPermissionType is REMOVE, then the TPermissionMode must be ignored.
*
* We interpret this requirement to apply to user and group ACLs only. Since
* we don't support these, we don't support REMOVE.
*/
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
TPermissionMode ownerMode = request.getOwnerPermission();
TPermissionMode otherMode = request.getOtherPermission();
TPermissionMode groupMode = null;
ArrayOfTUserPermission userPermissions = request.getArrayOfUserPermissions();
if (userPermissions != null) {
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
ArrayOfTGroupPermission groupPermissions = request.getArrayOfGroupPermissions();
if (groupPermissions != null && groupPermissions.getGroupPermissionArray() != null) {
switch(groupPermissions.getGroupPermissionArray().length) {
case 0:
break;
case 1:
TGroupPermission permission = groupPermissions.getGroupPermissionArray()[0];
String group = permission.getGroupID();
if (!group.equals("-") && !group.equals(fmd.group)) {
/* The dash is a special dCache convention used by our own SRM client to
* indicate that the POSIX group permissions should be updated.
*/
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
groupMode = permission.getMode();
break;
default:
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
}
fmd.permMode = toNewPermissions(fmd.permMode, permissionType, ownerMode, groupMode, otherMode);
storage.setFileMetaData(user, surl, fmd);
return new SrmSetPermissionResponse(new TReturnStatus(TStatusCode.SRM_SUCCESS, null));
}
use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class SrmGetPermission method srmGetPermission.
private SrmGetPermissionResponse srmGetPermission() throws SRMInvalidRequestException, SRMInternalErrorException {
org.apache.axis.types.URI[] surls = request.getArrayOfSURLs().getUrlArray();
if (surls == null || surls.length == 0) {
throw new SRMInvalidRequestException("arrayOfSURLs is empty");
}
int length = surls.length;
TPermissionReturn[] permissionsArray = new TPermissionReturn[length];
boolean hasFailure = false;
boolean hasSuccess = false;
for (int i = 0; i < length; i++) {
TPermissionReturn p = new TPermissionReturn();
TReturnStatus returnStatus;
try {
FileMetaData fmd = storage.getFileMetaData(user, URI.create(surls[i].toString()), false);
copyPermissions(fmd, p);
returnStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
hasSuccess = true;
} catch (SRMInternalErrorException e) {
throw e;
} catch (SRMAuthorizationException e) {
returnStatus = new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
hasFailure = true;
} catch (SRMInvalidPathException e) {
returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
hasFailure = true;
} catch (SRMException e) {
LOGGER.warn(e.toString());
returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
hasFailure = true;
}
p.setSurl(surls[i]);
p.setStatus(returnStatus);
permissionsArray[i] = p;
}
return new SrmGetPermissionResponse(getSummaryReturnStatus(hasFailure, hasSuccess), new ArrayOfTPermissionReturn(permissionsArray));
}
use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class SrmCheckPermission method srmCheckPermission.
private SrmCheckPermissionResponse srmCheckPermission() throws SRMInternalErrorException, SRMInvalidRequestException {
org.apache.axis.types.URI[] surls = request.getArrayOfSURLs().getUrlArray();
if (surls == null || surls.length == 0) {
throw new SRMInvalidRequestException("arrayOfSURLs is empty");
}
int length = surls.length;
TSURLPermissionReturn[] permissions = new TSURLPermissionReturn[length];
boolean hasSuccess = false;
boolean hasFailure = false;
for (int i = 0; i < length; i++) {
TReturnStatus returnStatus;
TPermissionMode pm = null;
try {
FileMetaData fmd = storage.getFileMetaData(user, URI.create(surls[i].toString()), false);
int mode = fmd.permMode;
if (fmd.isOwner(user)) {
pm = PermissionMaskToTPermissionMode.maskToTPermissionMode(((mode >> 6) & 0x7));
} else if (fmd.isGroupMember(user)) {
pm = PermissionMaskToTPermissionMode.maskToTPermissionMode(((mode >> 3) & 0x7));
} else {
pm = PermissionMaskToTPermissionMode.maskToTPermissionMode((mode & 0x7));
}
returnStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
hasSuccess = true;
} catch (SRMInternalErrorException e) {
throw e;
} catch (SRMInvalidPathException e) {
returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
hasFailure = true;
} catch (SRMAuthorizationException e) {
returnStatus = new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
hasFailure = true;
} catch (SRMException e) {
LOGGER.warn(e.toString());
returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
hasFailure = true;
}
permissions[i] = new TSURLPermissionReturn(surls[i], returnStatus, pm);
}
return new SrmCheckPermissionResponse(ReturnStatuses.getSummaryReturnStatus(hasFailure, hasSuccess), new ArrayOfTSURLPermissionReturn(permissions));
}
Aggregations