directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [12/26] directory-kerby git commit: DIRKRB-389 Fix kadmin break down when input command is illegal. Contributed by Yaning.
Date Mon, 10 Aug 2015 05:15:53 GMT
DIRKRB-389 Fix kadmin break down when input command is illegal. Contributed by Yaning.


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

Branch: refs/heads/pkinit-support
Commit: 14025c73f893bdd8716cc7d24c2ce122e6b7c035
Parents: 216ee66
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Thu Aug 6 10:41:15 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Thu Aug 6 10:41:15 2015 +0800

----------------------------------------------------------------------
 .../identitybackend/JsonIdentityBackend.java    |  6 ++--
 .../ZookeeperIdentityBackend.java               | 21 ++++---------
 .../kerby/kerberos/tool/kadmin/KadminTool.java  | 31 ++++++++++++--------
 .../kadmin/command/AddPrincipalCommand.java     |  2 +-
 .../kadmin/command/ChangePasswordCommand.java   |  4 +--
 .../kadmin/command/DeletePrincipalCommand.java  |  2 +-
 .../kadmin/command/GetPrincipalCommand.java     |  2 +-
 .../tool/kadmin/command/KeytabAddCommand.java   |  2 +-
 .../kadmin/command/ModifyPrincipalCommand.java  |  2 +-
 .../kadmin/command/RenamePrincipalCommand.java  |  2 +-
 10 files changed, 35 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
b/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
index 715a840..f810c4a 100644
--- a/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
+++ b/kerby-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
@@ -117,7 +117,7 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
      * Check kdb file timestamp to see if it's changed or not. If
      * necessary load the kdb again.
      */
