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-168 Adding a json file based identity backend.
Date Wed, 18 Mar 2015 02:54:34 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 479f28061 -> 0302ee9f5


DIRKRB-168 Adding a json file based identity 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/0302ee9f
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/0302ee9f
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/0302ee9f

Branch: refs/heads/master
Commit: 0302ee9f5f404efe22c55546ddf51f10d9921c9d
Parents: 479f280
Author: hazel <linchen7@foxmail.com>
Authored: Wed Mar 18 10:54:27 2015 +0800
Committer: hazel <linchen7@foxmail.com>
Committed: Wed Mar 18 10:54:27 2015 +0800

----------------------------------------------------------------------
 .../identitybackend/JsonIdentityBackend.java    | 114 +++++++++++++++----
 .../kdc/identitybackend/tool/FileHelper.java    |  74 ++++++++++++
 .../typeAdapter/EncryptionKeyAdapter.java       |  67 +++++++++++
 .../typeAdapter/KerberosTimeAdapter.java        |  45 ++++++++
 .../typeAdapter/PrincipalNameAdapter.java       |  42 +++++++
 .../kerb/identity/backend/JsonBackendTest.java  |  36 ++++++
 .../kerby/kerberos/kerb/spec/KerberosTime.java  |   4 +-
 kerby-kerb/kerb-identity-test/pom.xml           |   5 +
 .../kerb/identity/backend/BackendTest.java      |  52 ++++++++-
 9 files changed, 413 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
index d23a720..1236529 100644
--- a/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
+++ b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/JsonIdentityBackend.java
@@ -19,15 +19,24 @@
  */
 package org.apache.kerby.kerberos.kdc.identitybackend;
 
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
 import org.apache.kerby.config.Config;
+import org.apache.kerby.kerberos.kdc.identitybackend.tool.FileHelper;
+import org.apache.kerby.kerberos.kdc.identitybackend.typeAdapter.EncryptionKeyAdapter;
+import org.apache.kerby.kerberos.kdc.identitybackend.typeAdapter.KerberosTimeAdapter;
+import org.apache.kerby.kerberos.kdc.identitybackend.typeAdapter.PrincipalNameAdapter;
 import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
 import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
-import org.apache.kerby.kerberos.kerb.identity.backend.MemoryIdentityBackend;
+import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.util.List;
+import java.util.*;
+import java.util.Map.Entry;
 
 /**
  * A Json file based backend implementation.
@@ -37,6 +46,13 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
     public static final String JSON_IDENTITY_BACKEND_FILE = "backend.json.file";
     private Config config;
     private File jsonKdbFile;
+    private Gson gson;
+
+    /**
+     * Identities loaded from file
+     */
+    private Map<String, KrbIdentity> ids;
+    private long kdbFileTimeStamp;
 
     /**
      * Constructing an instance using specified config that contains anything
@@ -47,10 +63,18 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
         this.config = config;
     }
 
+    @Override
+    public void initialize() {
+        super.initialize();
+        createGson();
+        load();
+        setCacheSize(0);
+    }
+
     /**
      * Load identities from file
      */
