Search in sources :

Example 1 with ACL

use of org.apache.zookeeper_voltpatches.data.ACL in project voltdb by VoltDB.

the class ZooKeeperMain method parseACLs.

private static List<ACL> parseACLs(String aclString) {
    List<ACL> acl;
    String[] acls = aclString.split(",");
    acl = new ArrayList<ACL>();
    for (String a : acls) {
        int firstColon = a.indexOf(':');
        int lastColon = a.lastIndexOf(':');
        if (firstColon == -1 || lastColon == -1 || firstColon == lastColon) {
            System.err.println(a + " does not have the form scheme:id:perm");
            continue;
        }
        ACL newAcl = new ACL();
        newAcl.setId(new Id(a.substring(0, firstColon), a.substring(firstColon + 1, lastColon)));
        newAcl.setPerms(getPermFromString(a.substring(lastColon + 1)));
        acl.add(newAcl);
    }
    return acl;
}
Also used : ACL(org.apache.zookeeper_voltpatches.data.ACL) Id(org.apache.zookeeper_voltpatches.data.Id)

Example 2 with ACL

use of org.apache.zookeeper_voltpatches.data.ACL in project voltdb by VoltDB.

the class ACL method equals.

@Override
public boolean equals(Object peer_) {
    if (!(peer_ instanceof ACL)) {
        return false;
    }
    if (peer_ == this) {
        return true;
    }
    ACL peer = (ACL) peer_;
    boolean ret = false;
    ret = (perms == peer.perms);
    if (!ret)
        return ret;
    ret = id.equals(peer.id);
    if (!ret)
        return ret;
    return ret;
}
Also used : ACL(org.apache.zookeeper_voltpatches.data.ACL)

Example 3 with ACL

use of org.apache.zookeeper_voltpatches.data.ACL in project voltdb by VoltDB.

the class ZooKeeperServer method fixupACL.

/**
     * This method checks out the acl making sure it isn't null or empty, it has
     * valid schemes and ids, and expanding any relative ids that depend on the
     * requestor's authentication information.
     *
     * @param authInfo
     *            list of ACL IDs associated with the client connection
     * @param acl
     *            list of ACLs being assigned to the node (create or setACL
     *            operation)
     * @return
     */
private boolean fixupACL(List<Id> authInfo, List<ACL> acl) {
    if (skipACL) {
        return true;
    }
    if (acl == null || acl.size() == 0) {
        return false;
    }
    Iterator<ACL> it = acl.iterator();
    LinkedList<ACL> toAdd = null;
    while (it.hasNext()) {
        ACL a = it.next();
        Id id = a.getId();
        if (id.getScheme().equals("world") && id.getId().equals("anyone")) {
        // wide open
        } else if (id.getScheme().equals("auth")) {
            // This is the "auth" id, so we have to expand it to the
            // authenticated ids of the requestor
            it.remove();
            if (toAdd == null) {
                toAdd = new LinkedList<ACL>();
            }
            boolean authIdValid = false;
            for (Id cid : authInfo) {
                AuthenticationProvider ap = ProviderRegistry.getProvider(cid.getScheme());
                if (ap == null) {
                    LOG.error("Missing AuthenticationProvider for " + cid.getScheme());
                } else if (ap.isAuthenticated()) {
                    authIdValid = true;
                    toAdd.add(new ACL(a.getPerms(), cid));
                }
            }
            if (!authIdValid) {
                return false;
            }
        } else {
            AuthenticationProvider ap = ProviderRegistry.getProvider(id.getScheme());
            if (ap == null) {
                return false;
            }
            if (!ap.isValid(id.getId())) {
                return false;
            }
        }
    }
    if (toAdd != null) {
        for (ACL a : toAdd) {
            acl.add(a);
        }
    }
    return acl.size() > 0;
}
Also used : AuthenticationProvider(org.apache.zookeeper_voltpatches.server.auth.AuthenticationProvider) ACL(org.apache.zookeeper_voltpatches.data.ACL) Id(org.apache.zookeeper_voltpatches.data.Id) LinkedList(java.util.LinkedList)

