Search in sources :

Example 1 with SrmCheckPermissionResponse

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;
}
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 SrmCheckPermissionResponse

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));
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) 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(java.net.URI) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SrmCheckPermissionResponse(org.dcache.srm.v2_2.SrmCheckPermissionResponse) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) FileMetaData(org.dcache.srm.FileMetaData)

Example 3 with SrmCheckPermissionResponse

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;
    }
}
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)

Example 4 with SrmCheckPermissionResponse

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;
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmCheckPermissionResponse(org.dcache.srm.v2_2.SrmCheckPermissionResponse)

Aggregations

SrmCheckPermissionResponse (org.dcache.srm.v2_2.SrmCheckPermissionResponse)4 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 TSURLPermissionReturn (org.dcache.srm.v2_2.TSURLPermissionReturn)3 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)2 ArrayOfTSURLPermissionReturn (org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn)2 SrmCheckPermissionRequest (org.dcache.srm.v2_2.SrmCheckPermissionRequest)2 TPermissionMode (org.dcache.srm.v2_2.TPermissionMode)2 URI (java.net.URI)1 Nonnull (javax.annotation.Nonnull)1 URI (org.apache.axis.types.URI)1 FileMetaData (org.dcache.srm.FileMetaData)1 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)1 SRMException (org.dcache.srm.SRMException)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1