Search in sources :

Example 1 with GranteeType

use of com.zimbra.client.ZGrant.GranteeType in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doGetFolderGrant.

private void doGetFolderGrant(String[] args) throws ServiceException {
    ZFolder f = getFolderWithFullGrantInfo(args[0]);
    if (verboseOpt()) {
        StringBuilder sb = new StringBuilder();
        for (ZGrant g : f.getGrants()) {
            if (sb.length() > 0)
                sb.append(",\n");
            sb.append(g.dump());
        }
        stdout.format("[%n%s%n]%n", sb.toString());
    } else {
        String format = "%11.11s  %8.8s  %s%n";
        stdout.format(format, "Permissions", "Type", "Display");
        stdout.format(format, "-----------", "--------", "-------");
        for (ZGrant g : f.getGrants()) {
            GranteeType gt = g.getGranteeType();
            String dn = (gt == GranteeType.all || gt == GranteeType.pub) ? "" : ((gt == GranteeType.guest || gt == GranteeType.key) ? g.getGranteeId() : (g.getGranteeName() != null ? g.getGranteeName() : g.getGranteeId()));
            stdout.format(format, g.getPermissions(), getGranteeDisplay(g.getGranteeType()), dn);
        }
    }
}
Also used : GranteeType(com.zimbra.client.ZGrant.GranteeType) ZGrant(com.zimbra.client.ZGrant) ZFolder(com.zimbra.client.ZFolder)

Example 2 with GranteeType

use of com.zimbra.client.ZGrant.GranteeType in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doModifyFolderGrant.

private void doModifyFolderGrant(String[] args) throws ServiceException {
    String folderId = lookupFolderId(args[0], false);
    GranteeType type = getGranteeType(args[1]);
    String grantee = null;
    String perms = null;
    String password = null;
    switch(type) {
        case usr:
        case grp:
        case cos:
        case dom:
            if (args.length != 4) {
                throw ZClientException.CLIENT_ERROR("not enough args", null);
            }
            grantee = args[2];
            perms = args[3];
            break;
        case pub:
            grantee = GuestAccount.GUID_PUBLIC;
            perms = args[2];
            break;
        case all:
            grantee = GuestAccount.GUID_AUTHUSER;
            perms = args[2];
            break;
        case guest:
            if (args.length != 4 && args.length != 5)
                throw ZClientException.CLIENT_ERROR("not enough args", null);
            grantee = args[2];
            if (args.length == 5) {
                password = args[3];
                perms = args[4];
            } else {
                password = null;
                perms = args[3];
            }
            break;
        case key:
            if (args.length != 4 && args.length != 5)
                throw ZClientException.CLIENT_ERROR("not enough args", null);
            grantee = args[2];
            if (args.length == 5) {
                password = args[3];
                perms = args[4];
            } else {
                perms = args[3];
            }
            break;
    }
    boolean revoke = (perms != null && (perms.equalsIgnoreCase("none") || perms.length() == 0));
    if (revoke) {
        // convert grantee to grantee id if it is a name
        ZFolder f = getFolderWithFullGrantInfo(folderId);
        String zid = null;
        for (ZGrant g : f.getGrants()) {
            if (grantee.equalsIgnoreCase(g.getGranteeName()) || grantee.equalsIgnoreCase(g.getGranteeId())) {
                zid = g.getGranteeId();
                break;
            }
        }
        if (zid != null || (type == GranteeType.all || type == GranteeType.pub)) {
            if (zid != null)
                grantee = zid;
            mMbox.modifyFolderRevokeGrant(folderId, grantee);
        } else {
            // zid is null
            /*
                 * It could be we are trying to revoke a grant on a sub folder.
                 * e.g. /top/sub
                 *      mfg /top account user2 r
                 *      mfg /top/sub account user2 none
                 *      or
                 *      mfg /top account all r
                 *      mfg /top/sub account user3 none
                 *
                 * or simply just want to grant "no right" to a user
                 * e.g.
                 *      mfg /top account user2 none
                 *
                 * If this is the case zid wil be null because there is no such
                 * grant on the specified folder.   Just let it go through by issuing
                 * a grant action, instead of revoke.
                 */
            mMbox.modifyFolderGrant(folderId, type, grantee, "", password);
        }
    } else {
        mMbox.modifyFolderGrant(folderId, type, grantee, perms, password);
    }
}
Also used : GranteeType(com.zimbra.client.ZGrant.GranteeType) ZGrant(com.zimbra.client.ZGrant) ZFolder(com.zimbra.client.ZFolder)

Aggregations

ZFolder (com.zimbra.client.ZFolder)2 ZGrant (com.zimbra.client.ZGrant)2 GranteeType (com.zimbra.client.ZGrant.GranteeType)2