directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject directory-kerby git commit: DIRKRB-186 Determine whether the principal exists before adding to json-backend
Date Mon, 23 Mar 2015 01:53:03 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master f3f0245f5 -> 23c0a9dbb


DIRKRB-186 Determine whether the principal exists before adding to json-backend


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

Branch: refs/heads/master
Commit: 23c0a9dbb54cdaf36e16dbbb51784b0422927304
Parents: f3f0245
Author: hazel <linchen7@foxmail.com>
Authored: Mon Mar 23 09:52:56 2015 +0800
Committer: hazel <linchen7@foxmail.com>
Committed: Mon Mar 23 09:52:56 2015 +0800

----------------------------------------------------------------------
 .../kerberos/kdc/identitybackend/JsonIdentityBackend.java      | 6 ++++++
 .../kerberos/tool/kadmin/executor/AddPrincipalExecutor.java    | 6 +++++-
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/23c0a9db/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 36e1703..7db5ffd 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
@@ -123,6 +123,12 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
     @Override
     protected KrbIdentity doAddIdentity(KrbIdentity identity) {
         checkAndLoad();
+
+        String principal = identity.getPrincipalName();
+        if (ids.containsKey(principal)) {
+            throw new RuntimeException("Principal already exists.");
+        }
+
         ids.put(identity.getPrincipalName(), identity);
         idsToFile(ids);
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/23c0a9db/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
index d67a16e..33a6f6c 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
@@ -133,7 +133,11 @@ public class AddPrincipalExecutor implements KadminCommandExecutor{
         IdentityBackend backend = initBackend();
 
         KrbIdentity identity = createIdentity(principal, password);
-        backend.addIdentity(identity);
+        try {
+            backend.addIdentity(identity);
+        } catch (Exception e) {
+            System.err.println("Principal or policy already exists while creating \"" + principal
+ "\".");
+        }
     }
 
     private IdentityBackend initBackend() {


Mime
View raw message