use of org.dcache.srm.v2_2.TPermissionReturn 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.v2_2.TPermissionReturn in project dcache by dCache.
the class SRMGetPermissionClientV2 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);
SrmGetPermissionRequest req = new SrmGetPermissionRequest();
req.setArrayOfSURLs(surlarray);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmGetPermissionResponse resp = srm.srmGetPermission(req);
TReturnStatus rs = resp.getReturnStatus();
ArrayOfTPermissionReturn permissions = resp.getArrayOfPermissionReturns();
TPermissionReturn[] permissionarray = null;
if (permissions != null) {
permissionarray = permissions.getPermissionArray();
}
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());
}
StringBuilder txt = new StringBuilder();
if (permissionarray == null) {
txt.append("permissions array is null\n");
System.out.println(txt.toString());
System.exit(1);
}
for (TPermissionReturn 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;
}
}
txt.append("# owner : ").append(permission.getOwner()).append("\n");
txt.append("owner:").append(permission.getOwner()).append(":").append(permission.getOwnerPermission().toString()).append("\n");
ArrayOfTUserPermission arrayOfUserPermissions = permission.getArrayOfUserPermissions();
if (arrayOfUserPermissions != null) {
TUserPermission[] userPermissionArray = arrayOfUserPermissions.getUserPermissionArray();
if (userPermissionArray != null) {
for (TUserPermission upr : userPermissionArray) {
if (upr != null) {
txt.append("user:").append(upr.getUserID()).append(":").append(upr.getMode().toString()).append("\n");
}
}
}
}
ArrayOfTGroupPermission arrayOfGroupPermissions = permission.getArrayOfGroupPermissions();
if (arrayOfGroupPermissions != null) {
TGroupPermission[] groupPermissionArray = arrayOfGroupPermissions.getGroupPermissionArray();
if (groupPermissionArray != null) {
for (TGroupPermission upr : groupPermissionArray) {
if (upr != null) {
txt.append("group:").append(upr.getGroupID()).append(":").append(upr.getMode().toString()).append("\n");
}
}
}
}
txt.append("other:").append(permission.getOtherPermission().toString()).append("\n");
}
System.out.println(txt.toString());
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
System.exit(1);
} else {
System.exit(0);
}
}
use of org.dcache.srm.v2_2.TPermissionReturn in project dcache by dCache.
the class AxisSrmFileSystem method getPermissions.
@Nonnull
@Override
public TPermissionReturn[] getPermissions(URI... surls) throws RemoteException, SRMException {
checkArgument(surls.length > 0);
SrmGetPermissionResponse response = srm.srmGetPermission(new SrmGetPermissionRequest(null, new ArrayOfAnyURI(surls), null));
TPermissionReturn[] permissionArray = response.getArrayOfPermissionReturns().getPermissionArray();
if (permissionArray == null || permissionArray.length == 0) {
checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS);
throw new SrmProtocolException("Server reply lacks permission array.");
}
checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
// Simplify things for the caller
for (TPermissionReturn permission : permissionArray) {
if (permission.getArrayOfUserPermissions() == null) {
permission.setArrayOfUserPermissions(new ArrayOfTUserPermission());
}
if (permission.getArrayOfUserPermissions().getUserPermissionArray() == null) {
permission.getArrayOfUserPermissions().setUserPermissionArray(new TUserPermission[0]);
}
if (permission.getArrayOfGroupPermissions() == null) {
permission.setArrayOfGroupPermissions(new ArrayOfTGroupPermission());
}
if (permission.getArrayOfGroupPermissions().getGroupPermissionArray() == null) {
permission.getArrayOfGroupPermissions().setGroupPermissionArray(new TGroupPermission[0]);
}
}
return permissionArray;
}
use of org.dcache.srm.v2_2.TPermissionReturn in project dcache by dCache.
the class SrmGetPermission method copyPermissions.
private static void copyPermissions(FileMetaData fmd, TPermissionReturn p) {
String owner = fmd.owner;
String group = fmd.group;
int permissions = fmd.permMode;
TPermissionMode upm = PermissionMaskToTPermissionMode.maskToTPermissionMode(((permissions >> 6) & 0x7));
TPermissionMode gpm = PermissionMaskToTPermissionMode.maskToTPermissionMode(((permissions >> 3) & 0x7));
TPermissionMode opm = PermissionMaskToTPermissionMode.maskToTPermissionMode((permissions & 0x7));
TGroupPermission[] groupPermissionArray = new TGroupPermission[] { new TGroupPermission(group, gpm) };
p.setArrayOfGroupPermissions(new ArrayOfTGroupPermission(groupPermissionArray));
p.setOwnerPermission(upm);
p.setOtherPermission(opm);
p.setOwner(owner);
}
Aggregations