You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by an...@apache.org on 2018/10/05 12:26:24 UTC

[31/51] [partial] zookeeper git commit: ZOOKEEPER-3032: MAVEN MIGRATION - move java server, client

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java b/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java
deleted file mode 100644
index ff3de41..0000000
--- a/src/java/main/org/apache/zookeeper/server/admin/JettyAdminServer.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.admin;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class encapsulates a Jetty server for running Commands.
- *
- * Given the default settings, start a ZooKeeper server and visit
- * http://<hostname>:8080/commands for links to all registered commands. Visiting
- * http://<hostname>:8080/commands/<commandname> will execute the associated
- * Command and return the result in the body of the response. Any keyword
- * arguments to the command are specified with URL parameters (e.g.,
- * http://localhost:8080/commands/set_trace_mask?traceMask=306).
- *
- * @see Commands
- * @see CommandOutputter
- */
-public class JettyAdminServer implements AdminServer {
-    static final Logger LOG = LoggerFactory.getLogger(JettyAdminServer.class);
-
-    public static final int DEFAULT_PORT = 8080;
-    public static final int DEFAULT_IDLE_TIMEOUT = 30000;
-    public static final String DEFAULT_COMMAND_URL = "/commands";
-    private static final String DEFAULT_ADDRESS = "0.0.0.0";
-
-    private final Server server;
-    private final String address;
-    private final int port;
-    private final int idleTimeout;
-    private final String commandUrl;
-    private ZooKeeperServer zkServer;
-
-    public JettyAdminServer() throws AdminServerException {
-        this(System.getProperty("zookeeper.admin.serverAddress", DEFAULT_ADDRESS),
-             Integer.getInteger("zookeeper.admin.serverPort", DEFAULT_PORT),
-             Integer.getInteger("zookeeper.admin.idleTimeout", DEFAULT_IDLE_TIMEOUT),
-             System.getProperty("zookeeper.admin.commandURL", DEFAULT_COMMAND_URL));
-    }
-
-    public JettyAdminServer(String address, int port, int timeout, String commandUrl) {
-        this.port = port;
-        this.idleTimeout = timeout;
-        this.commandUrl = commandUrl;
-        this.address = address;
-
-        server = new Server();
-        ServerConnector connector = new ServerConnector(server);
-        connector.setHost(address);
-        connector.setPort(port);
-        connector.setIdleTimeout(idleTimeout);
-        server.addConnector(connector);
-
-        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
-        context.setContextPath("/*");
-        server.setHandler(context);
-
-        context.addServlet(new ServletHolder(new CommandServlet()), commandUrl + "/*");
-    }
-
-    /**
-     * Start the embedded Jetty server.
-     */
-    @Override
-    public void start() throws AdminServerException {
-        try {
-            server.start();
-        } catch (Exception e) {
-            // Server.start() only throws Exception, so let's at least wrap it
-            // in an identifiable subclass
-            throw new AdminServerException(String.format(
-                    "Problem starting AdminServer on address %s,"
-                            + " port %d and command URL %s", address, port,
-                    commandUrl), e);
-        }
-        LOG.info(String.format("Started AdminServer on address %s, port %d"
-                + " and command URL %s", address, port, commandUrl));
-    }
-
-    /**
-     * Stop the embedded Jetty server.
-     *
-     * This is not very important except for tests where multiple
-     * JettyAdminServers are started and may try to bind to the same ports if
-     * previous servers aren't shut down.
-     */
-    @Override
-    public void shutdown() throws AdminServerException {
-        try {
-            server.stop();
-        } catch (Exception e) {
-            throw new AdminServerException(String.format(
-                    "Problem stopping AdminServer on address %s,"
-                            + " port %d and command URL %s", address, port, commandUrl),
-                    e);
-        }
-    }
-
-    /**
-     * Set the ZooKeeperServer that will be used to run Commands.
-     *
-     * It is not necessary to set the ZK server before calling
-     * AdminServer.start(), and the ZK server can be set to null when, e.g.,
-     * that server is being shut down. If the ZK server is not set or set to
-     * null, the AdminServer will still be able to issue Commands, but they will
-     * return an error until a ZK server is set.
-     */
-    @Override
-    public void setZooKeeperServer(ZooKeeperServer zkServer) {
-        this.zkServer = zkServer;
-    }
-
-    private class CommandServlet extends HttpServlet {
-        private static final long serialVersionUID = 1L;
-
-        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-            // Capture the command name from the URL
-            String cmd = request.getPathInfo();
-            if (cmd == null || cmd.equals("/")) {
-                // No command specified, print links to all commands instead
-                for (String link : commandLinks()) {
-                    response.getWriter().println(link);
-                    response.getWriter().println("<br/>");
-                }
-                return;
-            }
-            // Strip leading "/"
-            cmd = cmd.substring(1);
-
-            // Extract keyword arguments to command from request parameters
-            @SuppressWarnings("unchecked")
-            Map<String, String[]> parameterMap = request.getParameterMap();
-            Map<String, String> kwargs = new HashMap<String, String>();
-            for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
-                kwargs.put(entry.getKey(), entry.getValue()[0]);
-            }
-
-            // Run the command
-            CommandResponse cmdResponse = Commands.runCommand(cmd, zkServer, kwargs);
-
-            // Format and print the output of the command
-            CommandOutputter outputter = new JsonOutputter();
-            response.setStatus(HttpServletResponse.SC_OK);
-            response.setContentType(outputter.getContentType());
-            outputter.output(cmdResponse, response.getWriter());
-        }
-    }
-
-    /**
-     * Returns a list of URLs to each registered Command.
-     */
-    private List<String> commandLinks() {
-        List<String> links = new ArrayList<String>();
-        List<String> commands = new ArrayList<String>(Commands.getPrimaryNames());
-        Collections.sort(commands);
-        for (String command : commands) {
-            String url = commandUrl + "/" + command;
-            links.add(String.format("<a href=\"%s\">%s</a>", url, command));
-        }
-        return links;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java b/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java
deleted file mode 100644
index 566444f..0000000
--- a/src/java/main/org/apache/zookeeper/server/admin/JsonOutputter.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.admin;
-
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategy;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-public class JsonOutputter implements CommandOutputter {
-    static final Logger LOG = LoggerFactory.getLogger(JsonOutputter.class);
-
-    public static final String ERROR_RESPONSE = "{\"error\": \"Exception writing command response to JSON\"}";
-
-    private ObjectMapper mapper;
-
-    public JsonOutputter() {
-        mapper = new ObjectMapper();
-        mapper.configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING, true);
-        mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
-        mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
-    }
-
-    @Override
-    public String getContentType() {
-        return "application/json";
-    }
-
-    @Override
-    public void output(CommandResponse response, PrintWriter pw) {
-        try {
-            mapper.writeValue(pw, response.toMap());
-        } catch (JsonGenerationException e) {
-            LOG.warn("Exception writing command response to JSON:", e);
-            pw.write(ERROR_RESPONSE);
-        } catch (JsonMappingException e) {
-            LOG.warn("Exception writing command response to JSON:", e);
-            pw.write(ERROR_RESPONSE);
-        } catch (IOException e) {
-            LOG.warn("Exception writing command response to JSON:", e);
-            pw.write(ERROR_RESPONSE);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java
deleted file mode 100644
index dd6e32f..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/AuthenticationProvider.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.server.ServerCnxn;
-
-/**
- * This interface is implemented by authentication providers to add new kinds of
- * authentication schemes to ZooKeeper.
- */
-public interface AuthenticationProvider {
-    /**
-     * The String used to represent this provider. This will correspond to the
-     * scheme field of an Id.
-     * 
-     * @return the scheme of this provider.
-     */
-    String getScheme();
-
-    /**
-     * This method is called when a client passes authentication data for this
-     * scheme. The authData is directly from the authentication packet. The
-     * implementor may attach new ids to the authInfo field of cnxn or may use
-     * cnxn to send packets back to the client.
-     * 
-     * @param cnxn
-     *                the cnxn that received the authentication information.
-     * @param authData
-     *                the authentication data received.
-     * @return TODO
-     */
-    KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte authData[]);
-
-    /**
-     * This method is called to see if the given id matches the given id
-     * expression in the ACL. This allows schemes to use application specific
-     * wild cards.
-     * 
-     * @param id
-     *                the id to check.
-     * @param aclExpr
-     *                the expression to match ids against.
-     * @return true if the id can be matched by the expression.
-     */
-    boolean matches(String id, String aclExpr);
-
-    /**
-     * This method is used to check if the authentication done by this provider
-     * should be used to identify the creator of a node. Some ids such as hosts
-     * and ip addresses are rather transient and in general don't really
-     * identify a client even though sometimes they do.
-     * 
-     * @return true if this provider identifies creators.
-     */
-    boolean isAuthenticated();
-
-    /**
-     * Validates the syntax of an id.
-     * 
-     * @param id
-     *                the id to validate.
-     * @return true if id is well formed.
-     */
-    boolean isValid(String id);
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java
deleted file mode 100644
index 2427e7a..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/DigestAuthenticationProvider.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.data.Id;
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class DigestAuthenticationProvider implements AuthenticationProvider {
-    private static final Logger LOG =
-        LoggerFactory.getLogger(DigestAuthenticationProvider.class);
-
-    /** specify a command line property with key of 
-     * "zookeeper.DigestAuthenticationProvider.superDigest"
-     * and value of "super:<base64encoded(SHA1(password))>" to enable
-     * super user access (i.e. acls disabled)
-     */
-    private final static String superDigest = System.getProperty(
-        "zookeeper.DigestAuthenticationProvider.superDigest");
-
-    public String getScheme() {
-        return "digest";
-    }
-
-    static final private String base64Encode(byte b[]) {
-        StringBuilder sb = new StringBuilder();
-        for (int i = 0; i < b.length;) {
-            int pad = 0;
-            int v = (b[i++] & 0xff) << 16;
-            if (i < b.length) {
-                v |= (b[i++] & 0xff) << 8;
-            } else {
-                pad++;
-            }
-            if (i < b.length) {
-                v |= (b[i++] & 0xff);
-            } else {
-                pad++;
-            }
-            sb.append(encode(v >> 18));
-            sb.append(encode(v >> 12));
-            if (pad < 2) {
-                sb.append(encode(v >> 6));
-            } else {
-                sb.append('=');
-            }
-            if (pad < 1) {
-                sb.append(encode(v));
-            } else {
-                sb.append('=');
-            }
-        }
-        return sb.toString();
-    }
-
-    static final private char encode(int i) {
-        i &= 0x3f;
-        if (i < 26) {
-            return (char) ('A' + i);
-        }
-        if (i < 52) {
-            return (char) ('a' + i - 26);
-        }
-        if (i < 62) {
-            return (char) ('0' + i - 52);
-        }
-        return i == 62 ? '+' : '/';
-    }
-
-    static public String generateDigest(String idPassword)
-            throws NoSuchAlgorithmException {
-        String parts[] = idPassword.split(":", 2);
-        byte digest[] = MessageDigest.getInstance("SHA1").digest(
-                idPassword.getBytes());
-        return parts[0] + ":" + base64Encode(digest);
-    }
-
-    public KeeperException.Code 
-        handleAuthentication(ServerCnxn cnxn, byte[] authData)
-    {
-        String id = new String(authData);
-        try {
-            String digest = generateDigest(id);
-            if (digest.equals(superDigest)) {
-                cnxn.addAuthInfo(new Id("super", ""));
-            }
-            cnxn.addAuthInfo(new Id(getScheme(), digest));
-            return KeeperException.Code.OK;
-        } catch (NoSuchAlgorithmException e) {
-            LOG.error("Missing algorithm",e);
-        }
-        return KeeperException.Code.AUTHFAILED;
-    }
-
-    public boolean isAuthenticated() {
-        return true;
-    }
-
-    public boolean isValid(String id) {
-        String parts[] = id.split(":");
-        return parts.length == 2;
-    }
-
-    public boolean matches(String id, String aclExpr) {
-        return id.equals(aclExpr);
-    }
-
-    /** Call with a single argument of user:pass to generate authdata.
-     * Authdata output can be used when setting superDigest for example. 
-     * @param args single argument of user:pass
-     * @throws NoSuchAlgorithmException
-     */
-    public static void main(String args[]) throws NoSuchAlgorithmException {
-        for (int i = 0; i < args.length; i++) {
-            System.out.println(args[i] + "->" + generateDigest(args[i]));
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java b/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java
deleted file mode 100644
index 955c728..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/DigestLoginModule.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.spi.LoginModule;
-import java.util.Map;
-
-public class DigestLoginModule implements LoginModule {
-    private Subject subject;
-
-    public boolean abort() {
-        return false;
-    }
-
-    public boolean commit() {
-        return true;
-    }
-
-    public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options) {
-        if (options.containsKey("username")) {
-            // Zookeeper client: get username and password from JAAS conf (only used if using DIGEST-MD5).
-            this.subject = subject;
-            String username = (String)options.get("username");
-            this.subject.getPublicCredentials().add((Object)username);
-            String password = (String)options.get("password");
-            this.subject.getPrivateCredentials().add((Object)password);
-        }
-        return;
-    }
-
-    public boolean logout() {
-        return true;
-    }
-
-    public boolean login() {
-        // Unlike with Krb5LoginModule, we don't do any actual login or credential passing here: authentication to Zookeeper
-        // is done later, through the SASLClient object.
-        return true;
-    }
-
-}
-
-

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java
deleted file mode 100644
index 6f2a81d..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/IPAuthenticationProvider.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.data.Id;
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class IPAuthenticationProvider implements AuthenticationProvider {
-
-    public String getScheme() {
-        return "ip";
-    }
-
-    public KeeperException.Code
-        handleAuthentication(ServerCnxn cnxn, byte[] authData)
-    {
-        String id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress();
-        cnxn.addAuthInfo(new Id(getScheme(), id));
-        return KeeperException.Code.OK;
-    }
-
-    // This is a bit weird but we need to return the address and the number of
-    // bytes (to distinguish between IPv4 and IPv6
-    private byte[] addr2Bytes(String addr) {
-        byte b[] = v4addr2Bytes(addr);
-        // TODO Write the v6addr2Bytes
-        return b;
-    }
-
-    private byte[] v4addr2Bytes(String addr) {
-        String parts[] = addr.split("\\.", -1);
-        if (parts.length != 4) {
-            return null;
-        }
-        byte b[] = new byte[4];
-        for (int i = 0; i < 4; i++) {
-            try {
-                int v = Integer.parseInt(parts[i]);
-                if (v >= 0 && v <= 255) {
-                    b[i] = (byte) v;
-                } else {
-                    return null;
-                }
-            } catch (NumberFormatException e) {
-                return null;
-            }
-        }
-        return b;
-    }
-
-    private void mask(byte b[], int bits) {
-        int start = bits / 8;
-        int startMask = (1 << (8 - (bits % 8))) - 1;
-        startMask = ~startMask;
-        while (start < b.length) {
-            b[start] &= startMask;
-            startMask = 0;
-            start++;
-        }
-    }
-
-    public boolean matches(String id, String aclExpr) {
-        String parts[] = aclExpr.split("/", 2);
-        byte aclAddr[] = addr2Bytes(parts[0]);
-        if (aclAddr == null) {
-            return false;
-        }
-        int bits = aclAddr.length * 8;
-        if (parts.length == 2) {
-            try {
-                bits = Integer.parseInt(parts[1]);
-                if (bits < 0 || bits > aclAddr.length * 8) {
-                    return false;
-                }
-            } catch (NumberFormatException e) {
-                return false;
-            }
-        }
-        mask(aclAddr, bits);
-        byte remoteAddr[] = addr2Bytes(id);
-        if (remoteAddr == null) {
-            return false;
-        }
-        mask(remoteAddr, bits);
-        for (int i = 0; i < remoteAddr.length; i++) {
-            if (remoteAddr[i] != aclAddr[i]) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    public boolean isAuthenticated() {
-        return false;
-    }
-
-    public boolean isValid(String id) {
-        String parts[] = id.split("/", 2);
-        byte aclAddr[] = addr2Bytes(parts[0]);
-        if (aclAddr == null) {
-            return false;
-        }
-        if (parts.length == 2) {
-            try {
-                int bits = Integer.parseInt(parts[1]);
-                if (bits < 0 || bits > aclAddr.length * 8) {
-                    return false;
-                }
-            } catch (NumberFormatException e) {
-                return false;
-            }
-        }
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java b/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
deleted file mode 100644
index 01d1f66..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
+++ /dev/null
@@ -1,418 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- /* This file copied from Hadoop's security branch,
-  * with the following changes:
-  * 1. package changed from org.apache.hadoop.security to
-  *    org.apache.zookeeper.server.auth.
-  * 2. Usage of Hadoop's Configuration class removed since
-  *    it is not available in Zookeeper: instead, system property
-  *    "zookeeper.security.auth_to_local" is used.
-  */
-
-package org.apache.zookeeper.server.auth;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.zookeeper.server.util.KerberosUtil;
-
-/**
- * This class implements parsing and handling of Kerberos principal names. In 
- * particular, it splits them apart and translates them down into local
- * operating system names.
- */
-public class KerberosName {
-  /** The first component of the name */
-  private final String serviceName;
-  /** The second component of the name. It may be null. */
-  private final String hostName;
-  /** The realm of the name. */
-  private final String realm;
-
-  /**
-   * A pattern that matches a Kerberos name with at most 2 components.
-   */
-  private static final Pattern nameParser = 
-    Pattern.compile("([^/@]*)(/([^/@]*))?@([^/@]*)");
-
-  /** 
-   * A pattern that matches a string with out '$' and then a single
-   * parameter with $n.
-   */
-  private static Pattern parameterPattern = 
-    Pattern.compile("([^$]*)(\\$(\\d*))?");
-
-  /**
-   * A pattern for parsing a auth_to_local rule.
-   */
-  private static final Pattern ruleParser =
-    Pattern.compile("\\s*((DEFAULT)|(RULE:\\[(\\d*):([^\\]]*)](\\(([^)]*)\\))?"+
-                    "(s/([^/]*)/([^/]*)/(g)?)?))");
-  
-  /**
-   * A pattern that recognizes simple/non-simple names.
-   */
-  private static final Pattern nonSimplePattern = Pattern.compile("[/@]");
-  
-  /**
-   * The list of translation rules.
-   */
-  private static List<Rule> rules;
-
-  private static String defaultRealm;
-  
-  static {
-    try {
-      defaultRealm = KerberosUtil.getDefaultRealm();
-    } catch (Exception ke) {
-      if ((System.getProperty("zookeeper.requireKerberosConfig") != null) &&
-          (System.getProperty("zookeeper.requireKerberosConfig").equals("true"))) {
-        throw new IllegalArgumentException("Can't get Kerberos configuration",ke);
-      }
-      else
-        defaultRealm="";
-    }
-    try {
-      // setConfiguration() will work even if the above try() fails due
-      // to a missing Kerberos configuration (unless zookeeper.requireKerberosConfig
-      // is set to true, which would not allow execution to reach here due to the
-      // throwing of an IllegalArgumentException above).
-      setConfiguration();
-    }
-    catch (IOException e) {
-      throw new IllegalArgumentException("Could not configure Kerberos principal name mapping.");
-    }
-  }
-
-  /**
-   * Create a name from the full Kerberos principal name.
-   * @param name
-   */
-  public KerberosName(String name) {
-    Matcher match = nameParser.matcher(name);
-    if (!match.matches()) {
-      if (name.contains("@")) {
-        throw new IllegalArgumentException("Malformed Kerberos name: " + name);
-      } else {
-        serviceName = name;
-        hostName = null;
-        realm = null;
-      }
-    } else {
-      serviceName = match.group(1);
-      hostName = match.group(3);
-      realm = match.group(4);
-    }
-  }
-
-  /**
-   * Get the configured default realm.
-   * @return the default realm from the krb5.conf
-   */
-  public String getDefaultRealm() {
-    return defaultRealm;
-  }
-
-  /**
-   * Put the name back together from the parts.
-   */
-  @Override
-  public String toString() {
-    StringBuilder result = new StringBuilder();
-    result.append(serviceName);
-    if (hostName != null) {
-      result.append('/');
-      result.append(hostName);
-    }
-    if (realm != null) {
-      result.append('@');
-      result.append(realm);
-    }
-    return result.toString();
-  }
-
-  /**
-   * Get the first component of the name.
-   * @return the first section of the Kerberos principal name
-   */
-  public String getServiceName() {
-    return serviceName;
-  }
-
-  /**
-   * Get the second component of the name.
-   * @return the second section of the Kerberos principal name, and may be null
-   */
-  public String getHostName() {
-    return hostName;
-  }
-  
-  /**
-   * Get the realm of the name.
-   * @return the realm of the name, may be null
-   */
-  public String getRealm() {
-    return realm;
-  }
-  
-  /**
-   * An encoding of a rule for translating kerberos names.
-   */
-  private static class Rule {
-    private final boolean isDefault;
-    private final int numOfComponents;
-    private final String format;
-    private final Pattern match;
-    private final Pattern fromPattern;
-    private final String toPattern;
-    private final boolean repeat;
-
-    Rule() {
-      isDefault = true;
-      numOfComponents = 0;
-      format = null;
-      match = null;
-      fromPattern = null;
-      toPattern = null;
-      repeat = false;
-    }
-
-    Rule(int numOfComponents, String format, String match, String fromPattern,
-         String toPattern, boolean repeat) {
-      isDefault = false;
-      this.numOfComponents = numOfComponents;
-      this.format = format;
-      this.match = match == null ? null : Pattern.compile(match);
-      this.fromPattern = 
-        fromPattern == null ? null : Pattern.compile(fromPattern);
-      this.toPattern = toPattern;
-      this.repeat = repeat;
-    }
-    
-    @Override
-    public String toString() {
-      StringBuilder buf = new StringBuilder();
-      if (isDefault) {
-        buf.append("DEFAULT");
-      } else {
-        buf.append("RULE:[");
-        buf.append(numOfComponents);
-        buf.append(':');
-        buf.append(format);
-        buf.append(']');
-        if (match != null) {
-          buf.append('(');
-          buf.append(match);
-          buf.append(')');
-        }
-        if (fromPattern != null) {
-          buf.append("s/");
-          buf.append(fromPattern);
-          buf.append('/');
-          buf.append(toPattern);
-          buf.append('/');
-          if (repeat) {
-            buf.append('g');
-          }
-        }
-      }
-      return buf.toString();
-    }
-    
-    /**
-     * Replace the numbered parameters of the form $n where n is from 1 to 
-     * the length of params. Normal text is copied directly and $n is replaced
-     * by the corresponding parameter.
-     * @param format the string to replace parameters again
-     * @param params the list of parameters
-     * @return the generated string with the parameter references replaced.
-     * @throws BadFormatString
-     */
-    static String replaceParameters(String format, 
-                                    String[] params) throws BadFormatString {
-      Matcher match = parameterPattern.matcher(format);
-      int start = 0;
-      StringBuilder result = new StringBuilder();
-      while (start < format.length() && match.find(start)) {
-        result.append(match.group(1));
-        String paramNum = match.group(3);
-        if (paramNum != null) {
-          try {
-            int num = Integer.parseInt(paramNum);
-            if (num < 0 || num > params.length) {
-              throw new BadFormatString("index " + num + " from " + format +
-                                        " is outside of the valid range 0 to " +
-                                        (params.length - 1));
-            }
-            result.append(params[num]);
-          } catch (NumberFormatException nfe) {
-            throw new BadFormatString("bad format in username mapping in " + 
-                                      paramNum, nfe);
-          }
-          
-        }
-        start = match.end();
-      }
-      return result.toString();
-    }
-
-    /**
-     * Replace the matches of the from pattern in the base string with the value
-     * of the to string.
-     * @param base the string to transform
-     * @param from the pattern to look for in the base string
-     * @param to the string to replace matches of the pattern with
-     * @param repeat whether the substitution should be repeated
-     * @return
-     */
-    static String replaceSubstitution(String base, Pattern from, String to, 
-                                      boolean repeat) {
-      Matcher match = from.matcher(base);
-      if (repeat) {
-        return match.replaceAll(to);
-      } else {
-        return match.replaceFirst(to);
-      }
-    }
-
-    /**
-     * Try to apply this rule to the given name represented as a parameter
-     * array.
-     * @param params first element is the realm, second and later elements are
-     *        are the components of the name "a/b@FOO" -> {"FOO", "a", "b"}
-     * @return the short name if this rule applies or null
-     * @throws IOException throws if something is wrong with the rules
-     */
-    String apply(String[] params) throws IOException {
-      String result = null;
-      if (isDefault) {
-        if (defaultRealm.equals(params[0])) {
-          result = params[1];
-        }
-      } else if (params.length - 1 == numOfComponents) {
-        String base = replaceParameters(format, params);
-        if (match == null || match.matcher(base).matches()) {
-          if (fromPattern == null) {
-            result = base;
-          } else {
-            result = replaceSubstitution(base, fromPattern, toPattern,  repeat);
-          }
-        }
-      }
-      if (result != null && nonSimplePattern.matcher(result).find()) {
-        throw new NoMatchingRule("Non-simple name " + result +
-                                 " after auth_to_local rule " + this);
-      }
-      return result;
-    }
-  }
-
-  static List<Rule> parseRules(String rules) {
-    List<Rule> result = new ArrayList<Rule>();
-    String remaining = rules.trim();
-    while (remaining.length() > 0) {
-      Matcher matcher = ruleParser.matcher(remaining);
-      if (!matcher.lookingAt()) {
-        throw new IllegalArgumentException("Invalid rule: " + remaining);
-      }
-      if (matcher.group(2) != null) {
-        result.add(new Rule());
-      } else {
-        result.add(new Rule(Integer.parseInt(matcher.group(4)),
-                            matcher.group(5),
-                            matcher.group(7),
-                            matcher.group(9),
-                            matcher.group(10),
-                            "g".equals(matcher.group(11))));
-      }
-      remaining = remaining.substring(matcher.end());
-    }
-    return result;
-  }
-
-  /**
-   * Set the static configuration to get the rules.
-   * @param conf the new configuration
-   * @throws IOException
-   */
-  public static void setConfiguration() throws IOException {
-    String ruleString = System.getProperty("zookeeper.security.auth_to_local", "DEFAULT");
-    rules = parseRules(ruleString);
-  }
-
-  @SuppressWarnings("serial")
-  public static class BadFormatString extends IOException {
-    BadFormatString(String msg) {
-      super(msg);
-    }
-    BadFormatString(String msg, Throwable err) {
-      super(msg, err);
-    }
-  }
-
-  @SuppressWarnings("serial")
-  public static class NoMatchingRule extends IOException {
-    NoMatchingRule(String msg) {
-      super(msg);
-    }
-  }
-
-  /**
-   * Get the translation of the principal name into an operating system
-   * user name.
-   * @return the short name
-   * @throws IOException
-   */
-  public String getShortName() throws IOException {
-    String[] params;
-    if (hostName == null) {
-      // if it is already simple, just return it
-      if (realm == null) {
-        return serviceName;
-      }
-      params = new String[]{realm, serviceName};
-    } else {
-      params = new String[]{realm, serviceName, hostName};
-    }
-    for(Rule r: rules) {
-      String result = r.apply(params);
-      if (result != null) {
-        return result;
-      }
-    }
-    throw new NoMatchingRule("No rules applied to " + toString());
-  }
-
-  static void printRules() throws IOException {
-    int i = 0;
-    for(Rule r: rules) {
-      System.out.println(++i + " " + r);
-    }
-  }
-
-  public static void main(String[] args) throws Exception {
-    for(String arg: args) {
-      KerberosName name = new KerberosName(arg);
-      System.out.println("Name: " + name + " to " + name.getShortName());
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/KeyAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/KeyAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/KeyAuthenticationProvider.java
deleted file mode 100644
index 25dc9f3..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/KeyAuthenticationProvider.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import java.io.UnsupportedEncodingException;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.apache.zookeeper.data.Id;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.apache.zookeeper.server.ZKDatabase;
-import org.apache.zookeeper.data.Stat;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * This class is a sample implementation of being passed the ZooKeeperServer
- * handle in the constructor, and reading data from zknodes to authenticate.
- * At a minimum, a real Auth provider would need to override validate() to
- * e.g. perform certificate validation of auth based a public key.
- *
- * See the "Pluggable ZooKeeper authentication" section of the 
- * "Zookeeper Programmer's Guide" for general details of implementing an
- * authentication plugin. e.g.
- * http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html#sc_ZooKeeperPluggableAuthentication
- *
- * This class looks for a numeric "key" under the /key node.
- * Authorizaton is granted if the user passes in as authorization a number
- * which is a multiple of the key value, i.e. 
- *   (auth % key) == 0
- * In a real implementation, you might do something like storing a public
- * key in /key, and using it to verify that auth tokens passed in were signed
- * by the corresponding private key.
- *
- * When the node /key does not exist, any auth token is accepted, so that 
- * bootstrapping may occur.
- *
- */
-public class KeyAuthenticationProvider extends ServerAuthenticationProvider {
-    private static final Logger LOG = LoggerFactory.getLogger(KeyAuthenticationProvider.class);
-
-    public String getScheme() {
-        return "key";
-    }
-
-    private byte[] getKey(ZooKeeperServer zks) {
-        ZKDatabase db = zks.getZKDatabase();
-        if (db != null) {
-            try {
-                Stat stat = new Stat();
-                return db.getData("/key", stat, null);
-            } catch (NoNodeException e) {
-                LOG.error("getData failed", e);
-            }
-        }
-        return null;
-    }
-
-    private boolean validate(byte[] key, byte[] auth) {
-        // perform arbitrary function (auth is a multiple of key)
-        try {
-            String keyStr = new String(key, "UTF-8");
-            String authStr = new String(auth, "UTF-8");
-            int keyVal = Integer.parseInt(keyStr);
-            int authVal = Integer.parseInt(authStr);
-            if (keyVal!=0 && ((authVal % keyVal) != 0)) {
-              return false;
-            }
-        } catch (NumberFormatException | UnsupportedEncodingException nfe) {
-            LOG.error("bad formatting", nfe);
-          return false;
-        }
-        return true;
-    }
-
-    @Override
-    public KeeperException.Code handleAuthentication(ServerObjs serverObjs, byte[] authData) {
-        byte[] key = getKey(serverObjs.getZks());
-        String authStr = "";
-        String keyStr = "";
-        try {
-          authStr = new String(authData, "UTF-8");
-        } catch (Exception e) {
-            LOG.error("UTF-8", e);
-        }
-        if (key != null) {
-            if (!validate(key, authData)) {
-                try {
-                  keyStr = new String(key, "UTF-8");
-                } catch (Exception e) {
-                    LOG.error("UTF-8", e);
-                    // empty key
-                    keyStr = authStr;
-                }
-                LOG.debug("KeyAuthenticationProvider handleAuthentication ("+keyStr+", "+authStr+") -> FAIL.\n");
-                return KeeperException.Code.AUTHFAILED;
-            }
-        }
-        // default to allow, so the key can be initially written
-        LOG.debug("KeyAuthenticationProvider handleAuthentication -> OK.\n");
-        // NOTE: keyStr in addAuthInfo() sticks with the created node ACLs.
-        //   For transient keys or certificates, this presents a problem.
-        //   In that case, replace it with something non-ephemeral (or punt with null).
-        //
-        // BOTH addAuthInfo and an OK return-code are needed for authentication.
-        serverObjs.getCnxn().addAuthInfo(new Id(getScheme(), keyStr));
-        return KeeperException.Code.OK;
-    }
-
-    @Override
-    public boolean matches(ServerObjs serverObjs, MatchValues matchValues) {
-        return matchValues.getId().equals(matchValues.getAclExpr());
-    }
-
-    @Override
-    public boolean isAuthenticated() {
-        return true;
-    }
-
-    @Override
-    public boolean isValid(String id) {
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java b/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java
deleted file mode 100644
index ed69f92..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/ProviderRegistry.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.zookeeper.server.ZooKeeperServer;
-
-public class ProviderRegistry {
-    private static final Logger LOG = LoggerFactory.getLogger(ProviderRegistry.class);
-
-    private static boolean initialized = false;
-    private static Map<String, AuthenticationProvider> authenticationProviders =
-        new HashMap<>();
-
-    //VisibleForTesting
-    public static void reset() {
-        synchronized (ProviderRegistry.class) {
-            initialized = false;
-            authenticationProviders.clear();
-        }
-    }
-
-    public static void initialize() {
-        synchronized (ProviderRegistry.class) {
-            if (initialized)
-                return;
-            IPAuthenticationProvider ipp = new IPAuthenticationProvider();
-            DigestAuthenticationProvider digp = new DigestAuthenticationProvider();
-            authenticationProviders.put(ipp.getScheme(), ipp);
-            authenticationProviders.put(digp.getScheme(), digp);
-            Enumeration<Object> en = System.getProperties().keys();
-            while (en.hasMoreElements()) {
-                String k = (String) en.nextElement();
-                if (k.startsWith("zookeeper.authProvider.")) {
-                    String className = System.getProperty(k);
-                    try {
-                        Class<?> c = ZooKeeperServer.class.getClassLoader()
-                                .loadClass(className);
-                        AuthenticationProvider ap = (AuthenticationProvider) c.getDeclaredConstructor()
-                                .newInstance();
-                        authenticationProviders.put(ap.getScheme(), ap);
-                    } catch (Exception e) {
-                        LOG.warn("Problems loading " + className,e);
-                    }
-                }
-            }
-            initialized = true;
-        }
-    }
-
-    public static ServerAuthenticationProvider getServerProvider(String scheme) {
-        return WrappedAuthenticationProvider.wrap(getProvider(scheme));
-    }
-
-    public static AuthenticationProvider getProvider(String scheme) {
-        if(!initialized)
-            initialize();
-        return authenticationProviders.get(scheme);
-    }
-
-    public static String listProviders() {
-        StringBuilder sb = new StringBuilder();
-        for(String s: authenticationProviders.keySet()) {
-            sb.append(s).append(" ");
-        }
-        return sb.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java
deleted file mode 100644
index 1f60b39..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/SASLAuthenticationProvider.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class SASLAuthenticationProvider implements AuthenticationProvider {
-
-    public String getScheme() {
-        return "sasl";
-    }
-
-    public KeeperException.Code
-        handleAuthentication(ServerCnxn cnxn, byte[] authData)
-    {
-        // Should never call this: SASL authentication is negotiated at session initiation.
-        // TODO: consider substituting current implementation of direct ClientCnxn manipulation with
-        // a call to this method (SASLAuthenticationProvider:handleAuthentication()) at session initiation.
-        return KeeperException.Code.AUTHFAILED;
-
-    }
-
-    public boolean matches(String id,String aclExpr) {
-        if ((id.equals("super") || id.equals(aclExpr))) {
-          return true;
-        }
-        String readAccessUser = System.getProperty("zookeeper.letAnySaslUserDoX");
-        if ( readAccessUser != null && aclExpr.equals(readAccessUser)) {
-          return true;
-        }
-        return false;
-    }
-
-    public boolean isAuthenticated() {
-        return true;
-    }
-
-    public boolean isValid(String id) {
-        // Since the SASL authenticator will usually be used with Kerberos authentication,
-        // it should enforce that these names are valid according to Kerberos's
-        // syntax for principals.
-        //
-        // Use the KerberosName(id) constructor to define validity:
-        // if KerberosName(id) throws IllegalArgumentException, then id is invalid.
-        // otherwise, it is valid.
-        //
-        try {
-            new KerberosName(id);
-            return true;
-        }
-        catch (IllegalArgumentException e) {
-            return false;
-        }
-   }
-
-
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java b/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java
deleted file mode 100644
index 9f53a4d..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/SaslServerCallbackHandler.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-import javax.security.sasl.AuthorizeCallback;
-import javax.security.sasl.RealmCallback;
-
-import org.apache.zookeeper.server.ZooKeeperSaslServer;
-
-public class SaslServerCallbackHandler implements CallbackHandler {
-    private static final String USER_PREFIX = "user_";
-    private static final Logger LOG = LoggerFactory.getLogger(SaslServerCallbackHandler.class);
-    private static final String SYSPROP_SUPER_PASSWORD = "zookeeper.SASLAuthenticationProvider.superPassword";
-    private static final String SYSPROP_REMOVE_HOST = "zookeeper.kerberos.removeHostFromPrincipal";
-    private static final String SYSPROP_REMOVE_REALM = "zookeeper.kerberos.removeRealmFromPrincipal";
-
-    private String userName;
-    private final Map<String,String> credentials = new HashMap<String,String>();
-
-    public SaslServerCallbackHandler(Configuration configuration)
-            throws IOException {
-        String serverSection = System.getProperty(
-                ZooKeeperSaslServer.LOGIN_CONTEXT_NAME_KEY,
-                ZooKeeperSaslServer.DEFAULT_LOGIN_CONTEXT_NAME);
-        AppConfigurationEntry configurationEntries[] = configuration.getAppConfigurationEntry(serverSection);
-
-        if (configurationEntries == null) {
-            String errorMessage = "Could not find a '" + serverSection + "' entry in this configuration: Server cannot start.";
-            LOG.error(errorMessage);
-            throw new IOException(errorMessage);
-        }
-        credentials.clear();
-        for(AppConfigurationEntry entry: configurationEntries) {
-            Map<String,?> options = entry.getOptions();
-            // Populate DIGEST-MD5 user -> password map with JAAS configuration entries from the "Server" section.
-            // Usernames are distinguished from other options by prefixing the username with a "user_" prefix.
-            for(Map.Entry<String, ?> pair : options.entrySet()) {
-                String key = pair.getKey();
-                if (key.startsWith(USER_PREFIX)) {
-                    String userName = key.substring(USER_PREFIX.length());
-                    credentials.put(userName,(String)pair.getValue());
-                }
-            }
-        }
-    }
-
-    public void handle(Callback[] callbacks) throws UnsupportedCallbackException {
-        for (Callback callback : callbacks) {
-            if (callback instanceof NameCallback) {
-                handleNameCallback((NameCallback) callback);
-            } else if (callback instanceof PasswordCallback) {
-                handlePasswordCallback((PasswordCallback) callback);
-            } else if (callback instanceof RealmCallback) {
-                handleRealmCallback((RealmCallback) callback);
-            } else if (callback instanceof AuthorizeCallback) {
-                handleAuthorizeCallback((AuthorizeCallback) callback);
-            }
-        }
-    }
-
-    private void handleNameCallback(NameCallback nc) {
-        // check to see if this user is in the user password database.
-        if (credentials.get(nc.getDefaultName()) == null) {
-            LOG.warn("User '" + nc.getDefaultName() + "' not found in list of DIGEST-MD5 authenticateable users.");
-            return;
-        }
-        nc.setName(nc.getDefaultName());
-        userName = nc.getDefaultName();
-    }
-
-    private void handlePasswordCallback(PasswordCallback pc) {
-        if ("super".equals(this.userName) && System.getProperty(SYSPROP_SUPER_PASSWORD) != null) {
-            // superuser: use Java system property for password, if available.
-            pc.setPassword(System.getProperty(SYSPROP_SUPER_PASSWORD).toCharArray());
-        } else if (credentials.containsKey(userName) ) {
-            pc.setPassword(credentials.get(userName).toCharArray());
-        } else {
-            LOG.warn("No password found for user: " + userName);
-        }
-    }
-
-    private void handleRealmCallback(RealmCallback rc) {
-        LOG.debug("client supplied realm: " + rc.getDefaultText());
-        rc.setText(rc.getDefaultText());
-    }
-
-    private void handleAuthorizeCallback(AuthorizeCallback ac) {
-        String authenticationID = ac.getAuthenticationID();
-        String authorizationID = ac.getAuthorizationID();
-
-        LOG.info("Successfully authenticated client: authenticationID=" + authenticationID
-                + ";  authorizationID=" + authorizationID + ".");
-        ac.setAuthorized(true);
-
-        // canonicalize authorization id according to system properties:
-        // zookeeper.kerberos.removeRealmFromPrincipal(={true,false})
-        // zookeeper.kerberos.removeHostFromPrincipal(={true,false})
-        KerberosName kerberosName = new KerberosName(authenticationID);
-        try {
-            StringBuilder userNameBuilder = new StringBuilder(kerberosName.getShortName());
-            if (shouldAppendHost(kerberosName)) {
-                userNameBuilder.append("/").append(kerberosName.getHostName());
-            }
-            if (shouldAppendRealm(kerberosName)) {
-                userNameBuilder.append("@").append(kerberosName.getRealm());
-            }
-            LOG.info("Setting authorizedID: " + userNameBuilder);
-            ac.setAuthorizedID(userNameBuilder.toString());
-        } catch (IOException e) {
-            LOG.error("Failed to set name based on Kerberos authentication rules.", e);
-        }
-    }
-
-    private boolean shouldAppendRealm(KerberosName kerberosName) {
-        return !isSystemPropertyTrue(SYSPROP_REMOVE_REALM) && kerberosName.getRealm() != null;
-    }
-
-    private boolean shouldAppendHost(KerberosName kerberosName) {
-        return !isSystemPropertyTrue(SYSPROP_REMOVE_HOST) && kerberosName.getHostName() != null;
-    }
-
-    private boolean isSystemPropertyTrue(String propertyName) {
-        return "true".equals(System.getProperty(propertyName));
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/ServerAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/ServerAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/ServerAuthenticationProvider.java
deleted file mode 100644
index 6264d8c..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/ServerAuthenticationProvider.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.data.ACL;
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ZooKeeperServer;
-
-import java.util.List;
-
-/**
- * A variation on {@link AuthenticationProvider} that provides additional
- * parameters for more detailed authentication
- */
-public abstract class ServerAuthenticationProvider implements AuthenticationProvider {
-    public static class ServerObjs {
-        private final ZooKeeperServer zks;
-        private final ServerCnxn cnxn;
-
-        /**
-         * @param zks
-         *                the ZooKeeper server instance
-         * @param cnxn
-         *                the cnxn that received the authentication information.
-         */
-        public ServerObjs(ZooKeeperServer zks, ServerCnxn cnxn) {
-            this.zks = zks;
-            this.cnxn = cnxn;
-        }
-
-        public ZooKeeperServer getZks() {
-            return zks;
-        }
-
-        public ServerCnxn getCnxn() {
-            return cnxn;
-        }
-    }
-
-    public static class MatchValues {
-        private final String path;
-        private final String id;
-        private final String aclExpr;
-        private final int perm;
-        private final List<ACL> setAcls;
-
-        /**
-         * @param path
-         *                the path of the operation being authenticated
-         * @param id
-         *                the id to check.
-         * @param aclExpr
-         *                the expression to match ids against.
-         * @param perm
-         *                the permission value being authenticated
-         * @param setAcls
-         *                for set ACL operations, the list of ACLs being set. Otherwise null.
-         */
-        public MatchValues(String path, String id, String aclExpr, int perm, List<ACL> setAcls) {
-            this.path = path;
-            this.id = id;
-            this.aclExpr = aclExpr;
-            this.perm = perm;
-            this.setAcls = setAcls;
-        }
-
-        public String getPath() {
-            return path;
-        }
-
-        public String getId() {
-            return id;
-        }
-
-        public String getAclExpr() {
-            return aclExpr;
-        }
-
-        public int getPerm() {
-            return perm;
-        }
-
-        public List<ACL> getSetAcls() {
-            return setAcls;
-        }
-    }
-
-    /**
-     * This method is called when a client passes authentication data for this
-     * scheme. The authData is directly from the authentication packet. The
-     * implementor may attach new ids to the authInfo field of cnxn or may use
-     * cnxn to send packets back to the client.
-     *
-     * @param serverObjs
-     *                cnxn/server/etc that received the authentication information.
-     * @param authData
-     *                the authentication data received.
-     * @return indication of success or failure
-     */
-    public abstract KeeperException.Code handleAuthentication(ServerObjs serverObjs, byte authData[]);
-
-    /**
-     * This method is called to see if the given id matches the given id
-     * expression in the ACL. This allows schemes to use application specific
-     * wild cards.
-     *
-     * @param serverObjs
-     *                cnxn/server/etc that received the authentication information.
-     * @param matchValues
-     *                values to be matched
-     */
-    public abstract boolean matches(ServerObjs serverObjs, MatchValues matchValues);
-
-    @Override
-    public final KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public final boolean matches(String id, String aclExpr) {
-        throw new UnsupportedOperationException();
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/WrappedAuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/WrappedAuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/WrappedAuthenticationProvider.java
deleted file mode 100644
index 7b9991f..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/WrappedAuthenticationProvider.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.server.ServerCnxn;
-
-/**
- * Provides backwards compatibility between older {@link AuthenticationProvider}
- * implementations and the new {@link ServerAuthenticationProvider} interface.
- */
-class WrappedAuthenticationProvider extends ServerAuthenticationProvider {
-    private final AuthenticationProvider implementation;
-
-    static ServerAuthenticationProvider wrap(AuthenticationProvider provider) {
-        if (provider == null) {
-            return null;
-        }
-        return (provider instanceof ServerAuthenticationProvider) ? (ServerAuthenticationProvider)provider
-                : new WrappedAuthenticationProvider(provider);
-    }
-
-    private WrappedAuthenticationProvider(AuthenticationProvider implementation) {
-        this.implementation = implementation;
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * forwards to older method {@link #handleAuthentication(ServerCnxn, byte[])}
-     */
-    @Override
-    public KeeperException.Code handleAuthentication(ServerObjs serverObjs, byte[] authData) {
-        return implementation.handleAuthentication(serverObjs.getCnxn(), authData);
-    }
-
-    /**
-     * {@inheritDoc}
-     *
-     * forwards to older method {@link #matches(String, String)}
-     */
-    @Override
-    public boolean matches(ServerObjs serverObjs, MatchValues matchValues) {
-        return implementation.matches(matchValues.getId(), matchValues.getAclExpr());
-    }
-
-    @Override
-    public String getScheme() {
-        return implementation.getScheme();
-    }
-
-    @Override
-    public boolean isAuthenticated() {
-        return implementation.isAuthenticated();
-    }
-
-    @Override
-    public boolean isValid(String id) {
-        return implementation.isValid(id);
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java b/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java
deleted file mode 100644
index 93bc8fc..0000000
--- a/src/java/main/org/apache/zookeeper/server/auth/X509AuthenticationProvider.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.auth;
-
-import java.security.cert.CertificateException;
-import java.security.cert.X509Certificate;
-
-import javax.net.ssl.X509KeyManager;
-import javax.net.ssl.X509TrustManager;
-import javax.security.auth.x500.X500Principal;
-
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.common.ZKConfig;
-import org.apache.zookeeper.common.X509Exception;
-import org.apache.zookeeper.common.X509Exception.KeyManagerException;
-import org.apache.zookeeper.common.X509Exception.TrustManagerException;
-import org.apache.zookeeper.common.X509Util;
-import org.apache.zookeeper.data.Id;
-import org.apache.zookeeper.server.ServerCnxn;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * An AuthenticationProvider backed by an X509TrustManager and an X509KeyManager
- * to perform remote host certificate authentication. The default algorithm is
- * SunX509 and a JKS KeyStore. To specify the locations of the key store and
- * trust store, set the following system properties:
- * <br/><code>zookeeper.ssl.keyStore.location</code>
- * <br/><code>zookeeper.ssl.trustStore.location</code>
- * <br/>To specify store passwords, set the following system properties:
- * <br/><code>zookeeper.ssl.keyStore.password</code>
- * <br/><code>zookeeper.ssl.trustStore.password</code>
- * <br/>Alternatively, this can be plugged with any X509TrustManager and
- * X509KeyManager implementation.
- */
-public class X509AuthenticationProvider implements AuthenticationProvider {
-    static final String ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER
-            = "zookeeper.X509AuthenticationProvider.superUser";
-    private static final Logger LOG
-            = LoggerFactory.getLogger(X509AuthenticationProvider.class);
-    private final X509TrustManager trustManager;
-    private final X509KeyManager keyManager;
-
-    /**
-     * Initialize the X509AuthenticationProvider with a JKS KeyStore and JKS
-     * TrustStore according to the following system properties:
-     * <br/><code>zookeeper.ssl.keyStore.location</code>
-     * <br/><code>zookeeper.ssl.trustStore.location</code>
-     * <br/><code>zookeeper.ssl.keyStore.password</code>
-     * <br/><code>zookeeper.ssl.trustStore.password</code>
-     */
-    public X509AuthenticationProvider() throws X509Exception {
-        String keyStoreLocationProp = System.getProperty(
-                ZKConfig.SSL_KEYSTORE_LOCATION);
-        String keyStorePasswordProp = System.getProperty(
-                ZKConfig.SSL_KEYSTORE_PASSWD);
-
-        X509KeyManager km = null;
-        X509TrustManager tm = null;
-        if (keyStoreLocationProp == null && keyStorePasswordProp == null) {
-            LOG.warn("keystore not specified for client connection");
-        } else {
-            if (keyStoreLocationProp == null) {
-                throw new X509Exception("keystore location not specified for client connection");
-            }
-            if (keyStorePasswordProp == null) {
-                throw new X509Exception("keystore password not specified for client connection");
-            }
-            try {
-                km = X509Util.createKeyManager(
-                        keyStoreLocationProp, keyStorePasswordProp);
-            } catch (KeyManagerException e) {
-                LOG.error("Failed to create key manager", e);
-            }
-        }
-        
-        String trustStoreLocationProp = System.getProperty(
-                ZKConfig.SSL_TRUSTSTORE_LOCATION);
-        String trustStorePasswordProp = System.getProperty(
-                ZKConfig.SSL_TRUSTSTORE_PASSWD);
-
-        if (trustStoreLocationProp == null && trustStorePasswordProp == null) {
-            LOG.warn("Truststore not specified for client connection");
-        } else {
-            if (trustStoreLocationProp == null) {
-                throw new X509Exception("Truststore location not specified for client connection");
-            }
-            if (trustStorePasswordProp == null) {
-                throw new X509Exception("Truststore password not specified for client connection");
-            }
-            try {
-                tm = X509Util.createTrustManager(
-                        trustStoreLocationProp, trustStorePasswordProp);
-            } catch (TrustManagerException e) {
-                LOG.error("Failed to create trust manager", e);
-            }
-        }
-        this.keyManager = km;
-        this.trustManager = tm;
-    }
-
-    /**
-     * Initialize the X509AuthenticationProvider with the provided
-     * X509TrustManager and X509KeyManager.
-     *
-     * @param trustManager X509TrustManager implementation to use for remote
-     *                     host authentication.
-     * @param keyManager   X509KeyManager implementation to use for certificate
-     *                     management.
-     */
-    public X509AuthenticationProvider(X509TrustManager trustManager,
-                                      X509KeyManager keyManager) {
-        this.trustManager = trustManager;
-        this.keyManager = keyManager;
-    }
-
-    @Override
-    public String getScheme() {
-        return "x509";
-    }
-
-    @Override
-    public KeeperException.Code handleAuthentication(ServerCnxn cnxn,
-                                                     byte[] authData) {
-        X509Certificate[] certChain
-                = (X509Certificate[]) cnxn.getClientCertificateChain();
-
-        if (certChain == null || certChain.length == 0) {
-            return KeeperException.Code.AUTHFAILED;
-        }
-
-        if (trustManager == null) {
-            LOG.error("No trust manager available to authenticate session 0x{}",
-                    Long.toHexString(cnxn.getSessionId()));
-            return KeeperException.Code.AUTHFAILED;
-        }
-
-        X509Certificate clientCert = certChain[0];
-
-        try {
-            // Authenticate client certificate
-            trustManager.checkClientTrusted(certChain,
-                    clientCert.getPublicKey().getAlgorithm());
-        } catch (CertificateException ce) {
-            LOG.error("Failed to trust certificate for session 0x" +
-                    Long.toHexString(cnxn.getSessionId()), ce);
-            return KeeperException.Code.AUTHFAILED;
-        }
-
-        String clientId = getClientId(clientCert);
-
-        if (clientId.equals(System.getProperty(
-                ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER))) {
-            cnxn.addAuthInfo(new Id("super", clientId));
-            LOG.info("Authenticated Id '{}' as super user", clientId);
-        }
-
-        Id authInfo = new Id(getScheme(), clientId);
-        cnxn.addAuthInfo(authInfo);
-
-        LOG.info("Authenticated Id '{}' for Scheme '{}'",
-                authInfo.getId(), authInfo.getScheme());
-        return KeeperException.Code.OK;
-    }
-
-    /**
-     * Determine the string to be used as the remote host session Id for
-     * authorization purposes. Associate this client identifier with a
-     * ServerCnxn that has been authenticated over SSL, and any ACLs that refer
-     * to the authenticated client.
-     *
-     * @param clientCert Authenticated X509Certificate associated with the
-     *                   remote host.
-     * @return Identifier string to be associated with the client.
-     */
-    protected String getClientId(X509Certificate clientCert) {
-        return clientCert.getSubjectX500Principal().getName();
-    }
-
-    @Override
-    public boolean matches(String id, String aclExpr) {
-        if (System.getProperty(ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER) != null) {
-            return (id.equals(System.getProperty(ZOOKEEPER_X509AUTHENTICATIONPROVIDER_SUPERUSER))
-                    || id.equals(aclExpr));
-        }
-
-        return (id.equals(aclExpr));
-    }
-
-    @Override
-    public boolean isAuthenticated() {
-        return true;
-    }
-
-    @Override
-    public boolean isValid(String id) {
-        try {
-            new X500Principal(id);
-            return true;
-        } catch (IllegalArgumentException e) {
-            return false;
-        }
-    }
-
-    /**
-     * Get the X509TrustManager implementation used for remote host
-     * authentication.
-     *
-     * @return The X509TrustManager.
-     * @throws TrustManagerException When there is no trust manager available.
-     */
-    public X509TrustManager getTrustManager() throws TrustManagerException {
-        if (trustManager == null) {
-            throw new TrustManagerException("No trust manager available");
-        }
-        return trustManager;
-    }
-
-    /**
-     * Get the X509KeyManager implementation used for certificate management.
-     *
-     * @return The X509KeyManager.
-     * @throws KeyManagerException When there is no key manager available.
-     */
-    public X509KeyManager getKeyManager() throws KeyManagerException {
-        if (keyManager == null) {
-            throw new KeyManagerException("No key manager available");
-        }
-        return keyManager;
-    }
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java b/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java
deleted file mode 100644
index fe78402..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/AbstractFourLetterCommand.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.command;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-import org.apache.zookeeper.server.ServerCnxnFactory;
-import org.apache.zookeeper.server.ZooKeeperServer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Set of threads for command ports. All the 4 letter commands are run via a
- * thread. Each class maps to a correspoding 4 letter command. CommandThread is
- * the abstract class from which all the others inherit.
- */
-public abstract class AbstractFourLetterCommand {
-    private static final Logger LOG = LoggerFactory
-        .getLogger(AbstractFourLetterCommand.class);
-
-    public static final String ZK_NOT_SERVING = "This ZooKeeper instance is not currently serving requests";
-
-    protected PrintWriter pw;
-    protected ServerCnxn serverCnxn;
-    protected ZooKeeperServer zkServer;
-    protected ServerCnxnFactory factory;
-
-    public AbstractFourLetterCommand(PrintWriter pw, ServerCnxn serverCnxn) {
-        this.pw = pw;
-        this.serverCnxn = serverCnxn;
-    }
-
-    public void start() {
-        run();
-    }
-
-    public void run() {
-        try {
-            commandRun();
-        } catch (IOException ie) {
-            LOG.error("Error in running command ", ie);
-        } finally {
-            serverCnxn.cleanupWriterSocket(pw);
-        }
-    }
-
-    public void setZkServer(ZooKeeperServer zkServer) {
-        this.zkServer = zkServer;
-    }
-
-    /**
-     * @return true if the server is running, false otherwise.
-     */
-    boolean isZKServerRunning() {
-        return zkServer != null && zkServer.isRunning();
-    }
-
-    public void setFactory(ServerCnxnFactory factory) {
-        this.factory = factory;
-    }
-
-    public abstract void commandRun() throws IOException;
-}

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/faa7cec7/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java b/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java
deleted file mode 100644
index 06e82b6..0000000
--- a/src/java/main/org/apache/zookeeper/server/command/CnxnStatResetCommand.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.zookeeper.server.command;
-
-import java.io.PrintWriter;
-
-import org.apache.zookeeper.server.ServerCnxn;
-
-public class CnxnStatResetCommand extends AbstractFourLetterCommand {
-    public CnxnStatResetCommand(PrintWriter pw, ServerCnxn serverCnxn) {
-        super(pw, serverCnxn);
-    }
-
-    @Override
-    public void commandRun() {
-        if (!isZKServerRunning()) {
-            pw.println(ZK_NOT_SERVING);
-        } else {
-            factory.resetAllConnectionStats();
-            pw.println("Connection stats reset.");
-        }
-    }
-}