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: Parse the error message from https response.
Date Fri, 02 Mar 2018 08:24:57 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk 439aeaed8 -> bec8f47a6


Parse the error message from https response.


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

Branch: refs/heads/trunk
Commit: bec8f47a6dac9c8409e3bab5265322fa6028d656
Parents: 439aeae
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Fri Mar 2 16:21:54 2018 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Fri Mar 2 16:21:54 2018 +0800

----------------------------------------------------------------------
 .../apache/kerby/has/client/HasInitClient.java  | 41 +++++++++++++++-----
 .../org/apache/kerby/has/server/HasServer.java  |  8 ++--
 .../kerby/has/server/web/rest/HadminApi.java    |  5 +--
 .../kerby/has/server/web/rest/InitApi.java      | 15 ++-----
 .../kerby/has/server/web/rest/KadminApi.java    | 21 +++-------
 kerby-dist/has-dist/conf/hadmin.conf            |  2 +-
 kerby-dist/has-dist/conf/has-server.conf        |  4 +-
 kerby-dist/has-dist/conf/kdc.conf               |  2 +-
 kerby-dist/has-dist/conf/krb5.conf              | 29 ++++++++++++++
 .../server/impl/AbstractInternalKdcServer.java  |  2 +-
 10 files changed, 79 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/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 ff017cb..104f302 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
@@ -24,8 +24,7 @@ import com.sun.jersey.api.client.config.ClientConfig;
 import com.sun.jersey.api.client.config.DefaultClientConfig;
 import com.sun.jersey.client.urlconnection.HTTPSProperties;
 import org.apache.kerby.has.common.HasConfig;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
