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-310]-Having getIdentities method to implement page search in the backend. Contributed by Yaning.
Date Thu, 02 Jul 2015 05:43:57 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master dca5fdb56 -> 9170df749


[DIRKRB-310]-Having getIdentities method to implement page search in the backend. 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/9170df74
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/9170df74
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/9170df74

Branch: refs/heads/master
Commit: 9170df7491903d23f44b72bcd1d1305d5ef797d6
Parents: dca5fdb
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Thu Jul 2 13:49:24 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Thu Jul 2 13:49:24 2015 +0800

----------------------------------------------------------------------
 .../identitybackend/JsonIdentityBackend.java    | 23 +++++++-------------
 .../identitybackend/LdapIdentityBackend.java    | 16 ++++++++++----
 .../java/org/apache/kerby/MavibotBackend.java   | 20 ++++-------------
 .../ZookeeperIdentityBackend.java               | 10 +++++++--
 .../kerby/kerberos/kerb/admin/Kadmin.java       |  4 ++--
 .../kerb/identity/backend/BackendTest.java      |  4 ++--
 .../kerberos/kerb/identity/IdentityService.java |  7 ------
 .../identity/backend/MemoryIdentityBackend.java |  4 ++--
 8 files changed, 38 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/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 63ca31e..199c72f 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
@@ -36,7 +36,6 @@ import org.apache.kerby.util.IOUtil;
 import java.io.File;
 import java.io.IOException;
 import java.util.*;
-import java.util.Map.Entry;
 
 /**
  * A Json file based backend implementation.
@@ -163,27 +162,21 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
         idsToFile(ids);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public List<String> getIdentities(int start, int limit) {
-        LinkedHashMap<String, KrbIdentity> linkedIds = (LinkedHashMap<String, KrbIdentity>)
ids;
-        Iterator<Entry<String, KrbIdentity>> iterator = linkedIds.entrySet().iterator();
-
-        int index = 0;
-        for(; index < start; index++) {
-            iterator.next();
-        }
+        List<String> principals =getIdentities();
 
-        List<String> principals = new ArrayList<>();
-        for (; index < limit; index++) {
-            Entry<String, KrbIdentity> entry = iterator.next();
-            principals.add(entry.getKey());
+        if (limit == -1) {
+            return principals;
         }
 
-        return principals;
+        return getIdentities().subList(start, start + limit);
     }
 
-    @Override
-    public List<String> getIdentities() {
+    private List<String> getIdentities() {
         List<String> principals = new ArrayList<>(ids.keySet());
         Collections.sort(principals);
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/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 f942151..4ebd35c 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
@@ -250,14 +250,22 @@ public class LdapIdentityBackend extends AbstractIdentityBackend {
         return dn;
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public List<String> getIdentities(int start, int limit) {
-        List<String> identityNames = getIdentities();
-        return identityNames.subList(start, limit);
+        List<String> identities = getIdentities();
+
+        if (limit == -1) {
+            return identities;
+        }
+
+        return getIdentities().subList(start, start + limit);
     }
 
-    @Override
-    public List<String> getIdentities() {
+
+    private List<String> getIdentities() {
         List<String> identityNames = new ArrayList<>();
         EntryCursor cursor;
         Entry entry;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/kerby-backend/mavibot/src/main/java/org/apache/kerby/MavibotBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot/src/main/java/org/apache/kerby/MavibotBackend.java b/kerby-backend/mavibot/src/main/java/org/apache/kerby/MavibotBackend.java
index 5f1d2e1..50aef65 100644
--- a/kerby-backend/mavibot/src/main/java/org/apache/kerby/MavibotBackend.java
+++ b/kerby-backend/mavibot/src/main/java/org/apache/kerby/MavibotBackend.java
@@ -19,18 +19,14 @@
  */
 package org.apache.kerby;
 
-import java.io.File;
-import java.util.List;
-
-import org.apache.directory.mavibot.btree.BTree;
-import org.apache.directory.mavibot.btree.BTreeFactory;
-import org.apache.directory.mavibot.btree.BTreeTypeEnum;
-import org.apache.directory.mavibot.btree.PersistedBTreeConfiguration;
-import org.apache.directory.mavibot.btree.RecordManager;
+import org.apache.directory.mavibot.btree.*;
 import org.apache.directory.mavibot.btree.serializer.StringSerializer;
 import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
 import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
 
+import java.io.File;
+import java.util.List;
+
 /**
  * A backend based on Apache Mavibot(an MVCC BTree library).
  *
@@ -99,14 +95,6 @@ public class MavibotBackend extends AbstractIdentityBackend {
      * {@inheritDoc}
      */
     @Override
-    public List<String> getIdentities() {
-        return null;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
     protected KrbIdentity doGetIdentity(String principalName) {
         return null;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/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 06e9d4d..d7e6864 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
@@ -242,12 +242,18 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
         }
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public List<String> getIdentities(int start, int limit) {
-        return getIdentities().subList(start, limit);
+        if (limit == -1) {
+            return getIdentities();
+        }
+
+        return getIdentities().subList(start, start + limit);
     }
 
-    @Override
     public List<String> getIdentities() {
 
         List<String> identityNames = null;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/Kadmin.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/Kadmin.java
b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/Kadmin.java
index 83ead42..030bd18 100644
--- a/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/Kadmin.java
+++ b/kerby-kerb/kerb-admin/src/main/java/org/apache/kerby/kerberos/kerb/admin/Kadmin.java
@@ -170,7 +170,7 @@ public class Kadmin {
     public void exportKeytab(File keytabFile) throws KrbException {
         Keytab keytab = AdminHelper.createOrLoadKeytab(keytabFile);
 
-        List<String> principals = backend.getIdentities();
+        List<String> principals = backend.getIdentities(0, -1);
         for (String principal : principals) {
             KrbIdentity identity = backend.getIdentity(principal);
             if (identity != null) {
@@ -243,7 +243,7 @@ public class Kadmin {
     }
 
     public List<String> getPrincipals() throws KrbException {
-        List<String> principalNames = backend.getIdentities();
+        List<String> principalNames = backend.getIdentities(0, -1);
         return principalNames;
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
b/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
index b87e071..8960060 100644
--- a/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
+++ b/kerby-kerb/kerb-identity-test/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
@@ -117,7 +117,7 @@ public abstract class BackendTest {
         // clear the identity cache.
         backend.release();
 
-        List<String> principals = backend.getIdentities(2, 5);
+        List<String> principals = backend.getIdentities(2, 3);
         assertThat(principals).hasSize(3)
                 .contains(identities[2].getPrincipalName())
                 .contains(identities[3].getPrincipalName())
@@ -165,7 +165,7 @@ public abstract class BackendTest {
     }
 
     protected void cleanIdentities(IdentityBackend backend) {
-        List<String> identities = backend.getIdentities();
+        List<String> identities = backend.getIdentities(0, -1);
         if (identities != null) {
             for (String identity : identities) {
                 backend.deleteIdentity(identity);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9170df74/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 9086fdc..6083cf0 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,13 +34,6 @@ 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/9170df74/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 cb6e52c..0678c89 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
@@ -60,8 +60,8 @@ public class MemoryIdentityBackend extends AbstractIdentityBackend {
         return getIdentities().subList(start, limit);
     }
 
-    @Override
-    public List<String> getIdentities() {
+
+    private List<String> getIdentities() {
         List<String> identities = new ArrayList<>(getCache().keySet());
         Collections.sort(identities);
         return identities;


Mime
View raw message