directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: DIRKRB-714 Replace Jersey client with HttpURLConnection in HasInitClient.
Date Wed, 16 May 2018 06:22:16 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk a09c3432f -> 6cb25114d


DIRKRB-714 Replace Jersey client with HttpURLConnection in HasInitClient.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/6cb25114
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/6cb25114
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/6cb25114

Branch: refs/heads/trunk
Commit: 6cb25114d067ed65333acdccebc862dc811b8852
Parents: a09c343
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Wed May 16 14:22:01 2018 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Wed May 16 14:22:01 2018 +0800

----------------------------------------------------------------------
 has-project/has-client/pom.xml                  |  10 -
 .../kerby/has/client/HasAuthAdminClient.java    | 261 +++------------
 .../org/apache/kerby/has/client/HasClient.java  |  79 ++---
 .../apache/kerby/has/client/HasClientUtil.java  | 126 +++++++
 .../apache/kerby/has/client/HasInitClient.java  | 335 +++++++++++--------
 .../has/common/util/URLConnectionFactory.java   |   2 +-
 .../apache/kerby/has/server/web/ConfFilter.java |   2 +-
 .../kerby/has/server/web/rest/ConfigApi.java    |   4 +-
 .../kerby/has/server/web/rest/InitApi.java      |   3 +-
 .../tool/admin/cmd/DisableConfRemoteCmd.java    |   7 +-
 .../tool/admin/cmd/EnableConfRemoteCmd.java     |   7 +-
 .../tool/admin/cmd/ExportKeytabsRemoteCmd.java  |   7 +-
 .../tool/admin/cmd/ListPrincipalsRemoteCmd.java |   3 +-
 .../tool/init/cmd/GetHasClientConfCmd.java      |  17 +-
 .../kerberos/tool/init/cmd/GetKrb5ConfCmd.java  |  17 +-
 .../kerberos/tool/init/cmd/InitKdcCmd.java      |  23 +-
 .../kerberos/tool/init/cmd/StartKdcCmd.java     |   2 +-
 17 files changed, 411 insertions(+), 494 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-client/pom.xml
----------------------------------------------------------------------
diff --git a/has-project/has-client/pom.xml b/has-project/has-client/pom.xml
index f3a90a7..c8b3468 100644
--- a/has-project/has-client/pom.xml
+++ b/has-project/has-client/pom.xml
@@ -29,16 +29,6 @@
     </dependency>
     <dependency>
       <groupId>com.sun.jersey</groupId>
