use of org.dcache.srm.v2_2.TPermissionMode in project dcache by dCache.
the class SRMSetPermissionClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
URI uri = new URI(surl_string);
SrmSetPermissionRequest req = new SrmSetPermissionRequest();
req.setSURL(uri);
TPermissionType type = TPermissionType.fromString(configuration.getSetPermissionType());
req.setPermissionType(type);
TPermissionMode mode = null;
if (configuration.getSetOwnerPermissionMode() != null) {
mode = TPermissionMode.fromString(configuration.getSetOwnerPermissionMode());
}
req.setOwnerPermission(mode);
ArrayOfTGroupPermission arrayOfGroupPermissions = new ArrayOfTGroupPermission();
TGroupPermission[] grouppermissions = null;
if (configuration.getSetGroupPermissionMode() != null) {
grouppermissions = new TGroupPermission[1];
grouppermissions[0] = new TGroupPermission();
grouppermissions[0].setMode(TPermissionMode.fromString(configuration.getSetGroupPermissionMode()));
grouppermissions[0].setGroupID(DEFAULT_DUMMY_GROUP_ID);
}
arrayOfGroupPermissions.setGroupPermissionArray(grouppermissions);
req.setArrayOfGroupPermissions(arrayOfGroupPermissions);
TPermissionMode other = null;
if (configuration.getSetOtherPermissionMode() != null) {
other = TPermissionMode.fromString(configuration.getSetOtherPermissionMode());
}
req.setOtherPermission(other);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmSetPermissionResponse resp = srm.srmSetPermission(req);
try {
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
TStatusCode rc = rs.getStatusCode();
StringBuilder sb = new StringBuilder();
sb.append("Return code: ").append(rc.toString()).append("\n");
sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
System.out.println(sb.toString());
System.exit(1);
} else {
System.exit(0);
}
} catch (Exception e) {
throw e;
}
}
use of org.dcache.srm.v2_2.TPermissionMode in project dcache by dCache.
the class SrmShell method cd.
@SuppressWarnings("fallthrough")
private void cd(String path) throws URI.MalformedURIException, RemoteException, SRMException, InterruptedException {
if (!path.endsWith("/")) {
path = path + "/";
}
URI uri = new URI(pwd, path);
checkValidPath(fs.stat(uri).getType() == TFileType.DIRECTORY, "Not a directory");
switch(checkCdPermission) {
case SRM_CHECK_PERMISSION:
try {
TPermissionMode permission = fs.checkPermission(uri);
if (permission != TPermissionMode.RWX && permission != TPermissionMode.RX && permission != TPermissionMode.WX && permission != TPermissionMode.X) {
throw new SRMAuthorizationException("Access denied");
}
break;
} catch (SRMNotSupportedException e) {
/* StoRM does not support checkPermission:
*
* https://ggus.eu/index.php?mode=ticket_info&ticket_id=124634
*/
notifications.add("The CheckPermission operation is not supported, using directory listing instead.");
checkCdPermission = PermissionOperation.SRM_LS;
// fall-through: use srmLs
}
case SRM_LS:
fs.list(uri, false);
}
pwd = uri;
}
use of org.dcache.srm.v2_2.TPermissionMode 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.v2_2.TPermissionMode 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));
}
use of org.dcache.srm.v2_2.TPermissionMode in project dcache by dCache.
the class SRMCheckPermissionClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
ArrayOfAnyURI surlarray = new ArrayOfAnyURI();
URI[] uriarray = new URI[surl_string.length];
URI uri;
for (int i = 0; i < uriarray.length; i++) {
uri = new URI(surl_string[i]);
uriarray[i] = uri;
}
surlarray.setUrlArray(uriarray);
SrmCheckPermissionRequest req = new SrmCheckPermissionRequest();
req.setArrayOfSURLs(surlarray);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmCheckPermissionResponse resp = srm.srmCheckPermission(req);
try {
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
TStatusCode rc = rs.getStatusCode();
StringBuilder sb = new StringBuilder();
sb.append("Return code: ").append(rc.toString()).append("\n");
sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
System.out.println(sb.toString());
}
ArrayOfTSURLPermissionReturn permissions = resp.getArrayOfPermissions();
TSURLPermissionReturn[] permissionarray = permissions.getSurlPermissionArray();
StringBuilder txt = new StringBuilder();
for (TSURLPermissionReturn permission : permissionarray) {
txt.append("# file : ").append(permission.getSurl()).append("\n");
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
txt.append("Return code: ").append(permission.getStatus().getStatusCode().toString()).append("\n");
txt.append("Explanation: ").append(permission.getStatus().getExplanation()).append("\n");
if (permission.getStatus().getStatusCode() != TStatusCode.SRM_SUCCESS) {
continue;
}
}
TPermissionMode mode = permission.getPermission();
txt.append("permission mode:").append(mode.toString()).append("\n");
}
System.out.println(txt.toString());
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
System.exit(1);
} else {
System.exit(0);
}
} catch (Exception e) {
throw e;
}
}
Aggregations