-    private synchronized void checkAndLoad() {
+    private synchronized void checkAndLoad() throws KrbException {
         long nowTimeStamp = jsonKdbFile.lastModified();
 
         if (kdbFileTimeStamp == 0 || nowTimeStamp != kdbFileTimeStamp) {
@@ -126,7 +126,7 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
             try {
                 existsFileJson = IOUtil.readFile(jsonKdbFile);
             } catch (IOException e) {
-                throw new RuntimeException("Failed to read file", e);
+                throw new KrbException("Failed to read file", e);
             }
 
             Map<String, KrbIdentity> loaded = gson.fromJson(existsFileJson,
@@ -143,7 +143,7 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
      * {@inheritDoc}
      */
     @Override
-    protected KrbIdentity doGetIdentity(String principalName) {
+    protected KrbIdentity doGetIdentity(String principalName) throws KrbException {
         checkAndLoad();
         return identities.get(principalName);
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
index f2204cc..88156d9 100644
--- a/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
+++ b/kerby-backend/zookeeper-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/ZookeeperIdentityBackend.java
@@ -164,7 +164,11 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
                     try {
                         zooKeeperServer.runFromConfig(configuration);
                     } catch (IOException e) {
-                        throw new RuntimeException("ZooKeeper Failed", e);
+                        try {
+                            throw new KrbException("ZooKeeper Failed", e);
+                        } catch (KrbException e1) {
+                            e1.printStackTrace();
+                        }
                     }
                 }
             };
@@ -213,11 +217,6 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
      */
     @Override
     protected KrbIdentity doAddIdentity(KrbIdentity identity) throws KrbException {
-        if (doGetIdentity(identity.getPrincipalName()) != null) {
-             LOG.error("Error occurred while adding identity, principal "
-                + identity.getPrincipalName() + " already exists.");
-            throw new KrbException("Principal already exists.");
-        }
         try {
             setIdentity(identity);
         } catch (KeeperException e) {
@@ -231,11 +230,6 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
      */
     @Override
     protected KrbIdentity doUpdateIdentity(KrbIdentity identity) throws KrbException {
-        if (doGetIdentity(identity.getPrincipalName()) == null) {
-            LOG.error("Error occured while updating identity, principal "
-                + identity.getPrincipalName() + " does not exists.");
-            throw new KrbException("Principal does not exist.");
-        }
         try {
             setIdentity(identity);
         } catch (KeeperException e) {
@@ -250,11 +244,6 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
     @Override
     protected void doDeleteIdentity(String principalName) throws KrbException {
         principalName = replaceSlash(principalName);
-        if (doGetIdentity(principalName) == null) {
-            LOG.error("Error occurred while deleting identity, principal "
-                + principalName + " does not exists.");
-            throw new KrbException("Principal does not exist.");
-        }
         IdentityZNode identityZNode = new IdentityZNode(zooKeeper, principalName);
         try {
             identityZNode.deleteIdentity();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
index d14b386..605a3e2 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
@@ -59,21 +59,28 @@ public class KadminTool {
             + "get_principal, getprinc  Get principal\n"
             + "list_principals, listprincs, get_principals, getprincs\n"
             + "                         List principals\n"
-            + "add_policy, addpol       Add policy\n"
-            + "modify_policy, modpol    Modify policy\n"
-            + "delete_policy, delpol    Delete policy\n"
-            + "get_policy, getpol       Get policy\n"
-            + "list_policies, listpols, get_policies, getpols\n"
+            + "add_policy, addpol       Add policy, not implemented, and will be implemented
in next version\n"
+            + "modify_policy, modpol    Modify policy, not implemented, and will be implemented
in next version\n"
+            + "delete_policy, delpol    Delete policy, not implemented, and will be implemented
in next version\n"
+            + "get_policy, getpol       Get policy, not implemented, and will be implemented
in next version\n"
+            + "list_policies, listpols, get_policies, getpols, not implemented,"
+            + " and will be implemented in next version"
             + "                         List policies\n"
-            + "get_privs, getprivs      Get privileges\n"
+            + "get_privs, getprivs      Get privileges, not implemented, and will be implemented
in next version\n"
             + "ktadd, xst               Add entry(s) to a keytab\n"
             + "ktremove, ktrem          Remove entry(s) from a keytab\n"
-            + "lock                     Lock database exclusively (use with extreme caution!)\n"
-            + "unlock                   Release exclusive database lock\n"
-            + "purgekeys                Purge previously retained old keys from a principal\n"
-            + "get_strings, getstrs     Show string attributes on a principal\n"
-            + "set_string, setstr       Set a string attribute on a principal\n"
-            + "del_string, delstr       Delete a string attribute on a principal\n"
+            + "lock                     Lock database exclusively (use with extreme caution!),"
+            + " not implemented, and will be implemented in next version\n"
+            + "unlock                   Release exclusive database lock, not implemented,"
+            + " and will be implemented in next version\n"
+            + "purgekeys                Purge previously retained old keys from a principal,
"
+            + "not implemented, and will be implemented in next version\n"
+            + "get_strings, getstrs     Show string attributes on a principal, not implemented,"
+            + " and will be implemented in next version\n"
+            + "set_string, setstr       Set a string attribute on a principal, not implemented,"
+            + " and will be implemented in next version\n"
+            + "del_string, delstr       Delete a string attribute on a principal, not implemented,"
+            + " and will be implemented in next version\n"
             + "list_requests, lr, ?     List available requests.\n"
             + "quit, exit, q            Exit program.";
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalCommand.java
index 6814d2d..90e9b16 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/AddPrincipalCommand.java
@@ -86,7 +86,7 @@ public class AddPrincipalCommand extends KadminCommand {
             getKadmin().addPrincipal(principal, password, kOptions);
             System.out.println("Principal \"" + principal + "\" created.");
         } catch (KrbException e) {
-            System.err.println("Fail to add principal \"" + principal + "\"." + e.getCause());
+            System.err.println("Fail to add principal \"" + principal + "\"." + e.getMessage());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ChangePasswordCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ChangePasswordCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ChangePasswordCommand.java
index e271ca8..1583566 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ChangePasswordCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ChangePasswordCommand.java
@@ -74,13 +74,13 @@ public class ChangePasswordCommand extends KadminCommand {
                     getKadmin().updatePassword(principal, password);
                     System.out.println("Update password success.");
                 } catch (KrbException e) {
-                    System.err.println("Fail to update password. " + e.getCause());
+                    System.err.println("Fail to update password. " + e.getMessage());
                 }
             } else if (kOptions.contains(KadminOption.RANDKEY)) {
                 try {
                     getKadmin().updateKeys(principal);
                 } catch (KrbException e) {
-                    System.err.println("Fail to update key. " + e.getCause());
+                    System.err.println("Fail to update key. " + e.getMessage());
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/DeletePrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/DeletePrincipalCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/DeletePrincipalCommand.java
index af2c0e2..feb0534 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/DeletePrincipalCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/DeletePrincipalCommand.java
@@ -79,7 +79,7 @@ public class DeletePrincipalCommand extends KadminCommand {
             kadmin.deletePrincipal(principal);
             System.out.println("Principal \"" + principal + "\" deleted.");
         } catch (KrbException e) {
-            System.err.println("Fail to delete principal \"" + principal + "\" ." + e.getCause());
+            System.err.println("Fail to delete principal \"" + principal + "\" ." + e.getMessage());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/GetPrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/GetPrincipalCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/GetPrincipalCommand.java
index 2b63db6..c029935 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/GetPrincipalCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/GetPrincipalCommand.java
@@ -49,7 +49,7 @@ public class GetPrincipalCommand extends KadminCommand {
         try {
             identity = getKadmin().getPrincipal(princName);
         } catch (KrbException e) {
-            System.err.println("Fail to get principal: " + princName + ". " + e.getCause());
+            System.err.println("Fail to get principal: " + princName + ". " + e.getMessage());
         }
 
         if (identity == null) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/KeytabAddCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/KeytabAddCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/KeytabAddCommand.java
index 9cdf9b4..9777a4b 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/KeytabAddCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/KeytabAddCommand.java
@@ -74,7 +74,7 @@ public class KeytabAddCommand extends KadminCommand {
             System.out.println("Done!");
         } catch (KrbException e) {
             System.err.println("Principal \"" + principal + "\" fail to add entry to keytab."
-                    + e.getCause());
+                    + e.getMessage());
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
index 63415ab..7ff18ac 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
@@ -57,7 +57,7 @@ public class ModifyPrincipalCommand extends KadminCommand {
             getKadmin().modifyPrincipal(principal, kOptions);
             System.out.println("Principal \"" + principal + "\" modified.");
         } catch (KrbException e) {
-            System.err.println("Principal \"" + principal + "\" fail to modify. " + e.getCause());
+            System.err.println("Principal \"" + principal + "\" fail to modify. " + e.getMessage());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/14025c73/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
index 9edac54..32ac090 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
@@ -74,7 +74,7 @@ public class RenamePrincipalCommand extends KadminCommand {
             System.out.println("Principal \"" + oldPrincipalName + "\" renamed to \""
                     + newPrincipalName + "\".");
         } catch (KrbException e) {
-            System.err.println("Principal rename failed! Exception happened. " + e.getCause());
+            System.err.println("Principal rename failed! Exception happened. " + e.getMessage());
         }
     }
 }


Mime
View raw message