Search in sources :

Example 1 with ArrayOfTGroupPermission

use of org.dcache.srm.v2_2.ArrayOfTGroupPermission 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 ArrayOfTGroupPermission

use of org.dcache.srm.v2_2.ArrayOfTGroupPermission 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 3 with ArrayOfTGroupPermission

use of org.dcache.srm.v2_2.ArrayOfTGroupPermission 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);
    }
}
Also used : SrmGetPermissionRequest(org.dcache.srm.v2_2.SrmGetPermissionRequest) SrmGetPermissionResponse(org.dcache.srm.v2_2.SrmGetPermissionResponse) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) TUserPermission(org.dcache.srm.v2_2.TUserPermission) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TStatusCode(org.dcache.srm.v2_2.TStatusCode) ArrayOfTPermissionReturn(org.dcache.srm.v2_2.ArrayOfTPermissionReturn) TPermissionReturn(org.dcache.srm.v2_2.TPermissionReturn) ArrayOfTPermissionReturn(org.dcache.srm.v2_2.ArrayOfTPermissionReturn) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 4 with ArrayOfTGroupPermission

use of org.dcache.srm.v2_2.ArrayOfTGroupPermission 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;
}
Also used : SrmGetPermissionRequest(org.dcache.srm.v2_2.SrmGetPermissionRequest) SrmGetPermissionResponse(org.dcache.srm.v2_2.SrmGetPermissionResponse) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TPermissionReturn(org.dcache.srm.v2_2.TPermissionReturn) Nonnull(javax.annotation.Nonnull)

Example 5 with ArrayOfTGroupPermission

use of org.dcache.srm.v2_2.ArrayOfTGroupPermission 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);
}
Also used : TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode)

Aggregations

ArrayOfTGroupPermission (org.dcache.srm.v2_2.ArrayOfTGroupPermission)5 TGroupPermission (org.dcache.srm.v2_2.TGroupPermission)4 ArrayOfTUserPermission (org.dcache.srm.v2_2.ArrayOfTUserPermission)3 TPermissionMode (org.dcache.srm.v2_2.TPermissionMode)3 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 URI (org.apache.axis.types.URI)2 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)2 SrmGetPermissionRequest (org.dcache.srm.v2_2.SrmGetPermissionRequest)2 SrmGetPermissionResponse (org.dcache.srm.v2_2.SrmGetPermissionResponse)2 SrmSetPermissionResponse (org.dcache.srm.v2_2.SrmSetPermissionResponse)2 TPermissionReturn (org.dcache.srm.v2_2.TPermissionReturn)2 TPermissionType (org.dcache.srm.v2_2.TPermissionType)2 TStatusCode (org.dcache.srm.v2_2.TStatusCode)2 URI (java.net.URI)1 Nonnull (javax.annotation.Nonnull)1 FileMetaData (org.dcache.srm.FileMetaData)1 ArrayOfTPermissionReturn (org.dcache.srm.v2_2.ArrayOfTPermissionReturn)1 SrmSetPermissionRequest (org.dcache.srm.v2_2.SrmSetPermissionRequest)1 TUserPermission (org.dcache.srm.v2_2.TUserPermission)1