-    public void load() throws IOException {
+    public void load() {
         String jsonFile = config.getString(JSON_IDENTITY_BACKEND_FILE);
         if (jsonFile == null || jsonFile.isEmpty()) {
             throw new RuntimeException("No json kdb file is found");
@@ -58,46 +82,98 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
 
         jsonKdbFile = new File(jsonFile);
         if (! jsonKdbFile.exists()) {
-            throw new FileNotFoundException("File not found:" + jsonFile);
+            try {
+                jsonKdbFile.createNewFile();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
 
-        // TODO: load the kdb file.
-    }
-
-    private void checkAndLoad() {
-        // TODO: check kdb file timestamp to see if it's changed or not. If
-        // necessary load the kdb again.
+        checkAndLoad();
     }
 
     /**
-     * Persist the updated identities back
+     * check kdb file timestamp to see if it's changed or not. If
+     * necessary load the kdb again.
      */
-    public void save() {
-        // TODO: save into the kdb file
+    private void checkAndLoad() {
+        long nowTimeStamp = jsonKdbFile.lastModified();
+
+        if (kdbFileTimeStamp == 0 || nowTimeStamp != kdbFileTimeStamp) {
+            //load ids
+            String existsFileJson = FileHelper.getStringFromFile(jsonKdbFile);
+
+            ids = gson.fromJson(existsFileJson,
+                    new TypeToken<LinkedHashMap<String, KrbIdentity>>() {
+                    }.getType());
+        }
+
+        if (ids == null) {
+            ids = new LinkedHashMap<>();
+        }
     }
 
     @Override
     protected KrbIdentity doGetIdentity(String principalName) {
-        return null;
+        checkAndLoad();
+        return ids.get(principalName);
     }
 
     @Override
     protected KrbIdentity doAddIdentity(KrbIdentity identity) {
-        return null;
+        checkAndLoad();
+        ids.put(identity.getPrincipalName(), identity);
+        idsToFile(ids);
+
+        return identity;
     }
 
     @Override
     protected KrbIdentity doUpdateIdentity(KrbIdentity identity) {
-        return null;
+        checkAndLoad();
+        ids.put(identity.getPrincipalName(), identity);
+        idsToFile(ids);
+
+        return identity;
     }
 
     @Override
     protected void doDeleteIdentity(String principalName) {
-
+        checkAndLoad();
+        ids.remove(principalName);
+        idsToFile(ids);
     }
 
     @Override
     public List<String> getIdentities(int start, int limit) {
-        return null;
+        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 = new ArrayList<>();
+        for (; index < limit; index++) {
+            Entry<String, KrbIdentity> entry = iterator.next();
+            principals.add(entry.getKey());
+        }
+
+        return principals;
+    }
+
+    private void createGson() {
+        GsonBuilder gsonBuilder = new GsonBuilder();
+        gsonBuilder.registerTypeAdapter(EncryptionKey.class, new EncryptionKeyAdapter());
+        gsonBuilder.registerTypeAdapter(PrincipalName.class, new PrincipalNameAdapter());
+        gsonBuilder.registerTypeAdapter(KerberosTime.class, new KerberosTimeAdapter());
+        gsonBuilder.enableComplexMapKeySerialization();
+        gson = gsonBuilder.create();
+    }
+
+    private void idsToFile(Map<String, KrbIdentity> ids) {
+        String newFileJson = gson.toJson(ids);
+        FileHelper.writeStringToFile(newFileJson, jsonKdbFile);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/tool/FileHelper.java
----------------------------------------------------------------------
diff --git a/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/tool/FileHelper.java
b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/tool/FileHelper.java
new file mode 100644
index 0000000..163c6b3
--- /dev/null
+++ b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/tool/FileHelper.java
@@ -0,0 +1,74 @@
+/**
+ *  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.kdc.identitybackend.tool;
+
+import java.io.*;
+
+public class FileHelper {
+
+    public static String getStringFromFile(File file) {
+        assert (file != null);
+
+        BufferedReader reader = null;
+        try {
+            FileInputStream fileInputStream = new FileInputStream(file);
+            reader = new BufferedReader(new InputStreamReader(fileInputStream));
+            StringBuilder stringBuilder = new StringBuilder();
+            String line = null;
+            while ((line = reader.readLine()) != null) {
+                stringBuilder.append(line);
+            }
+            return stringBuilder.toString();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (reader != null) {
+                    reader.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+        return null;
+    }
+
+    public static void writeStringToFile(String string, File file) {
+        assert (file != null);
+
+        BufferedWriter bufferedWriter = null;
+        try {
+            FileWriter fileWriter = new FileWriter(file);
+            bufferedWriter = new BufferedWriter(fileWriter);
+            bufferedWriter.write(string);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (bufferedWriter != null){
+                    bufferedWriter.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
----------------------------------------------------------------------
diff --git a/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
new file mode 100644
index 0000000..96d504d
--- /dev/null
+++ b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/EncryptionKeyAdapter.java
@@ -0,0 +1,67 @@
+/**
+ *  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.kdc.identitybackend.typeAdapter;
+
+import com.google.gson.*;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
+
+import java.lang.reflect.Type;
+
+public class EncryptionKeyAdapter implements JsonSerializer<EncryptionKey>,
+        JsonDeserializer<EncryptionKey> {
+
+    @Override
+    public EncryptionKey deserialize(JsonElement jsonElement, Type type,
+                                     JsonDeserializationContext jsonDeserializationContext)
+            throws JsonParseException {
+        JsonObject jsonObject = (JsonObject) jsonElement;
+        EncryptionKey encryptionKey = new EncryptionKey();
+        encryptionKey.setKvno(jsonObject.get("kvno").getAsInt());
+        String encryptionTypeString = jsonObject.get("keyType").getAsString();
+        EncryptionType encryptionType = EncryptionType.fromName(encryptionTypeString);
+        encryptionKey.setKeyType(encryptionType);
+
+        JsonArray jsonArray = jsonObject.get("keyData").getAsJsonArray();
+        byte[] keyData = new byte[jsonArray.size()];
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JsonElement element = jsonArray.get(i);
+            keyData[i] = element.getAsByte();
+        }
+        encryptionKey.setKeyData(keyData);
+        return encryptionKey;
+    }
+
+    @Override
+    public JsonElement serialize(EncryptionKey encryptionKey,
+                                 Type type, JsonSerializationContext jsonSerializationContext)
{
+        JsonObject jsonObject = new JsonObject();
+        jsonObject.addProperty("kvno", encryptionKey.getKvno());
+        jsonObject.addProperty("keyType", encryptionKey.getKeyType().getName());
+
+        JsonArray jsonArray = new JsonArray();
+        byte[] keyData = encryptionKey.getKeyData();
+        for (byte aData : keyData) {
+            jsonArray.add(new JsonPrimitive(aData));
+        }
+        jsonObject.add("keyData", jsonArray);
+        return jsonObject;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/KerberosTimeAdapter.java
----------------------------------------------------------------------
diff --git a/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/KerberosTimeAdapter.java
b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/KerberosTimeAdapter.java
new file mode 100644
index 0000000..b4f6a85
--- /dev/null
+++ b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/KerberosTimeAdapter.java
@@ -0,0 +1,45 @@
+/**
+ *  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.kdc.identitybackend.typeAdapter;
+
+import com.google.gson.*;
+import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+
+import java.lang.reflect.Type;
+
+public class KerberosTimeAdapter implements JsonSerializer<KerberosTime>,
+        JsonDeserializer<KerberosTime> {
+
+    @Override
+    public KerberosTime deserialize(JsonElement jsonElement, Type type,
+                                    JsonDeserializationContext jsonDeserializationContext)
+            throws JsonParseException {
+        String timeString = jsonElement.getAsString();
+        long time = Long.valueOf(timeString);
+        return new KerberosTime(time);
+    }
+
+    @Override
+    public JsonElement serialize(KerberosTime kerberosTime, Type type,
+                                 JsonSerializationContext jsonSerializationContext) {
+        String timeString = String.valueOf(kerberosTime.getTime());
+        return new JsonPrimitive(timeString);
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/PrincipalNameAdapter.java
----------------------------------------------------------------------
diff --git a/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/PrincipalNameAdapter.java
b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/PrincipalNameAdapter.java
new file mode 100644
index 0000000..7b59ed7
--- /dev/null
+++ b/kdc-backend/json-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/typeAdapter/PrincipalNameAdapter.java
@@ -0,0 +1,42 @@
+/**
+ *  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.kdc.identitybackend.typeAdapter;
+
+import com.google.gson.*;
+import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
+
+import java.lang.reflect.Type;
+
+public class PrincipalNameAdapter implements JsonSerializer<PrincipalName>,
+        JsonDeserializer<PrincipalName> {
+
+    @Override
+    public PrincipalName deserialize(JsonElement jsonElement, Type type,
+                                     JsonDeserializationContext jsonDeserializationContext)
+            throws JsonParseException {
+        return new PrincipalName(jsonElement.getAsString());
+    }
+
+    @Override
+    public JsonElement serialize(PrincipalName principalName,
+                                 Type type, JsonSerializationContext jsonSerializationContext)
{
+        return new JsonPrimitive(principalName.getName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kdc-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
----------------------------------------------------------------------
diff --git a/kdc-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
b/kdc-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
index 71194a3..ad8140c 100644
--- a/kdc-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
+++ b/kdc-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
@@ -19,20 +19,56 @@
  */
 package org.apache.kerby.kerberos.kerb.identity.backend;
 
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.config.Config;
+import org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend;
+import org.junit.Before;
 import org.junit.Test;
 
+import java.io.File;
+
 /**
  * Json backend test
  */
 public class JsonBackendTest extends BackendTest {
     private IdentityBackend backend;
+    private String jsonBackendFileString;
 
+    @Before
     public void setup() {
+        File testDir = new File(System.getProperty("test.dir", "target"));
+        jsonBackendFileString = new File(testDir, "json-identity-backend-file").getAbsolutePath();
+
+        Config backendConfig = new Conf();
+        backendConfig.setString(JsonIdentityBackend.JSON_IDENTITY_BACKEND_FILE, jsonBackendFileString);
 
+        backend = new JsonIdentityBackend(backendConfig);
+        backend.initialize();
     }
 
     @Test
     public void testGet() {
         super.testGet(backend);
     }
+
+    @Test
+    public void testStore() {
+        super.testStore(backend);
+    }
+
+    @Test
+    public void testUpdate() {
+        super.testUpdate(backend);
+    }
+
+    @Test
+    public void testDelete() {
+        super.testDelete(backend);
+    }
+
+    @Test
+    public void testGetIdentities() {
+        super.testGetIdentities(backend);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KerberosTime.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KerberosTime.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KerberosTime.java
index cb10933..8ed8061 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KerberosTime.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/KerberosTime.java
@@ -118,11 +118,11 @@ public class KerberosTime extends Asn1GeneralizedTime {
         if (o == null || getClass() != o.getClass()) return false;
 
         KerberosTime time = (KerberosTime) o;
-        return this.getTime() == time.getTime();
+        return this.getValue().equals(time.getValue());
     }
 
     @Override
     public int hashCode() {
-        return 31 * (int) this.getTime();
+        return getValue().hashCode();
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kerby-kerb/kerb-identity-test/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/pom.xml b/kerby-kerb/kerb-identity-test/pom.xml
index b288ee6..18437f7 100644
--- a/kerby-kerb/kerb-identity-test/pom.xml
+++ b/kerby-kerb/kerb-identity-test/pom.xml
@@ -52,5 +52,10 @@
       <artifactId>kerb-identity</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/0302ee9f/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
index 3f2a4d7..19c47cb 100644
--- a/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
+++ b/kerby-kerb/kerb-identity-test/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/BackendTest.java
@@ -30,6 +30,8 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 /**
  * A common backend test utility
  */
@@ -39,29 +41,69 @@ public abstract class BackendTest {
 
     static final EncryptionType[] encTypes = new EncryptionType[]{
             EncryptionType.AES128_CTS,
-            EncryptionType.AES256_CTS,
-            EncryptionType.ARCFOUR_HMAC,
-            EncryptionType.CAMELLIA128_CTS,
-            EncryptionType.CAMELLIA256_CTS_CMAC
+            EncryptionType.DES3_CBC_SHA1_KD
     };
 
     protected void testGet(IdentityBackend backend) {
+        KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
+        backend.addIdentity(kid);
 
+        assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNotNull();
+
+        //tearDown
+        backend.deleteIdentity(TEST_PRINCIPAL);
     }
 
     protected void testStore(IdentityBackend backend) {
         KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
         backend.addIdentity(kid);
         KrbIdentity kid2 = backend.getIdentity(TEST_PRINCIPAL);
-        // kid == kid2
+
+        assertThat(kid).isEqualTo(kid2);
+
+        //tearDown
+        backend.deleteIdentity(TEST_PRINCIPAL);
     }
 
     protected void testUpdate(IdentityBackend backend) {
+        KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
+        backend.addIdentity(kid);
+
+        kid.setDisabled(true);
+        backend.updateIdentity(kid);
+
+        assertThat(backend.getIdentity(TEST_PRINCIPAL)).isEqualTo(kid);
 
+        //tearDown
+        backend.deleteIdentity(TEST_PRINCIPAL);
     }
 
     protected void testDelete(IdentityBackend backend) {
+        KrbIdentity kid = createOneIdentity(TEST_PRINCIPAL);
+        backend.addIdentity(kid);
+        assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNotNull();
+
+        backend.deleteIdentity(TEST_PRINCIPAL);
+        assertThat(backend.getIdentity(TEST_PRINCIPAL)).isNull();
+    }
+
+    protected void testGetIdentities(IdentityBackend backend) {
+        KrbIdentity[] identities = createManyIdentities();
 
+        for (KrbIdentity identity : identities) {
+            backend.addIdentity(identity);
+        }
+
+        List<String> principals = backend.getIdentities(2, 5);
+        assertThat(principals).hasSize(3)
+                .contains(identities[2].getPrincipalName())
+                .contains(identities[3].getPrincipalName())
+                .contains(identities[4].getPrincipalName());
+
+        //tearDown
+        for (KrbIdentity identity : identities) {
+            backend.deleteIdentity(identity.getPrincipalName());
+        }
     }
 
     protected KrbIdentity[] createManyIdentities() {


Mime
View raw message