use of org.dcache.srm.v2_2.SrmCheckPermissionResponse in project dcache by dCache.
the class AxisSrmFileSystem method checkPermissions.
@Nonnull
@Override
public TSURLPermissionReturn[] checkPermissions(URI... surls) throws RemoteException, SRMException {
checkArgument(surls.length > 0);
SrmCheckPermissionResponse response = srm.srmCheckPermission(new SrmCheckPermissionRequest(new ArrayOfAnyURI(surls), null, null));
checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
TSURLPermissionReturn[] permissionArray = response.getArrayOfPermissions() == null ? null : response.getArrayOfPermissions().getSurlPermissionArray();
if (permissionArray == null || permissionArray.length == 0) {
checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS);
throw new SrmProtocolException("Server reply lacks permission array.");
}
if (permissionArray.length != surls.length) {
throw new SrmProtocolException("Server returns permissionArray " + "with wrong size (" + permissionArray.length + " != " + surls.length + ")");
}
return permissionArray;
}
use of org.dcache.srm.v2_2.SrmCheckPermissionResponse 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.SrmCheckPermissionResponse 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;
}
}
use of org.dcache.srm.v2_2.SrmCheckPermissionResponse in project dcache by dCache.
the class SrmCheckPermission method getFailedResponse.
public static final SrmCheckPermissionResponse getFailedResponse(String error, TStatusCode statusCode) {
TReturnStatus status = new TReturnStatus(statusCode, error);
SrmCheckPermissionResponse response = new SrmCheckPermissionResponse();
response.setReturnStatus(status);
return response;
}
Aggregations