+import org.apache.kerby.has.common.HasException;
 import org.glassfish.jersey.SslConfigurator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -96,16 +95,17 @@ public class HasInitClient {
     public void startKdc() {
         WebResource webResource = getWebResource("init/kdcstart");
         ClientResponse response = webResource.get(ClientResponse.class);
+        String message = null;
         try {
-            JSONObject result = new JSONObject(response.getEntity(String.class));
-            if (result.getString("result").equals("success")) {
-                System.out.println(result.getString("msg"));
-            } else {
-                System.err.println(result.getString("msg"));
-            }
-        } catch (JSONException e) {
+            message = getResponse(response);
+        } catch (HasException e) {
             System.err.println(e.getMessage());
         }
+        if (response.getStatus() == 200) {
+            System.out.println(message);
+        } else {
+            System.err.println(message);
+        }
     }
 
     public InputStream initKdc() {
@@ -113,7 +113,28 @@ public class HasInitClient {
         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());
+            }
+            return null;
+        }
+    }
+
+    private String getResponse(ClientResponse response) throws HasException {
+        InputStream is = response.getEntityInputStream();
+        final byte[] b = new byte[1024];
+        int read;
+        final StringBuilder msg = new StringBuilder();
+        try {
+            while ((read = is.read(b)) > 0) {
+                msg.append(new String(b, 0, read));
+            }
+        } catch (IOException e) {
+            throw new HasException(e.getMessage());
         }
-        return null;
+        return msg.toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/has-project/has-server/src/main/java/org/apache/kerby/has/server/HasServer.java
----------------------------------------------------------------------
diff --git a/has-project/has-server/src/main/java/org/apache/kerby/has/server/HasServer.java
b/has-project/has-server/src/main/java/org/apache/kerby/has/server/HasServer.java
index 4df8dfc..17cb8b4 100644
--- a/has-project/has-server/src/main/java/org/apache/kerby/has/server/HasServer.java
+++ b/has-project/has-server/src/main/java/org/apache/kerby/has/server/HasServer.java
@@ -106,7 +106,7 @@ public class HasServer {
         try {
             kdcServer = new KdcServer(confDir);
         } catch (KrbException e) {
-            throw new HasException("Failed to create KdcServer. " + e);
+            throw new HasException("Failed to create KdcServer. " + e.getMessage());
         }
         kdcServer.setWorkDir(workDir);
         kdcServer.setInnerKdcImpl(new NettyKdcServerImpl(kdcServer.getKdcSetting()));
@@ -117,7 +117,7 @@ public class HasServer {
             throw new HasException("Errors occurred when init has kdc server:  " + e.getMessage());
         }
 
-        KrbConfig krbConfig = null;
+        KrbConfig krbConfig;
         try {
             krbConfig = ClientUtil.getConfig(confDir);
         } catch (KrbException e) {
@@ -131,12 +131,12 @@ public class HasServer {
         try {
             kdcServer.start();
         } catch (KrbException e) {
-            throw new HasException("Failed to start kdc server. " + e);
+            throw new HasException("Failed to start kdc server. " + e.getMessage());
         }
         try {
             HasUtil.setEnableConf(new File(confDir, "has-server.conf"), "false");
         } catch (Exception e) {
-            throw new HasException("Failed to enable conf. " + e);
+            throw new HasException("Failed to enable conf. " + e.getMessage());
         }
         setHttpFilter();
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/HadminApi.java
----------------------------------------------------------------------
diff --git a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/HadminApi.java
b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/HadminApi.java
index 7054a2a..c8c21f8 100644
--- a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/HadminApi.java
+++ b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/HadminApi.java
@@ -94,7 +94,6 @@ public class HadminApi {
             } catch (KrbException e) {
                 WebServer.LOG.info("Failed to create local hadmin." + e.getMessage());
             }
-            JSONObject result = new JSONObject();
             StringBuilder msg = new StringBuilder();
             try {
                 StringBuilder data = new StringBuilder();
@@ -112,9 +111,7 @@ public class HadminApi {
                         msg.append(hasAdmin.addPrincByRole(host.getString("name"), role.toUpperCase()));
                     }
                 }
-                result.put("result", "success");
-                result.put("msg", msg.toString());
-                return Response.ok(result.toString()).build();
+                return Response.ok(msg).build();
             } catch (Exception e) {
                 WebServer.LOG.error("Failed to create principals,because : " + e.getMessage());
                 String error = "Failed to create principals,because : " + e.getMessage();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/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 6e1cc6e..b4b7648 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
@@ -21,7 +21,6 @@ import org.apache.kerby.has.common.HasException;
 import org.apache.kerby.has.server.HasServer;
 import org.apache.kerby.has.server.web.WebServer;
 import org.apache.kerby.kerberos.kerb.KrbException;
-import org.codehaus.jettison.json.JSONObject;
 
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
@@ -71,21 +70,13 @@ public class InitApi {
     public Response kdcStart() {
         if (httpRequest.isSecure()) {
             final HasServer hasServer = WebServer.getHasServerFromContext(context);
-            JSONObject result = new JSONObject();
             String msg;
             try {
                 hasServer.startKdcServer();
-            } catch (HasException e) {
-                msg = "Failed to start kdc server, because: " + e.getMessage();
-                WebServer.LOG.error(msg);
-                return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
-            }
-            try {
                 msg = "Succeed in starting KDC server.";
-                result.put("result", "success");
-                result.put("msg", msg);
-                return Response.ok(result.toString()).build();
-            } catch (Exception e) {
+                WebServer.LOG.info(msg);
+                return Response.ok(msg).build();
+            } catch (HasException e) {
                 msg = "Failed to start kdc server, because: " + e.getMessage();
                 WebServer.LOG.error(msg);
                 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/KadminApi.java
----------------------------------------------------------------------
diff --git a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/KadminApi.java
b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/KadminApi.java
index 6445156..61c9a25 100644
--- a/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/KadminApi.java
+++ b/has-project/has-server/src/main/java/org/apache/kerby/has/server/web/rest/KadminApi.java
@@ -112,7 +112,7 @@ public class KadminApi {
                 localKadmin = new LocalKadminImpl(serverSetting);
             } catch (KrbException e) {
                 msg = "Failed to create local kadmin." + e.getMessage();
-                WebServer.LOG.info(msg);
+                WebServer.LOG.error(msg);
                 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
             }
             try {
@@ -158,16 +158,13 @@ public class KadminApi {
                 localKadmin = new LocalKadminImpl(serverSetting);
             } catch (KrbException e) {
                 msg = "Failed to create local kadmin." + e.getMessage();
-                WebServer.LOG.info(msg);
+                WebServer.LOG.error(msg);
                 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
             }
-            JSONObject result = new JSONObject();
             try {
                 localKadmin.addPrincipal(principal.getValue(), password.getValue());
                 msg = "Add principal successfully.";
-                result.put("result", "success");
-                result.put("msg", msg);
-                return Response.ok(result.toString()).build();
+                return Response.ok(msg).build();
             } catch (Exception e) {
                 msg = "Failed to add " + principal + " principal, because: " + e.getMessage();
                 WebServer.LOG.error(msg);
@@ -184,7 +181,6 @@ public class KadminApi {
                                     @QueryParam("newprincipal") String newPrincipal) {
         if (httpRequest.isSecure()) {
             WebServer.LOG.info("Request to rename " + oldPrincipal + " to " + newPrincipal);
-            JSONObject result = new JSONObject();
             String msg;
             if (oldPrincipal != null && newPrincipal != null) {
                 LocalKadminImpl localKadmin;
@@ -201,9 +197,7 @@ public class KadminApi {
                 try {
                     localKadmin.renamePrincipal(oldPrincipal, newPrincipal);
                     msg = "Rename principal successfully.";
-                    result.put("result", "success");
-                    result.put("msg", msg);
-                    return Response.ok(result.toString()).build();
+                    return Response.ok(msg).build();
                 } catch (Exception e) {
                     msg = "Failed to rename principal " + oldPrincipal + " to "
                         + newPrincipal + ",because: " + e.getMessage();
@@ -232,7 +226,6 @@ public class KadminApi {
                                     final PrincipalParam principal) {
         if (httpRequest.isSecure()) {
             WebServer.LOG.info("Request to delete the principal named " + principal.getValue());
-            JSONObject result = new JSONObject();
             String msg;
             LocalKadminImpl localKadmin;
             HasServer hasServer = WebServer.getHasServerFromContext(context);
@@ -248,9 +241,7 @@ public class KadminApi {
             try {
                 localKadmin.deletePrincipal(principal.getValue());
                 msg = "Delete principal successfully.";
-                result.put("result", "success");
-                result.put("msg", msg);
-                return Response.ok(result.toString()).build();
+                return Response.ok(msg).build();
             } catch (Exception e) {
                 msg = "Failed to delete the principal named " + principal.getValue()
                     + ",because : " + e.getMessage();
@@ -258,6 +249,6 @@ public class KadminApi {
                 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
             }
         }
-        return Response.status(403).entity("HTTPS required.\n").build();
+        return Response.status(Response.Status.FORBIDDEN).entity("HTTPS required.\n").build();
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/kerby-dist/has-dist/conf/hadmin.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/has-dist/conf/hadmin.conf b/kerby-dist/has-dist/conf/hadmin.conf
index e950aea..125bdfc 100644
--- a/kerby-dist/has-dist/conf/hadmin.conf
+++ b/kerby-dist/has-dist/conf/hadmin.conf
@@ -1,5 +1,5 @@
 [HAS]
-    https_host = plusplus-desktop
+    https_host = hostname
     https_port = 8092
     admin_keytab = /etc/has/admin.keytab
     admin_keytab_principal = kadmin/HADOOP.COM@HADOOP.COM

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/kerby-dist/has-dist/conf/has-server.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/has-dist/conf/has-server.conf b/kerby-dist/has-dist/conf/has-server.conf
index 57ef56e..93accaf 100644
--- a/kerby-dist/has-dist/conf/has-server.conf
+++ b/kerby-dist/has-dist/conf/has-server.conf
@@ -17,8 +17,8 @@
 #
 
 [HAS]
-  https_host = localhost
+  https_host = plusplus-desktop
   https_port = 8092
   filter_auth_type = kerberos
-  enable_conf = true
+  enable_conf = false
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/kerby-dist/has-dist/conf/kdc.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/has-dist/conf/kdc.conf b/kerby-dist/has-dist/conf/kdc.conf
index c9c7921..21ccdd1 100644
--- a/kerby-dist/has-dist/conf/kdc.conf
+++ b/kerby-dist/has-dist/conf/kdc.conf
@@ -17,7 +17,7 @@
 #
 
 [kdcdefaults]
-  kdc_host = localhost
+  kdc_host = hostname
   kdc_udp_port = 88
   kdc_tcp_port = 88
   kdc_realm = HADOOP.COM

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/kerby-dist/has-dist/conf/krb5.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/has-dist/conf/krb5.conf b/kerby-dist/has-dist/conf/krb5.conf
new file mode 100644
index 0000000..55ae355
--- /dev/null
+++ b/kerby-dist/has-dist/conf/krb5.conf
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+[libdefaults]
+    kdc_realm = HADOOP.COM
+    default_realm = HADOOP.COM
+    udp_preference_limit = 4096
+    kdc_tcp_port = 88
+    kdc_udp_port = 88
+    ticket_lifetime = 60
+[realms]
+    HADOOP.COM = {
+        kdc = hostname:88
+    }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bec8f47a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
index 5e3e5a1..d5f2761 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
@@ -81,7 +81,7 @@ public class AbstractInternalKdcServer implements InternalKdcServer {
         try {
             doStart();
         } catch (Exception e) {
-            throw new KrbException("Failed to start " + getServiceName(), e);
+            throw new KrbException("Failed to start " + getServiceName() + ". " + e.getMessage());
         }
 
         started = true;


Mime
View raw message