Search in sources :

Example 1 with TPermissionMode

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;
    }
}
Also used : SrmSetPermissionRequest(org.dcache.srm.v2_2.SrmSetPermissionRequest) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(org.apache.axis.types.URI) SrmSetPermissionResponse(org.dcache.srm.v2_2.SrmSetPermissionResponse) TStatusCode(org.dcache.srm.v2_2.TStatusCode) TPermissionType(org.dcache.srm.v2_2.TPermissionType) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission)

Example 2 with TPermissionMode

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;
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(org.apache.axis.types.URI)

Example 3 with TPermissionMode

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));
}
Also used : TPermissionType(org.dcache.srm.v2_2.TPermissionType) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(java.net.URI) SrmSetPermissionResponse(org.dcache.srm.v2_2.SrmSetPermissionResponse) FileMetaData(org.dcache.srm.FileMetaData)

Example 4 with TPermissionMode

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));
}
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 5 with TPermissionMode

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

TPermissionMode (org.dcache.srm.v2_2.TPermissionMode)6 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)4 URI (org.apache.axis.types.URI)3 ArrayOfTGroupPermission (org.dcache.srm.v2_2.ArrayOfTGroupPermission)3 TGroupPermission (org.dcache.srm.v2_2.TGroupPermission)3 URI (java.net.URI)2 FileMetaData (org.dcache.srm.FileMetaData)2 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)2 ArrayOfTSURLPermissionReturn (org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn)2 SrmCheckPermissionResponse (org.dcache.srm.v2_2.SrmCheckPermissionResponse)2 SrmSetPermissionResponse (org.dcache.srm.v2_2.SrmSetPermissionResponse)2 TPermissionType (org.dcache.srm.v2_2.TPermissionType)2 TSURLPermissionReturn (org.dcache.srm.v2_2.TSURLPermissionReturn)2 TStatusCode (org.dcache.srm.v2_2.TStatusCode)2 SRMException (org.dcache.srm.SRMException)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1