-      <artifactId>jersey-client</artifactId>
-      <version>${jersey.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.glassfish.jersey.containers</groupId>
-      <artifactId>jersey-container-servlet-core</artifactId>
-      <version>${jersey.container.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-json</artifactId>
       <version>${jersey.version}</version>
     </dependency>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
----------------------------------------------------------------------
diff --git a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
index ec27fb5..e2d74a6 100644
--- a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
+++ b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasAuthAdminClient.java
@@ -21,9 +21,6 @@ package org.apache.kerby.has.client;
 
 import org.apache.kerby.KOptions;
 import org.apache.kerby.has.common.HasConfig;
-import org.apache.kerby.has.common.HasException;
-import org.apache.kerby.has.common.ssl.SSLFactory;
-import org.apache.kerby.has.common.util.URLConnectionFactory;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.kadmin.Kadmin;
 import org.codehaus.jettison.json.JSONArray;
@@ -40,7 +37,6 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
-import java.net.ProtocolException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -59,63 +55,12 @@ public class HasAuthAdminClient implements Kadmin {
         this.hasConfig = hasConfig;
     }
 
-    protected HttpURLConnection getHttpsConnection(URL url, boolean isSpnego) throws Exception {
-        HasConfig conf = new HasConfig();
-
-        conf.setString(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "ALLOW_ALL");
-        String sslClientConf = hasConfig.getSslClientConf();
-        conf.setString(SSLFactory.SSL_CLIENT_CONF_KEY, sslClientConf);
-        conf.setBoolean(SSLFactory.SSL_REQUIRE_CLIENT_CERT_KEY, false);
-
-        URLConnectionFactory connectionFactory = URLConnectionFactory
-            .newDefaultURLConnectionFactory(conf);
-        return (HttpURLConnection) connectionFactory.openConnection(url, isSpnego, hasConfig);
-    }
-
-    /**
-     * Create an authenticated connection to the Has server.
-     * <p>
-     * It uses Hadoop-auth client authentication which by default supports
-     * Kerberos HTTP SPNEGO, Pseudo/Simple and anonymous.
-     *
-     * @param url    the URL to open a HTTP connection to.
-     * @param method the HTTP method for the HTTP connection.
-     * @return an authenticated connection to the has server.
-     * @throws IOException if an IO error occurred.
-     */
-    protected HttpURLConnection createConnection(URL url, String method) {
-        HttpURLConnection conn = null;
-        if (hasConfig.getHttpsPort() != null && hasConfig.getHttpsHost() != null) {
-            try {
-                conn = getHttpsConnection(url, true);
-            } catch (Exception e) {
-                throw new RuntimeException("Error occurred when creating https connection. " + e.getMessage());
-            }
-        }
-        if (method.equals("POST") || method.equals("PUT")) {
-            conn.setDoOutput(true);
-        }
-        return conn;
-    }
-
-    private String getKadminBaseURL() {
-        return getBaseUrl("kadmin");
-    }
-
-    private String getHadminBaseURL() {
-        return getBaseUrl("hadmin");
+    private String getKadminBaseURL() throws KrbException {
+        return HasClientUtil.getBaseUrl(hasConfig, "kadmin");
     }
 
-    private String getBaseUrl(String input) {
-        String url = null;
-        if (hasConfig.getHttpsPort() != null && hasConfig.getHttpsHost() != null) {
-            url = "https://" + hasConfig.getHttpsHost() + ":" + hasConfig.getHttpsPort()
-                + "/has/v1/" + input + "/";
-        }
-        if (url == null) {
-            throw new RuntimeException("Please set the https address and port.");
-        }
-        return url;
+    private String getHadminBaseURL() throws KrbException {
+        return HasClientUtil.getBaseUrl(hasConfig, "hadmin");
     }
 
     @Override
@@ -129,25 +74,15 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object.", e);
         }
 
-        httpConn = createConnection(url, "POST");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "POST", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("POST");
-        } catch (ProtocolException e) {
-            LOG.error("Fail to add principal. " + e);
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
         try {
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                LOG.info(getResponse(httpConn));
+                LOG.info(HasClientUtil.getResponse(httpConn));
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (IOException e) {
             throw new KrbException("IO error occurred.", e);
@@ -166,24 +101,15 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object.", e);
         }
 
-        httpConn = createConnection(url, "POST");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "POST", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
         try {
-            httpConn.setRequestMethod("POST");
-        } catch (ProtocolException e) {
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
-        try {
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                LOG.info(getResponse(httpConn));
+                LOG.info(HasClientUtil.getResponse(httpConn));
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (IOException e) {
             throw new KrbException("IO error occurred.", e);
@@ -192,7 +118,7 @@ public class HasAuthAdminClient implements Kadmin {
 
     @Override
     public void addPrincipal(String principal, String password, KOptions kOptions) throws KrbException {
-
+        throw new KrbException("Unsupported feature");
     }
 
     @Override
@@ -206,22 +132,13 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object.", e);
         }
 
-        httpConn = createConnection(url, "DELETE");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "DELETE", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("DELETE");
-        } catch (ProtocolException e) {
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
         try {
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                LOG.info(getResponse(httpConn));
+                LOG.info(HasClientUtil.getResponse(httpConn));
             } else {
                 throw new KrbException("Connection deined.");
             }
@@ -232,7 +149,7 @@ public class HasAuthAdminClient implements Kadmin {
 
     @Override
     public void modifyPrincipal(String principal, KOptions kOptions) throws KrbException {
-
+        throw new KrbException("Unsupported feature");
     }
 
     @Override
@@ -247,24 +164,15 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object.", e);
         }
 
-        httpConn = createConnection(url, "POST");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "POST", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("POST");
-        } catch (ProtocolException e) {
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
         try {
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                LOG.info(getResponse(httpConn));
+                LOG.info(HasClientUtil.getResponse(httpConn));
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (IOException e) {
             throw new KrbException("IO error occurred.", e);
@@ -281,25 +189,19 @@ public class HasAuthAdminClient implements Kadmin {
         } catch (MalformedURLException e) {
             throw new KrbException("Failed to create a URL object.", e);
         }
+        LOG.info("Remote Admin Url: " + url);
 
-        httpConn = createConnection(url, "GET");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("GET");
-        } catch (ProtocolException e) {
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
         String response;
         try {
             httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                response = getResponse(httpConn);
+                response = HasClientUtil.getResponse(httpConn);
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (IOException e) {
             LOG.error("IO error occurred." + e.getMessage());
@@ -319,26 +221,16 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object. ", e);
         }
 
-        httpConn = createConnection(url, "GET");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("GET");
-        } catch (ProtocolException e) {
-            LOG.error("Failed to set the method for URL request." + e.getMessage());
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
         String response;
         try {
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                response = getResponse(httpConn);
+                response = HasClientUtil.getResponse(httpConn);
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (IOException e) {
             throw new KrbException("IO error occurred.", e);
@@ -379,19 +271,12 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object.", e);
         }
 
-        HttpURLConnection httpConn = createConnection(url, "GET");
-        httpConn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("GET");
-        } catch (ProtocolException e) {
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
-        httpConn.setDoOutput(true);
-        httpConn.setDoInput(true);
+        HttpURLConnection httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", true);
+
         try {
             httpConn.connect();
             if (httpConn.getResponseCode() != 200) {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
             FileOutputStream fos = new FileOutputStream(keytab);
             InputStream in = httpConn.getInputStream();
@@ -419,19 +304,12 @@ public class HasAuthAdminClient implements Kadmin {
             } catch (MalformedURLException e) {
                 throw new KrbException("Failed to create a URL object.");
             }
-            httpConn = createConnection(url, "GET");
-            httpConn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
-            try {
-                httpConn.setRequestMethod("GET");
-            } catch (ProtocolException e) {
-                throw new KrbException("Failed to set the method for URL request.", e);
-            }
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
+            httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", true);
+
             try {
                 httpConn.connect();
                 if (httpConn.getResponseCode() != 200) {
-                    throw new KrbException(getResponse(httpConn));
+                    throw new KrbException(HasClientUtil.getResponse(httpConn));
                 }
                 FileOutputStream fos = new FileOutputStream(keytabFile);
                 InputStream in = httpConn.getInputStream();
@@ -495,23 +373,6 @@ public class HasAuthAdminClient implements Kadmin {
 
     }
 
-    private String getResponse(HttpURLConnection httpConn) throws IOException {
-        StringBuilder data = new StringBuilder();
-        InputStream inputStream;
-        if (httpConn.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
-            inputStream = httpConn.getInputStream();
-        } else {
-            /* Error from server */
-            inputStream = httpConn.getErrorStream();
-        }
-        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
-        String s;
-        while ((s = br.readLine()) != null) {
-            data.append(s);
-        }
-        return data.toString();
-    }
-
     public List<String> addPrincipalsByRole(String hostRoles) throws KrbException {
         HttpURLConnection httpConn;
 
@@ -522,17 +383,8 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException(e.getMessage());
         }
 
-        httpConn = createConnection(url, "POST");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "PUT", true);
 
-        httpConn.setRequestProperty("Content-Type",
-                "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("PUT");
-        } catch (ProtocolException e) {
-            throw new KrbException(e.getMessage());
-        }
-        httpConn.setDoOutput(true);
-        httpConn.setDoInput(true);
         String response;
         try {
             httpConn.connect();
@@ -541,9 +393,9 @@ public class HasAuthAdminClient implements Kadmin {
             out.flush();
             out.close();
             if (httpConn.getResponseCode() == 200) {
-                response = getResponse(httpConn);
+                response = HasClientUtil.getResponse(httpConn);
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (Exception e) {
             throw new KrbException(e.getMessage());
@@ -551,28 +403,19 @@ public class HasAuthAdminClient implements Kadmin {
         return stringtoList(response);
     }
 
-    public void setEnableOfConf(String isEnable) throws HasException {
+    public void setEnableOfConf(String isEnable) throws KrbException {
         HttpURLConnection httpConn;
 
         URL url;
         try {
             url = new URL(getHadminBaseURL() + "setconf?isEnable=" + isEnable);
         } catch (MalformedURLException e) {
-            throw new HasException(e);
+            throw new KrbException(e.getMessage());
         }
 
-        httpConn = createConnection(url, "PUT");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "PUT", true);
 
-        httpConn.setRequestProperty("Content-Type",
-                "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("PUT");
-        } catch (ProtocolException e) {
-            throw new HasException(e);
-        }
         try {
-            httpConn.setDoOutput(true);
-            httpConn.setDoInput(true);
             httpConn.connect();
             InputStream inputStream = httpConn.getResponseCode() == 200
                     ? httpConn.getInputStream() : httpConn.getErrorStream();
@@ -590,11 +433,11 @@ public class HasAuthAdminClient implements Kadmin {
             }
         } catch (Exception e) {
             LOG.error("Fail to connect to server. " + e);
-            throw new HasException(e);
+            throw new KrbException(e.getMessage());
         }
     }
 
-    public File getKeytabByHostAndRole(String host, String role) throws HasException {
+    public File getKeytabByHostAndRole(String host, String role) throws KrbException {
         String keytabName = host + ".zip";
         HttpURLConnection httpConn;
         String request = getHadminBaseURL() + "exportKeytabsbyrole?host=" + host;
@@ -607,20 +450,11 @@ public class HasAuthAdminClient implements Kadmin {
         try {
             url = new URL(request);
         } catch (MalformedURLException e) {
-            throw new HasException(e);
+            throw new KrbException(e.getMessage());
         }
 
-        httpConn = createConnection(url, "GET");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("GET");
-        } catch (ProtocolException e) {
-            throw new HasException(e);
-        }
-        httpConn.setDoOutput(true);
-        httpConn.setDoInput(true);
         try {
             httpConn.connect();
 
@@ -638,7 +472,7 @@ public class HasAuthAdminClient implements Kadmin {
             fos.close();
             in.close();
         } catch (IOException e) {
-            throw new HasException(e);
+            throw new KrbException(e.getMessage());
         }
         System.out.println("Accept keytab file \"" + keytabName + "\" from server.");
 
@@ -655,24 +489,17 @@ public class HasAuthAdminClient implements Kadmin {
             throw new KrbException("Failed to create a URL object.", e);
         }
 
-        httpConn = createConnection(url, "GET");
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", true);
 
-        httpConn.setRequestProperty("Content-Type",
-            "application/json; charset=UTF-8");
-        try {
-            httpConn.setRequestMethod("GET");
-        } catch (ProtocolException e) {
-            throw new KrbException("Failed to set the method for URL request.", e);
-        }
         String response;
         try {
             httpConn.setDoInput(true);
             httpConn.connect();
 
             if (httpConn.getResponseCode() == 200) {
-                response = getResponse(httpConn);
+                response = HasClientUtil.getResponse(httpConn);
             } else {
-                throw new KrbException(getResponse(httpConn));
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
         } catch (IOException e) {
             LOG.error("IO error occurred." + e.getMessage());

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClient.java
----------------------------------------------------------------------
diff --git a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClient.java b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClient.java
index 14cbd23..bfef56a 100755
--- a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClient.java
+++ b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClient.java
@@ -17,10 +17,6 @@
  */
 package org.apache.kerby.has.client;
 
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.text.CharacterPredicates;
 import org.apache.commons.text.RandomStringGenerator;
@@ -312,35 +308,7 @@ public class HasClient {
                     + responseStatus);
             }
         } else {
-            WebResource webResource;
-            Client client = Client.create();
-            String[] hosts = config.getHttpHost().split(",");
-            for (String host : hosts) {
-                webResource = client
-                    .resource("http://" + host.trim() + ":" + config.getHttpPort()
-                        + "/has/v1?type=" + type + "&authToken="
-                        + tokenString);
-                try {
-                    ClientResponse response = webResource.accept("application/json")
-                        .put(ClientResponse.class);
-
-                    if (response.getStatus() != 200) {
-                        LOG.warn("WARN! " + response.getEntity(String.class));
-                        responseStatus = response.getStatus();
-                        continue;
-                    }
-                    json = response.getEntity(JSONObject.class);
-                    success = true;
-                    break;
-                } catch (ClientHandlerException e) {
-                    LOG.warn("WARN! " + e.toString());
-                    continue;
-                }
-            }
-            if (!success) {
-                throw new HasException("Failed : HTTP error code : "
-                    + responseStatus);
-            }
+            throw new HasException("Please set https host and port.");
         }
 
         LOG.debug("Return from Server .... \n");
@@ -506,18 +474,43 @@ public class HasClient {
      */
     private X509Certificate getCertificate(String host, String port) throws HasException {
         X509Certificate certificate;
-        Client client = Client.create();
-        WebResource webResource = client.resource("http://" + host + ":" + port + "/has/v1/getcert");
-        ClientResponse response = webResource.get(ClientResponse.class);
-        if (response.getStatus() != 200) {
-            throw new HasException(response.getEntity(String.class));
+
+        HttpURLConnection httpConn = null;
+
+        URL url;
+        try {
+            url = new URL("http://" + host + ":" + port + "/has/v1/getcert");
+        } catch (MalformedURLException e) {
+            throw new HasException("Failed to create a URL object.", e);
         }
         try {
-            CertificateFactory factory = CertificateFactory.getInstance("X.509");
-            InputStream in = response.getEntityInputStream();
-            certificate = (X509Certificate) factory.generateCertificate(in);
-        } catch (CertificateException e) {
-            throw new HasException("Failed to get certificate from HAS server", e);
+            httpConn = (HttpURLConnection) url.openConnection();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        httpConn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+        try {
+            httpConn.setRequestMethod("GET");
+        } catch (ProtocolException e) {
+            LOG.error("Fail to add principal. " + e);
+            throw new HasException("Failed to set the method for URL request.", e);
+        }
+
+        try {
+            httpConn.connect();
+            if (httpConn.getResponseCode() != 200) {
+                throw new HasException(HasClientUtil.getResponse(httpConn));
+            }
+            try {
+                CertificateFactory factory = CertificateFactory.getInstance("X.509");
+                InputStream in = HasClientUtil.getInputStream(httpConn);
+                certificate = (X509Certificate) factory.generateCertificate(in);
+            } catch (CertificateException e) {
+                throw new HasException("Failed to get certificate from HAS server", e);
+            }
+
+        } catch (IOException e) {
+            throw new HasException("IO error occurred.", e);
         }
 
         return certificate;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClientUtil.java
----------------------------------------------------------------------
diff --git a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClientUtil.java b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClientUtil.java
new file mode 100644
index 0000000..56ebd98
--- /dev/null
+++ b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasClientUtil.java
@@ -0,0 +1,126 @@
+/**
+ *  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.kerby.has.client;
+
+import org.apache.kerby.has.common.HasConfig;
+import org.apache.kerby.has.common.ssl.SSLFactory;
+import org.apache.kerby.has.common.util.URLConnectionFactory;
+import org.apache.kerby.kerberos.kerb.KrbException;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.ProtocolException;
+import java.net.URL;
+
+public class HasClientUtil {
+
+    public static HttpURLConnection getHttpsConnection(HasConfig hasConfig, URL url, boolean isSpnego)
+            throws Exception {
+        HasConfig conf = new HasConfig();
+
+        conf.setString(SSLFactory.SSL_HOSTNAME_VERIFIER_KEY, "ALLOW_ALL");
+        String sslClientConf = hasConfig.getSslClientConf();
+        conf.setString(SSLFactory.SSL_CLIENT_CONF_KEY, sslClientConf);
+        conf.setBoolean(SSLFactory.SSL_REQUIRE_CLIENT_CERT_KEY, false);
+
+        URLConnectionFactory connectionFactory = URLConnectionFactory
+                .newDefaultURLConnectionFactory(conf);
+        return (HttpURLConnection) connectionFactory.openConnection(url, isSpnego, hasConfig);
+    }
+
+    /**
+     * Create an authenticated connection to the Has server.
+     * <p>
+     * It uses Hadoop-auth client authentication which by default supports
+     * Kerberos HTTP SPNEGO, Pseudo/Simple and anonymous.
+     *
+     * @param hasConfig the HAS client config.
+     * @param url    the URL to open a HTTP connection to.
+     * @param method the HTTP method for the HTTP connection.
+     * @param  isSpnego  true or false.
+     * @return an authenticated connection to the has server.
+     * @throws IOException if an IO error occurred.
+     */
+    public static HttpURLConnection createConnection(HasConfig hasConfig, URL url, String method, boolean isSpnego)
+            throws KrbException {
+        HttpURLConnection conn = null;
+        if (hasConfig.getHttpsPort() != null && hasConfig.getHttpsHost() != null) {
+            try {
+                conn = getHttpsConnection(hasConfig, url, isSpnego);
+            } catch (Exception e) {
+                throw new KrbException("Error occurred when creating https connection. "
+                        + e.getMessage());
+            }
+        }
+        try {
+            conn.setRequestMethod(method);
+        } catch (ProtocolException e) {
+            throw new KrbException("Failed to set the method for URL request.", e);
+        }
+        if (method.equals("POST") || method.equals("PUT")) {
+            conn.setDoOutput(true);
+        }
+        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
+        return conn;
+    }
+
+    public static String getBaseUrl(HasConfig hasConfig, String input) throws KrbException {
+        String url = null;
+        if (hasConfig.getHttpsPort() != null && hasConfig.getHttpsHost() != null) {
+            url = "https://" + hasConfig.getHttpsHost() + ":" + hasConfig.getHttpsPort()
+                    + "/has/v1/" + input + "/";
+        }
+        if (url == null) {
+            throw new KrbException("Please set the https address and port.");
+        }
+        return url;
+    }
+
+    public static String getResponse(HttpURLConnection httpConn) throws IOException {
+        StringBuilder data = new StringBuilder();
+
+        InputStream inputStream = getInputStream(httpConn);
+        BufferedReader br;
+        if (inputStream != null) {
+          br = new BufferedReader(new InputStreamReader(inputStream));
+        } else {
+            throw new IOException("Failed to get the InputStream");
+        }
+        String s;
+        while ((s = br.readLine()) != null) {
+            data.append(s);
+        }
+        return data.toString();
+    }
+
+    public static InputStream getInputStream(HttpURLConnection httpConn) throws IOException {
+        InputStream inputStream;
+        if (httpConn.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
+            inputStream = httpConn.getInputStream();
+        } else {
+            /* Error from server */
+            inputStream = httpConn.getErrorStream();
+        }
+        return inputStream;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasInitClient.java
----------------------------------------------------------------------
diff --git a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasInitClient.java b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasInitClient.java
index 675b1b7..fb52130 100644
--- a/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasInitClient.java
+++ b/has-project/has-client/src/main/java/org/apache/kerby/has/client/HasInitClient.java
@@ -17,27 +17,18 @@
  */
 package org.apache.kerby.has.client;
 
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
 import org.apache.kerby.has.common.HasConfig;
-import org.apache.kerby.has.common.HasException;
 import org.apache.kerby.kerberos.kerb.KrbException;
-import org.glassfish.jersey.SslConfigurator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.ws.rs.core.MultivaluedMap;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
  * HAS client API for applications to interact with HAS server
@@ -58,181 +49,231 @@ public class HasInitClient {
         return confDir;
     }
 
-    private WebResource getWebResource(String restName) {
-        Client client;
-        String server = null;
-        if (hasConfig.getHttpsPort() != null && hasConfig.getHttpsHost() != null) {
-            server = "https://" + hasConfig.getHttpsHost() + ":" + hasConfig.getHttpsPort()
-                    + "/has/v1/" + restName;
-            LOG.info("Admin request url: " + server);
-            HasConfig conf = new HasConfig();
-            try {
-                conf.addIniConfig(new File(hasConfig.getSslClientConf()));
-            } catch (IOException e) {
-                throw new RuntimeException("Errors occurred when adding ssl conf. "
-                    + e.getMessage());
-            }
-            SslConfigurator sslConfigurator = SslConfigurator.newInstance()
-                    .trustStoreFile(conf.getString("ssl.client.truststore.location"))
-                    .trustStorePassword(conf.getString("ssl.client.truststore.password"));
-            sslConfigurator.securityProtocol("SSL");
-            SSLContext sslContext = sslConfigurator.createSSLContext();
-            ClientConfig clientConfig = new DefaultClientConfig();
-            clientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
-                    new HTTPSProperties(new HostnameVerifier() {
-                        @Override
-                        public boolean verify(String s, SSLSession sslSession) {
-                            return false;
-                        }
-                    }, sslContext));
-            client = Client.create(clientConfig);
-        } else {
-            client = Client.create();
-        }
-        if (server == null) {
-            throw new RuntimeException("Please set the https address and port.");
-        }
-        return client.resource(server);
+    private String getInitBaseURL() throws KrbException {
+        return HasClientUtil.getBaseUrl(hasConfig, "init");
     }
 
-    public void startKdc() {
-        WebResource webResource = getWebResource("init/kdcstart");
-        ClientResponse response = webResource.get(ClientResponse.class);
-        String message = null;
+    private String getConfigBaseURL() throws KrbException {
+        return HasClientUtil.getBaseUrl(hasConfig, "conf");
+    }
+
+    public String startKdc() throws KrbException {
+        HttpURLConnection httpConn;
+
+        URL url;
         try {
-            message = getResponse(response);
-        } catch (HasException e) {
-            System.err.println(e.getMessage());
-        }
-        if (response.getStatus() == 200) {
-            System.out.println(message);
-        } else {
-            System.err.println(message);
+            url = new URL(getInitBaseURL() + "kdcstart");
+        } catch (MalformedURLException e) {
+            throw new KrbException("Failed to create a URL object.", e);
         }
-    }
 
-    public InputStream initKdc() {
-        WebResource webResource = getWebResource("init/kdcinit");
-        ClientResponse response = webResource.get(ClientResponse.class);
-        if (response.getStatus() == 200) {
-            return response.getEntityInputStream();
-        } else {
-            try {
-                System.err.println(getResponse(response));
-            } catch (HasException e) {
-                System.err.println(e.getMessage());
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "PUT", false);
+
+        try {
+            httpConn.connect();
+
+            if (httpConn.getResponseCode() == 200) {
+                String response = HasClientUtil.getResponse(httpConn);
+                LOG.info(response);
+                return response;
+            } else {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
-            return null;
+        } catch (IOException e) {
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
     }
 
-    private String getResponse(ClientResponse response) throws HasException {
-        InputStream is = response.getEntityInputStream();
-        final byte[] b = new byte[1024];
-        int read;
-        final StringBuilder msg = new StringBuilder();
+    public void initKdc(File keytab) throws KrbException {
+        HttpURLConnection httpConn;
+
+        URL url;
         try {
-            while ((read = is.read(b)) > 0) {
-                msg.append(new String(b, 0, read));
+            url = new URL(getInitBaseURL() + "kdcinit");
+        } catch (MalformedURLException e) {
+            throw new KrbException("Failed to create a URL object.", e);
+        }
+
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", false);
+
+        try {
+            httpConn.connect();
+            if (httpConn.getResponseCode() != 200) {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
             }
+            FileOutputStream fos = new FileOutputStream(keytab);
+            InputStream in = httpConn.getInputStream();
+            byte[] buffer = new byte[3 * 1024];
+            int read;
+            while ((read = in.read(buffer)) > 0) {
+                fos.write(buffer, 0, read);
+            }
+            fos.close();
+            in.close();
         } catch (IOException e) {
-            throw new HasException(e.getMessage());
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
-        return msg.toString();
     }
 
-    public String getKrb5conf() throws KrbException {
-        WebResource webResource = getWebResource("conf/getkrb5conf");
-        ClientResponse response = webResource.get(ClientResponse.class);
-        String message;
+    public void getKrb5conf(File file) throws KrbException {
+
+        HttpURLConnection httpConn;
+
+        URL url;
         try {
-            message = getResponse(response);
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
+            url = new URL(getConfigBaseURL() + "getkrb5conf");
+        } catch (MalformedURLException e) {
+            throw new KrbException("Failed to create a URL object.", e);
         }
-        if (response.getStatus() == 200) {
-            return message;
-        } else {
-            throw new KrbException(message);
+
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", false);
+
+        try {
+            httpConn.connect();
+            if (httpConn.getResponseCode() != 200) {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
+            }
+            FileOutputStream fos = new FileOutputStream(file);
+            InputStream in = httpConn.getInputStream();
+            byte[] buffer = new byte[3 * 1024];
+            int read;
+            while ((read = in.read(buffer)) > 0) {
+                fos.write(buffer, 0, read);
+            }
+            fos.close();
+            in.close();
+        } catch (IOException e) {
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
     }
 
-    public String getHasClientConf() throws KrbException {
-        WebResource webResource = getWebResource("conf/gethasclientconf");
-        ClientResponse response = webResource.get(ClientResponse.class);
-        String message;
+    public void getHasClientConf(File file) throws KrbException {
+
+        HttpURLConnection httpConn;
+
+        URL url;
         try {
-            message = getResponse(response);
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
+            url = new URL(getConfigBaseURL() + "gethasclientconf");
+        } catch (MalformedURLException e) {
+            throw new KrbException("Failed to create a URL object.", e);
         }
-        if (response.getStatus() == 200) {
-            return message;
-        } else {
-            throw new KrbException(message);
+
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "GET", false);
+
+        try {
+            httpConn.connect();
+            if (httpConn.getResponseCode() != 200) {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
+            }
+            FileOutputStream fos = new FileOutputStream(file);
+            InputStream in = httpConn.getInputStream();
+            byte[] buffer = new byte[3 * 1024];
+            int read;
+            while ((read = in.read(buffer)) > 0) {
+                fos.write(buffer, 0, read);
+            }
+            fos.close();
+            in.close();
+        } catch (IOException e) {
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
     }
 
     public String setPlugin(String plugin) throws KrbException {
-        WebResource webResource = getWebResource("conf/setplugin");
-        MultivaluedMap<String, String> params = new MultivaluedMapImpl();
-        params.add("plugin", plugin);
-        ClientResponse response = webResource.queryParams(params).put(ClientResponse.class);
-        String message;
+
+        HttpURLConnection httpConn;
+
+        URL url;
         try {
-            message = getResponse(response);
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
+            url = new URL(getConfigBaseURL() + "setplugin?plugin=" + plugin);
+        } catch (MalformedURLException e) {
+            throw new KrbException("Failed to create a URL object.", e);
         }
-        if (response.getStatus() == 200) {
-            return message;
-        } else {
-            throw new KrbException(message);
+
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "PUT", false);
+
+        try {
+            httpConn.connect();
+
+            if (httpConn.getResponseCode() == 200) {
+                String response = HasClientUtil.getResponse(httpConn);
+                LOG.info(response);
+                return response;
+            } else {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
+            }
+        } catch (IOException e) {
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
     }
 
     public String configKdc(String port, String realm, String host) throws KrbException {
-        WebResource webResource = getWebResource("conf/configkdc");
-        MultivaluedMap<String, String> params = new MultivaluedMapImpl();
-        params.add("port", port);
-        params.add("realm", realm);
-        params.add("host", host);
-        ClientResponse response = webResource.queryParams(params).put(ClientResponse.class);
-        String message;
+
+        HttpURLConnection httpConn;
+
+        URL url;
         try {
-            message = getResponse(response);
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
+            url = new URL(getConfigBaseURL() + "configkdc?port=" + port + "&realm="
+                    + realm + "&host=" + host);
+        } catch (MalformedURLException e) {
+            throw new KrbException("Failed to create a URL object.", e);
         }
-        if (response.getStatus() == 200) {
-            return message;
-        } else {
-            throw new KrbException(message);
+
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "PUT", false);
+
+        try {
+            httpConn.connect();
+
+            if (httpConn.getResponseCode() == 200) {
+                String response = HasClientUtil.getResponse(httpConn);
+                LOG.info(response);
+                return response;
+            } else {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
+            }
+        } catch (IOException e) {
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
     }
-    public String configBackend(String backendType, String dir, String url, String user,
+
+    public String configBackend(String backendType, String dir, String mysqlUrl, String user,
                               String password) throws KrbException {
-        WebResource webResource = getWebResource("conf/configbackend");
-        MultivaluedMap<String, String> params = new MultivaluedMapImpl();
-        params.add("backendType", backendType);
+
+        HttpURLConnection httpConn;
+
+        URL url;
         if (backendType.equals("json")) {
-            params.add("dir", dir);
+            try {
+                url = new URL(getConfigBaseURL() + "configbackend?backendType=" + backendType
+                        + "&dir=" + dir);
+            } catch (MalformedURLException e) {
+                throw new KrbException("Failed to create a URL object.", e);
+            }
         } else if (backendType.equals("mysql")) {
-            params.add("url", url);
-            params.add("user", user);
-            params.add("password", password);
+            try {
+                url = new URL(getConfigBaseURL() + "configbackend?backendType=" + backendType
+                        + "&url=" + mysqlUrl + "&user=" + user + "&password=" + password);
+            } catch (MalformedURLException e) {
+                throw new KrbException("Failed to create a URL object.", e);
+            }
+        } else {
+            throw new KrbException("Unsupported backend: " + backendType);
         }
-        ClientResponse response = webResource.queryParams(params).put(ClientResponse.class);
-        String message;
+
+        httpConn = HasClientUtil.createConnection(hasConfig, url, "PUT", false);
+
         try {
-            message = getResponse(response);
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
-        }
-        if (response.getStatus() == 200) {
-            return message;
-        } else {
-            throw new KrbException(message);
+            httpConn.connect();
+
+            if (httpConn.getResponseCode() == 200) {
+                String response = HasClientUtil.getResponse(httpConn);
+                LOG.info(response);
+                return response;
+            } else {
+                throw new KrbException(HasClientUtil.getResponse(httpConn));
+            }
+        } catch (IOException e) {
+            throw new KrbException("IO error occurred. " + e.getMessage());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/URLConnectionFactory.java
----------------------------------------------------------------------
diff --git a/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/URLConnectionFactory.java b/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/URLConnectionFactory.java
index cf74340..90481de 100644
--- a/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/URLConnectionFactory.java
+++ b/has-project/has-common/src/main/java/org/apache/kerby/has/common/util/URLConnectionFactory.java
@@ -80,7 +80,7 @@ public class URLConnectionFactory {
    * try to load SSL certificates when it is specified.
    */
   public static URLConnectionFactory newDefaultURLConnectionFactory(HasConfig conf) {
-    ConnectionConfigurator conn = null;
+    ConnectionConfigurator conn;
     try {
       conn = newSslConnConfigurator(DEFAULT_SOCKET_TIMEOUT, conf);
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/ConfFilter.java
----------------------------------------------------------------------
diff --git a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/ConfFilter.java b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/ConfFilter.java
index e300886..b6491b3 100644
--- a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/ConfFilter.java
+++ b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/ConfFilter.java
@@ -40,7 +40,7 @@ public class ConfFilter implements Filter {
                     new File(hasServer.getConfDir(), "has-server.conf"));
             String isEnableConf = hasConfig.getEnableConf();
             if (!isEnableConf.equals("true")) {
-                throw new RuntimeException("The KDC has started, please stop KDC before setting.");
+                throw new IOException("The KDC has started, please stop KDC before setting.");
             }
             filterChain.doFilter(servletRequest, servletResponse);
         } catch (HasException e) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/ConfigApi.java
----------------------------------------------------------------------
diff --git a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/ConfigApi.java b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/ConfigApi.java
index 73a2a55..2a70a34 100644
--- a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/ConfigApi.java
+++ b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/ConfigApi.java
@@ -63,7 +63,7 @@ public class ConfigApi {
      */
     @PUT
     @Path("/setplugin")
-    @Consumes({MediaType.TEXT_PLAIN})
+    @Consumes({MediaType.APPLICATION_JSON})
     @Produces({MediaType.TEXT_PLAIN})
     public Response setPlugin(@QueryParam("plugin") final String plugin) {
         if (httpRequest.isSecure()) {
@@ -174,7 +174,7 @@ public class ConfigApi {
      */
     @PUT
     @Path("/configkdc")
-    @Consumes({MediaType.TEXT_PLAIN})
+    @Consumes({MediaType.APPLICATION_JSON})
     @Produces({MediaType.TEXT_PLAIN})
     public Response configKdc(
         @QueryParam("port") final int port,

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/InitApi.java
----------------------------------------------------------------------
diff --git a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/InitApi.java b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/InitApi.java
index b4b7648..b7ded08 100644
--- a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/InitApi.java
+++ b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/InitApi.java
@@ -25,6 +25,7 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
@@ -64,7 +65,7 @@ public class InitApi {
         return Response.status(Response.Status.FORBIDDEN).entity("HTTPS required.\n").build();
     }
 
-    @GET
+    @PUT
     @Path("/kdcstart")
     @Produces(MediaType.TEXT_PLAIN)
     public Response kdcStart() {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/DisableConfRemoteCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/DisableConfRemoteCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/DisableConfRemoteCmd.java
index c152ad2..9a6d6a3 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/DisableConfRemoteCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/DisableConfRemoteCmd.java
@@ -20,7 +20,6 @@
 package org.apache.kerby.kerberos.tool.admin.cmd;
 
 import org.apache.kerby.has.client.HasAuthAdminClient;
-import org.apache.kerby.has.common.HasException;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
 /**
@@ -39,10 +38,6 @@ public class DisableConfRemoteCmd extends AdminRemoteCmd {
     @Override
     public void execute(String[] items) throws KrbException {
         HasAuthAdminClient client = getAuthAdminClient();
-        try {
-            client.setEnableOfConf("false");
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
-        }
+        client.setEnableOfConf("false");
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/EnableConfRemoteCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/EnableConfRemoteCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/EnableConfRemoteCmd.java
index 28011a8..6b72db3 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/EnableConfRemoteCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/EnableConfRemoteCmd.java
@@ -20,7 +20,6 @@
 package org.apache.kerby.kerberos.tool.admin.cmd;
 
 import org.apache.kerby.has.client.HasAuthAdminClient;
-import org.apache.kerby.has.common.HasException;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
 /**
@@ -40,10 +39,6 @@ public class EnableConfRemoteCmd extends AdminRemoteCmd {
     public void execute(String[] items) throws KrbException {
 
         HasAuthAdminClient client = getAuthAdminClient();
-        try {
-            client.setEnableOfConf("true");
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
-        }
+        client.setEnableOfConf("true");
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ExportKeytabsRemoteCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ExportKeytabsRemoteCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ExportKeytabsRemoteCmd.java
index 52513ca..5d5614d 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ExportKeytabsRemoteCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ExportKeytabsRemoteCmd.java
@@ -20,7 +20,6 @@
 package org.apache.kerby.kerberos.tool.admin.cmd;
 
 import org.apache.kerby.has.client.HasAuthAdminClient;
-import org.apache.kerby.has.common.HasException;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
 public class ExportKeytabsRemoteCmd extends AdminRemoteCmd {
@@ -48,10 +47,6 @@ public class ExportKeytabsRemoteCmd extends AdminRemoteCmd {
         if (items.length >= 3) {
             role = items[2];
         }
-        try {
-            client.getKeytabByHostAndRole(host, role);
-        } catch (HasException e) {
-            throw new KrbException(e.getMessage());
-        }
+        client.getKeytabByHostAndRole(host, role);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ListPrincipalsRemoteCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ListPrincipalsRemoteCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ListPrincipalsRemoteCmd.java
index b46f95c..470ca33 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ListPrincipalsRemoteCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/admin/cmd/ListPrincipalsRemoteCmd.java
@@ -57,7 +57,8 @@ public class ListPrincipalsRemoteCmd extends AdminRemoteCmd {
             principalLists = client.getPrincipals(exp);
         }
 
-        if (principalLists.size() == 0 || principalLists.size() == 1 && principalLists.get(0).isEmpty()) {
+        if (principalLists == null || principalLists.size() == 0
+                || principalLists.size() == 1 && principalLists.get(0).isEmpty()) {
             return;
         } else {
             System.out.println("Principals are listed:");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetHasClientConfCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetHasClientConfCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetHasClientConfCmd.java
index f195e0e..01bcddf 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetHasClientConfCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetHasClientConfCmd.java
@@ -23,9 +23,6 @@ import org.apache.kerby.has.client.HasInitClient;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
 
 /**
  * Remote get has-client.conf cmd
@@ -56,17 +53,7 @@ public class GetHasClientConfCmd extends InitCmd {
             }
         }
         File hasConf = new File(path, "has-client.conf");
-        String content = client.getHasClientConf();
-        if (content == null) {
-            System.err.println("Failed to get has.conf.");
-            return;
-        }
-        try {
-            PrintStream ps = new PrintStream(new FileOutputStream(hasConf));
-            ps.println(content);
-            System.out.println("has-client.conf has saved in : " + hasConf.getAbsolutePath());
-        } catch (FileNotFoundException e) {
-            System.err.println(e.getMessage());
-        }
+        client.getHasClientConf(hasConf);
+        System.out.println("has-client.conf has saved in : " + hasConf.getAbsolutePath());
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetKrb5ConfCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetKrb5ConfCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetKrb5ConfCmd.java
index 58df209..8a4b062 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetKrb5ConfCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/GetKrb5ConfCmd.java
@@ -23,9 +23,6 @@ import org.apache.kerby.has.client.HasInitClient;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
 
 /**
  * Remote get krb5.conf cmd
@@ -56,17 +53,7 @@ public class GetKrb5ConfCmd extends InitCmd {
             }
         }
         File krb5Conf = new File(path, "krb5.conf");
-        String content = client.getKrb5conf();
-        if (content == null) {
-            System.err.println("Failed to get krb5.conf.");
-            return;
-        }
-        try {
-            PrintStream ps = new PrintStream(new FileOutputStream(krb5Conf));
-            ps.println(content);
-            System.out.println("krb5.conf has saved in : " + krb5Conf.getAbsolutePath());
-        } catch (FileNotFoundException e) {
-            System.err.println(e.getMessage());
-        }
+        client.getKrb5conf(krb5Conf);
+        System.out.println("krb5.conf has saved in : " + krb5Conf.getAbsolutePath());
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/InitKdcCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/InitKdcCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/InitKdcCmd.java
index d9ad062..1b68799 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/InitKdcCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/InitKdcCmd.java
@@ -23,10 +23,6 @@ import org.apache.kerby.has.client.HasInitClient;
 import org.apache.kerby.kerberos.kerb.KrbException;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
 
 /**
  * Remote init kdc cmd
@@ -58,25 +54,8 @@ public class InitKdcCmd extends InitCmd {
         File adminKeytab = new File(path, "admin.keytab");
 
         HasInitClient client = getClient();
-        InputStream content = client.initKdc();
 
-        if (content == null) {
-            return;
-        }
-
-        try (FileOutputStream fos = new FileOutputStream(adminKeytab)) {
-            byte[] buffer = new byte[4 * 1024];
-            int read;
-            while ((read = content.read(buffer)) > 0) {
-                fos.write(buffer, 0, read);
-            }
-            fos.close();
-            content.close();
-        } catch (FileNotFoundException e) {
-            System.err.println("the admin keytab file not found. " + e.getMessage());
-        } catch (IOException e) {
-            System.err.println("Errors occurred when getting the admin.keytab. " + e.getMessage());
-        }
+        client.initKdc(adminKeytab);
 
         System.out.println("admin.keytab has saved in : " + adminKeytab.getAbsolutePath()
             + ",\nplease safely save it to use kadmin.");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/6cb25114/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/StartKdcCmd.java
----------------------------------------------------------------------
diff --git a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/StartKdcCmd.java b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/StartKdcCmd.java
index 36405b2..a5fa8ef 100644
--- a/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/StartKdcCmd.java
+++ b/kerby-tool/has-tool/src/main/java/org/apache/kerby/kerberos/tool/init/cmd/StartKdcCmd.java
@@ -47,6 +47,6 @@ public class StartKdcCmd extends InitCmd {
             return;
         }
         HasInitClient client = getClient();
-        client.startKdc();
+        System.out.println(client.startKdc());
     }
 }


Mime
View raw message