directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [2/2] directory-kerby git commit: DIRKRB-229 Enhance kadmin to support list principals. Contributed by Yaning
Date Thu, 21 May 2015 12:41:59 GMT
DIRKRB-229 Enhance kadmin to support list principals. 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/a2128ad7
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/a2128ad7
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/a2128ad7

Branch: refs/heads/master
Commit: a2128ad79f504aa1747705b966021ff2dcb7af42
Parents: 6376258
Author: Lin <linchen7@foxmail.com>
Authored: Thu May 21 20:40:59 2015 +0800
Committer: Lin <linchen7@foxmail.com>
Committed: Thu May 21 20:40:59 2015 +0800

----------------------------------------------------------------------
 .../identitybackend/JsonIdentityBackend.java    |  8 +++
 .../identitybackend/LdapIdentityBackend.java    |  6 +++
 .../ZookeeperIdentityBackend.java               |  6 +++
 .../kerberos/kerb/identity/IdentityService.java |  7 +++
 .../identity/backend/MemoryIdentityBackend.java |  6 +++
 .../kerby/kerberos/tool/kadmin/Kadmin.java      |  4 ++
 .../kadmin/executor/ListPrincipalExcutor.java   | 55 ++++++++++++++++++++
 7 files changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/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 4c89db6..7934ae9 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
@@ -177,6 +177,14 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
         return principals;
     }
 
+    @Override
+    public List<String> getIdentities() {
+        List<String> principals = new ArrayList<>(ids.keySet());
+        Collections.sort(principals);
+
+        return principals;
+    }
+
     private void createGson() {
         GsonBuilder gsonBuilder = new GsonBuilder();
         gsonBuilder.registerTypeAdapter(EncryptionKey.class, new EncryptionKeyAdapter());

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
index e84c04a..ab9c398 100644
--- a/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
+++ b/kerby-backend/ldap-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/LdapIdentityBackend.java
@@ -80,4 +80,10 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
     public List<String> getIdentities(int start, int limit) {
         return null;
     }
+
+    @Override
+    public List<String> getIdentities() {
+        //TODO
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/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 743c2b9..654689b 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
@@ -219,6 +219,12 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
         return newIdentities.subList(start, limit);
     }
 
+    @Override
+    public List<String> getIdentities() {
+        //TODO
+        return null;
+    }
+
     private void setIdentity(KrbIdentity identity) throws KeeperException {
         String principalName = identity.getPrincipalName();
         principalName = replaceSlash(principalName);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/IdentityService.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/IdentityService.java
b/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/IdentityService.java
index 6083cf0..9086fdc 100644
--- a/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/IdentityService.java
+++ b/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/IdentityService.java
@@ -34,6 +34,13 @@ public interface IdentityService {
     List<String> getIdentities(int start, int limit);
 
     /**
+     * Get the identity principal names,
+     * Note it's ordered by principal name.
+     * @return principal names
+     */
+    List<String> getIdentities();
+
+    /**
      * Get the identity account specified by name.
      * @param principalName
      * @return identity

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/MemoryIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/MemoryIdentityBackend.java
b/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/MemoryIdentityBackend.java
index 1ea780c..68742ee 100644
--- a/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/MemoryIdentityBackend.java
+++ b/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/MemoryIdentityBackend.java
@@ -58,4 +58,10 @@ public class MemoryIdentityBackend extends AbstractIdentityBackend {
     public List<String> getIdentities(int start, int limit) {
         return new ArrayList<>(getCache().keySet());
     }
+
+    @Override
+    public List<String> getIdentities() {
+        //TODO
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
index 39e429d..c6c3112 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
@@ -95,6 +95,10 @@ public class Kadmin {
         } else if (command.startsWith("get_principal") || command.startsWith("getprinc")
||
                 command.startsWith("Get principal")) {
             executor = new GetPrincipalExcutor(backendConfig);
+        } else if (command.startsWith("list_principals") ||
+                command.startsWith("listprincs") || command.startsWith("get_principals")
||
+                command.startsWith("getprincs") || command.startsWith("List principals"))
{
+            executor = new ListPrincipalExcutor(backendConfig);
         }
         if (executor == null) {
             System.out.println("Unknown request \"" + command + "\". Type \"?\" for a request
list.");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a2128ad7/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
new file mode 100644
index 0000000..49f9f4f
--- /dev/null
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
@@ -0,0 +1,55 @@
+/**
+ *  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.kerberos.tool.kadmin.executor;
+
+import org.apache.kerby.config.Config;
+import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
+import org.apache.kerby.kerberos.tool.kadmin.tool.KadminTool;
+
+import java.util.List;
+
+public class ListPrincipalExcutor implements KadminCommandExecutor {
+    private Config backenConfig;
+
+    public ListPrincipalExcutor(Config backenConfig) {
+        this.backenConfig = backenConfig;
+    }
+
+    @Override
+    public void execute(String input) {
+        String[] commands = input.split(" ");
+        List<String> principalNames = null;
+
+        if (commands.length == 1) {
+            principalNames = listPrincipal();
+        }
+        System.out.println("Principals are listed:");
+
+        for (String principalName : principalNames) {
+            System.out.println(principalName);
+        }
+    }
+
+    private List<String> listPrincipal() {
+        IdentityBackend backend = KadminTool.getBackend(backenConfig);
+        List<String> principalName = backend.getIdentities();
+        return principalName;
+    }
+}


Mime
View raw message