Example 4 with ACL

use of org.apache.zookeeper_voltpatches.data.ACL in project voltdb by VoltDB.

the class ZooKeeperMain method processZKCmd.

protected boolean processZKCmd(MyCommandOptions co) throws KeeperException, IOException, InterruptedException {
    Stat stat = new Stat();
    String[] args = co.getArgArray();
    String cmd = co.getCommand();
    if (args.length < 1) {
        usage();
        return false;
    }
    if (!commandMap.containsKey(cmd)) {
        usage();
        return false;
    }
    boolean watch = args.length > 2;
    String path = null;
    List<ACL> acl = Ids.OPEN_ACL_UNSAFE;
    LOG.debug("Processing " + cmd);
    if (cmd.equals("quit")) {
        System.out.println("Quitting...");
        zk.close();
        System.exit(0);
    } else if (cmd.equals("redo") && args.length >= 2) {
        Integer i = Integer.decode(args[1]);
        if (commandCount <= i) {
            // don't allow redoing this redo
            System.out.println("Command index out of range");
            return false;
        }
        cl.parseCommand(history.get(i));
        if (cl.getCommand().equals("redo")) {
            System.out.println("No redoing redos");
            return false;
        }
        history.put(commandCount, history.get(i));
        processCmd(cl);
    } else if (cmd.equals("history")) {
        for (int i = commandCount - 10; i <= commandCount; ++i) {
            if (i < 0)
                continue;
            System.out.println(i + " - " + history.get(i));
        }
    } else if (cmd.equals("printwatches")) {
        if (args.length == 1) {
            System.out.println("printwatches is " + (printWatches ? "on" : "off"));
        } else {
            printWatches = args[1].equals("on");
        }
    } else if (cmd.equals("connect")) {
        if (args.length >= 2) {
            connectToZK(args[1]);
        } else {
            connectToZK(host);
        }
    }
    // Below commands all need a live connection
    if (zk == null || !zk.state.isAlive()) {
        System.out.println("Not connected");
        return false;
    }
    if (cmd.equals("create") && args.length >= 3) {
        int first = 0;
        CreateMode flags = CreateMode.PERSISTENT;
        if ((args[1].equals("-e") && args[2].equals("-s")) || (args[1]).equals("-s") && (args[2].equals("-e"))) {
            first += 2;
            flags = CreateMode.EPHEMERAL_SEQUENTIAL;
        } else if (args[1].equals("-e")) {
            first++;
            flags = CreateMode.EPHEMERAL;
        } else if (args[1].equals("-s")) {
            first++;
            flags = CreateMode.PERSISTENT_SEQUENTIAL;
        }
        if (args.length == first + 4) {
            acl = parseACLs(args[first + 3]);
        }
        path = args[first + 1];
        String newPath = zk.create(path, args[first + 2].getBytes(), acl, flags);
        System.err.println("Created " + newPath);
    } else if (cmd.equals("delete") && args.length >= 2) {
        path = args[1];
        zk.delete(path, watch ? Integer.parseInt(args[2]) : -1);
    } else if (cmd.equals("set") && args.length >= 3) {
        path = args[1];
        stat = zk.setData(path, args[2].getBytes(), args.length > 3 ? Integer.parseInt(args[3]) : -1);
        printStat(stat);
    } else if (cmd.equals("aget") && args.length >= 2) {
        path = args[1];
        zk.getData(path, watch, dataCallback, path);
    } else if (cmd.equals("get") && args.length >= 2) {
        path = args[1];
        byte[] data = zk.getData(path, watch, stat);
        data = (data == null) ? "null".getBytes() : data;
        System.out.println(new String(data));
        printStat(stat);
    } else if (cmd.equals("ls") && args.length >= 2) {
        path = args[1];
        List<String> children = zk.getChildren(path, watch);
        System.out.println(children);
    } else if (cmd.equals("ls2") && args.length >= 2) {
        path = args[1];
        List<String> children = zk.getChildren(path, watch, stat);
        System.out.println(children);
        printStat(stat);
    } else if (cmd.equals("getAcl") && args.length >= 2) {
        path = args[1];
        acl = zk.getACL(path, stat);
        for (ACL a : acl) {
            System.out.println(a.getId() + ": " + getPermString(a.getPerms()));
        }
    } else if (cmd.equals("setAcl") && args.length >= 3) {
        path = args[1];
        stat = zk.setACL(path, parseACLs(args[2]), args.length > 4 ? Integer.parseInt(args[3]) : -1);
        printStat(stat);
    } else if (cmd.equals("stat") && args.length >= 2) {
        path = args[1];
        stat = zk.exists(path, watch);
        printStat(stat);
    } else if (cmd.equals("listquota") && args.length >= 2) {
        path = args[1];
        String absolutePath = Quotas.quotaZookeeper + path + "/" + Quotas.limitNode;
        byte[] data = null;
        try {
            System.err.println("absolute path is " + absolutePath);
            data = zk.getData(absolutePath, false, stat);
            StatsTrack st = new StatsTrack(new String(data));
            System.out.println("Output quota for " + path + " " + st.toString());
            data = zk.getData(Quotas.quotaZookeeper + path + "/" + Quotas.statNode, false, stat);
            System.out.println("Output stat for " + path + " " + new StatsTrack(new String(data)).toString());
        } catch (KeeperException.NoNodeException ne) {
            System.err.println("quota for " + path + " does not exist.");
        }
    } else if (cmd.equals("setquota") && args.length >= 4) {
        String option = args[1];
        String val = args[2];
        path = args[3];
        System.err.println("Comment: the parts are " + "option " + option + " val " + val + " path " + path);
        if ("-b".equals(option)) {
            // we are setting the bytes quota
            createQuota(zk, path, Long.parseLong(val), -1);
        } else if ("-n".equals(option)) {
            // we are setting the num quota
            createQuota(zk, path, -1L, Integer.parseInt(val));
        } else {
            usage();
        }
    } else if (cmd.equals("delquota") && args.length >= 2) {
        // the quota node for thsi node.
        if (args.length == 3) {
            // this time we have an option
            String option = args[1];
            path = args[2];
            if ("-b".equals(option)) {
                delQuota(zk, path, true, false);
            } else if ("-n".equals(option)) {
                delQuota(zk, path, false, true);
            }
        } else if (args.length == 2) {
            path = args[1];
            // we dont have an option specified.
            // just delete whole quota node
            delQuota(zk, path, true, true);
        } else if (cmd.equals("help")) {
            usage();
        }
    } else if (cmd.equals("close")) {
        zk.close();
    } else if (cmd.equals("addauth") && args.length >= 2) {
        byte[] b = null;
        if (args.length >= 3)
            b = args[2].getBytes();
        zk.addAuthInfo(args[1], b);
    } else {
        usage();
    }
    return watch;
}
Also used : ACL(org.apache.zookeeper_voltpatches.data.ACL) Stat(org.apache.zookeeper_voltpatches.data.Stat) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 5 with ACL

use of org.apache.zookeeper_voltpatches.data.ACL in project voltdb by VoltDB.

the class ACL method compareTo.

public int compareTo(Object peer_) throws ClassCastException {
    if (!(peer_ instanceof ACL)) {
        throw new ClassCastException("Comparing different types of records.");
    }
    ACL peer = (ACL) peer_;
    int ret = 0;
    ret = (perms == peer.perms) ? 0 : ((perms < peer.perms) ? -1 : 1);
    if (ret != 0)
        return ret;
    ret = id.compareTo(peer.id);
    if (ret != 0)
        return ret;
    return ret;
}
Also used : ACL(org.apache.zookeeper_voltpatches.data.ACL)

Aggregations

ACL (org.apache.zookeeper_voltpatches.data.ACL)8 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Id (org.apache.zookeeper_voltpatches.data.Id)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Index (org.apache.jute_voltpatches.Index)1 Stat (org.apache.zookeeper_voltpatches.data.Stat)1 AuthenticationProvider (org.apache.zookeeper_voltpatches.server.auth.AuthenticationProvider)1