Search in sources :

Example 1 with SrmCheckPermissionRequest

use of org.dcache.srm.v2_2.SrmCheckPermissionRequest 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;
}
Also used : SrmCheckPermissionRequest(org.dcache.srm.v2_2.SrmCheckPermissionRequest) SrmCheckPermissionResponse(org.dcache.srm.v2_2.SrmCheckPermissionResponse) TSURLPermissionReturn(org.dcache.srm.v2_2.TSURLPermissionReturn) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) Nonnull(javax.annotation.Nonnull)

Example 2 with SrmCheckPermissionRequest

use of org.dcache.srm.v2_2.SrmCheckPermissionRequest 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;
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTSURLPermissionReturn(org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn) TSURLPermissionReturn(org.dcache.srm.v2_2.TSURLPermissionReturn) ArrayOfTSURLPermissionReturn(org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TStatusCode(org.dcache.srm.v2_2.TStatusCode) SrmCheckPermissionRequest(org.dcache.srm.v2_2.SrmCheckPermissionRequest) SrmCheckPermissionResponse(org.dcache.srm.v2_2.SrmCheckPermissionResponse) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Aggregations

ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)2 SrmCheckPermissionRequest (org.dcache.srm.v2_2.SrmCheckPermissionRequest)2 SrmCheckPermissionResponse (org.dcache.srm.v2_2.SrmCheckPermissionResponse)2 TSURLPermissionReturn (org.dcache.srm.v2_2.TSURLPermissionReturn)2 Nonnull (javax.annotation.Nonnull)1 URI (org.apache.axis.types.URI)1 ArrayOfTSURLPermissionReturn (org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn)1 TPermissionMode (org.dcache.srm.v2_2.TPermissionMode)1 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1