You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2015/07/08 09:39:29 UTC
directory-kerby git commit: Renamed mavibot module dir to
mavibot-backend to be consistent with backends
Repository: directory-kerby
Updated Branches:
refs/heads/master f82e49764 -> 58665d358
Renamed mavibot module dir to mavibot-backend to be consistent with backends
Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/58665d35
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/58665d35
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/58665d35
Branch: refs/heads/master
Commit: 58665d358dc6644f3d89ee783157c169a72590a0
Parents: f82e497
Author: drankye <ka...@intel.com>
Authored: Wed Jul 8 15:39:00 2015 +0800
Committer: Drankye <dr...@gmail.com>
Committed: Wed Jul 8 15:39:00 2015 +0800
----------------------------------------------------------------------
kerby-backend/mavibot-backend/pom.xml | 46 +++++
.../org/apache/kerby/KrbIdentityComparator.java | 43 ++++
.../org/apache/kerby/KrbIdentitySerializer.java | 182 +++++++++++++++++
.../java/org/apache/kerby/MavibotBackend.java | 200 +++++++++++++++++++
.../apache/kerby/KrbIdentitySerializerTest.java | 106 ++++++++++
.../org/apache/kerby/MavibotBackendTest.java | 82 ++++++++
kerby-backend/mavibot/pom.xml | 46 -----
.../org/apache/kerby/KrbIdentityComparator.java | 43 ----
.../org/apache/kerby/KrbIdentitySerializer.java | 182 -----------------
.../java/org/apache/kerby/MavibotBackend.java | 200 -------------------
.../apache/kerby/KrbIdentitySerializerTest.java | 106 ----------
.../org/apache/kerby/MavibotBackendTest.java | 82 --------
12 files changed, 659 insertions(+), 659 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/pom.xml b/kerby-backend/mavibot-backend/pom.xml
new file mode 100644
index 0000000..cc5dfa8
--- /dev/null
+++ b/kerby-backend/mavibot-backend/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerby-backend</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>mavibot-backend</artifactId>
+ <name>Mavibot based backend</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.directory.mavibot</groupId>
+ <artifactId>mavibot</artifactId>
+ <version>1.0.0-M8-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerby-config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerb-identity</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerb-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerb-identity-test</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentityComparator.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentityComparator.java b/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentityComparator.java
new file mode 100644
index 0000000..bce3033
--- /dev/null
+++ b/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentityComparator.java
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import java.util.Comparator;
+
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+
+/**
+ * Comparator for KrbIdentity
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public final class KrbIdentityComparator implements Comparator<KrbIdentity> {
+
+ public static final KrbIdentityComparator INSTANCE = new KrbIdentityComparator();
+
+ private KrbIdentityComparator() {
+ }
+
+ @Override
+ public int compare(KrbIdentity o1, KrbIdentity o2) {
+ return o1.getPrincipalName().compareTo(o2.getPrincipalName());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentitySerializer.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentitySerializer.java b/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentitySerializer.java
new file mode 100644
index 0000000..b63c9a4
--- /dev/null
+++ b/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/KrbIdentitySerializer.java
@@ -0,0 +1,182 @@
+/*
+ * 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;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Comparator;
+import java.util.Map;
+
+import org.apache.directory.mavibot.btree.serializer.BufferHandler;
+import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+import org.apache.directory.mavibot.btree.serializer.IntSerializer;
+import org.apache.directory.mavibot.btree.serializer.LongSerializer;
+import org.apache.directory.mavibot.btree.serializer.StringSerializer;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
+
+/**
+ * Serializer for KrbIdentity.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class KrbIdentitySerializer implements ElementSerializer<KrbIdentity> {
+ /** the static instance of the serializer */
+ public static final KrbIdentitySerializer INSTANCE = new KrbIdentitySerializer();
+
+ /** comparator for KrbIdentity */
+ private KrbIdentityComparator comparator = KrbIdentityComparator.INSTANCE;
+
+ @Override
+ public byte[] serialize(KrbIdentity entry) {
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ try {
+ // the principalName
+ out.write(StringSerializer.INSTANCE.serialize(entry.getPrincipalName()));
+
+ // key version
+ out.write(IntSerializer.serialize(entry.getKeyVersion()));
+
+ out.write(IntSerializer.serialize(entry.getKdcFlags()));
+
+ // mask for disabled and lock flags
+ byte mask = 0;
+
+ if(entry.isDisabled()) {
+ mask |= 1 << 1;
+ }
+
+ if(entry.isLocked()) {
+ mask |= 1 << 2;
+ }
+
+ out.write(mask);
+
+ // creation time
+ out.write(LongSerializer.serialize(entry.getCreatedTime().getTime()));
+
+ // expiration time
+ out.write(LongSerializer.serialize(entry.getExpireTime().getTime()));
+
+ Map<EncryptionType, EncryptionKey> keys = entry.getKeys();
+ // num keys
+ out.write(IntSerializer.serialize(keys.size()));
+
+ for(EncryptionKey ek : keys.values()) {
+ int type = ek.getKeyType().getValue();
+ out.write(IntSerializer.serialize(type));
+ byte[] data = ek.getKeyData();
+ out.write(IntSerializer.serialize(data.length));
+ out.write(data);
+ }
+
+ return out.toByteArray();
+ }
+ catch(Exception e) {
+ throw new IllegalStateException("Failed to serialize the identity " + entry);
+ }
+ }
+
+ @Override
+ public KrbIdentity deserialize(BufferHandler bufferHandler)
+ throws IOException {
+ return fromBytes(bufferHandler.getBuffer());
+ }
+
+ @Override
+ public KrbIdentity deserialize(ByteBuffer buffer) throws IOException {
+ KrbIdentity id = null;
+
+ String principal = StringSerializer.INSTANCE.deserialize(buffer);
+
+ id = new KrbIdentity(principal);
+
+ int kvno = IntSerializer.INSTANCE.deserialize(buffer);
+ id.setKeyVersion(kvno);
+
+ int flags = IntSerializer.INSTANCE.deserialize(buffer);
+ id.setKdcFlags(flags);
+
+ byte mask = buffer.get();
+
+ if((mask & 2) != 0) {
+ id.setDisabled(true);
+ }
+
+ if((mask & 4) != 0) {
+ id.setLocked(true);
+ }
+
+ long creationTime = LongSerializer.INSTANCE.deserialize(buffer);
+ id.setCreatedTime(new KerberosTime(creationTime));
+
+ long exprTime = LongSerializer.INSTANCE.deserialize(buffer);
+ id.setExpireTime(new KerberosTime(exprTime));
+
+ int numKeys = IntSerializer.INSTANCE.deserialize(buffer);
+
+ for(int i=0; i<numKeys; i++) {
+ int keyType = IntSerializer.INSTANCE.deserialize(buffer);
+ int keyLen = IntSerializer.INSTANCE.deserialize(buffer);
+
+ byte[] keyData = new byte[keyLen];
+ buffer.get(keyData);
+
+ EncryptionKey ek = new EncryptionKey(keyType, keyData);
+
+ id.addKey(ek);
+ }
+
+ return id;
+ }
+
+ @Override
+ public KrbIdentity fromBytes(byte[] buffer) throws IOException {
+ ByteBuffer buf = ByteBuffer.wrap(buffer);
+ return deserialize(buf);
+ }
+
+ @Override
+ public KrbIdentity fromBytes(byte[] buffer, int pos) throws IOException {
+ ByteBuffer buf = ByteBuffer.wrap(buffer, pos, buffer.length - pos);
+ return deserialize(buf);
+ }
+
+ @Override
+ public int compare(KrbIdentity type1, KrbIdentity type2) {
+ return comparator.compare(type1, type2);
+ }
+
+ @Override
+ public Comparator<KrbIdentity> getComparator() {
+ return comparator;
+ }
+
+ @Override
+ public Class<?> getType() {
+ return KrbIdentity.class;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/MavibotBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/MavibotBackend.java b/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/MavibotBackend.java
new file mode 100644
index 0000000..f78f75a
--- /dev/null
+++ b/kerby-backend/mavibot-backend/src/main/java/org/apache/kerby/MavibotBackend.java
@@ -0,0 +1,200 @@
+/*
+ * 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;
+
+import org.apache.directory.mavibot.btree.*;
+import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
+import org.apache.directory.mavibot.btree.serializer.StringSerializer;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A backend based on Apache Mavibot(an MVCC BTree library).
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class MavibotBackend extends AbstractIdentityBackend {
+ //The RecordManager of Mavibot
+ private RecordManager rm;
+
+ //The BTree holding all data
+ private BTree<String, KrbIdentity> database;
+
+ //Name of the database
+ private static final String DATA_TREE = "kerby-data";
+
+ // Name of the database file
+ private static final String DATABASE_NAME = "kerby-data.db";
+
+ private static final Logger LOG = LoggerFactory.getLogger(MavibotBackend.class);
+
+ /**
+ * Creates a new instance of MavibotBackend.
+ *
+ * @param location
+ * the File handle pointing to the database file or the directory
+ * where it is present
+ * @throws Exception
+ */
+ public MavibotBackend(File location) throws Exception {
+ String dbPath = location.getAbsolutePath();
+
+ LOG.info("Initializing the mavibot backend");
+
+ if (!location.exists()) {
+ location.mkdirs();
+ }
+
+ if (location.isDirectory()) {
+ dbPath += File.separator + DATABASE_NAME;
+ }
+
+ rm = new RecordManager(dbPath);
+
+ if (rm.getManagedTrees().contains(DATA_TREE)) {
+ database = rm.getManagedTree(DATA_TREE);
+ } else {
+ PersistedBTreeConfiguration<String, KrbIdentity> config =
+ new PersistedBTreeConfiguration<String, KrbIdentity>();
+ // _no_ duplicates
+ config.setAllowDuplicates(false);
+ config.setBtreeType(BTreeTypeEnum.PERSISTED);
+ config.setFilePath(dbPath);
+ config.setKeySerializer(StringSerializer.INSTANCE);
+ config.setName(DATA_TREE);
+ config.setValueSerializer(KrbIdentitySerializer.INSTANCE);
+
+ database = BTreeFactory.createPersistedBTree(config);
+ rm.manage(database);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected List<String> doGetIdentities(int start, int limit) throws KrbException {
+ List<String> keys = new ArrayList<String>();
+ KeyCursor<String> cursor = null;
+
+ try {
+ cursor = database.browseKeys();
+ while(cursor.hasNext()) {
+ keys.add(cursor.next());
+ }
+ } catch(Exception e) {
+ throw new KrbException("Errors occurred while fetching the principals", e);
+ } finally {
+ if(cursor != null) {
+ cursor.close();
+ }
+ }
+
+ return keys;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected KrbIdentity doGetIdentity(String principalName) throws KrbException {
+ try {
+ return database.get(principalName);
+ } catch(KeyNotFoundException e) {
+ LOG.debug("Identity {} doesn't exist", principalName);
+ return null;
+ } catch(IOException e) {
+ throw new KrbException("Failed to get the identity " + principalName);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected synchronized KrbIdentity doAddIdentity(KrbIdentity identity) throws KrbException {
+ String p = identity.getPrincipalName();
+ try {
+ if(database.hasKey(p)) {
+ throw new KrbException("Identity already exists " + p);
+ }
+
+ return database.insert(p, identity);
+ } catch(KeyNotFoundException e) {
+ throw new KrbException("No such identity exists " + p);
+ } catch(IOException e) {
+ throw new KrbException("Failed to add the identity " + p);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected synchronized KrbIdentity doUpdateIdentity(KrbIdentity identity) throws KrbException {
+ String p = identity.getPrincipalName();
+ try {
+ if(!database.hasKey(p)) {
+ throw new KrbException("No identity found with the principal " + p);
+ }
+
+ database.delete(p);
+
+ return database.insert(p, identity);
+ } catch(Exception e) {
+ throw new KrbException("Failed to update the identity " + p);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doDeleteIdentity(String principalName) throws KrbException {
+ try {
+ Tuple<String, KrbIdentity> t = database.delete(principalName);
+ if (t == null) {
+ throw new KrbException("Not existing, identity = " + principalName);
+ }
+ } catch(IOException e) {
+ throw new KrbException("Failed to delete the identity " + principalName);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doStop() throws KrbException {
+ try {
+ rm.close();
+ } catch(IOException e) {
+ throw new KrbException("Failed to close the database", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java
new file mode 100644
index 0000000..227957a
--- /dev/null
+++ b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java
@@ -0,0 +1,106 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Map;
+
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
+import org.junit.Test;
+
+/**
+ * Tests for KrbIdentity serializer.
+ *
+ * @author <a href="mailto:kerby@directory.apache.org">Apache Kerby Project</a>
+ */
+public class KrbIdentitySerializerTest {
+
+ private KrbIdentitySerializer serializer = KrbIdentitySerializer.INSTANCE;
+
+ @Test
+ public void testSerialization() throws Exception {
+ KrbIdentity entry = new KrbIdentity("hnelson@EXAMPLE.COM");
+ entry.setCreatedTime(new KerberosTime(System.currentTimeMillis()));
+ entry.setDisabled(true);
+ entry.setKeyVersion(1);
+ entry.setLocked(true);
+
+ byte[] junk = new byte[11];
+ Arrays.fill(junk, (byte)1);
+ EncryptionKey key1 = new EncryptionKey(EncryptionType.AES128_CTS, junk);
+ entry.addKey(key1);
+
+ EncryptionKey key2 = new EncryptionKey(EncryptionType.AES128_CTS_HMAC_SHA1_96, junk);
+ entry.addKey(key2);
+
+ byte[] serialized = serializer.serialize(entry);
+
+ KrbIdentity deserialized = serializer.fromBytes(serialized);
+ verifyEquality(entry, deserialized);
+
+ deserialized = serializer.fromBytes(serialized, 0);
+ verifyEquality(entry, deserialized);
+
+ deserialized = serializer.deserialize(ByteBuffer.wrap(serialized));
+ verifyEquality(entry, deserialized);
+
+ try {
+ deserialized = serializer.fromBytes(serialized, 1);
+ fail("shouldn't deserialize");
+ }
+ catch(Exception e) {
+ // expected
+ }
+ }
+
+
+ private void verifyEquality(KrbIdentity expected, KrbIdentity actual) {
+ assertNotNull(actual);
+ assertEquals(expected.getPrincipalName(), actual.getPrincipalName());
+ assertEquals(expected.getCreatedTime().getTime(), actual.getCreatedTime().getTime());
+ assertEquals(expected.getExpireTime().getTime(), actual.getExpireTime().getTime());
+ assertEquals(expected.isDisabled(), actual.isDisabled());
+ assertEquals(expected.isLocked(), actual.isLocked());
+ assertEquals(expected.getKeyVersion(), actual.getKeyVersion());
+ assertEquals(expected.getKdcFlags(), actual.getKdcFlags());
+ assertEquals(expected.getKeys().size(), actual.getKeys().size());
+
+ Map<EncryptionType, EncryptionKey> exKeys = expected.getKeys();
+ Map<EncryptionType, EncryptionKey> acKeys = actual.getKeys();
+ for(EncryptionType et : exKeys.keySet() ) {
+ EncryptionKey exKey = exKeys.get(et);
+ EncryptionKey acKey = acKeys.get(et);
+
+ assertEquals(exKey.getKvno(), acKey.getKvno());
+ assertEquals(exKey.getKeyType(), acKey.getKeyType());
+ boolean equal = Arrays.equals(exKey.getKeyData(), acKey.getKeyData());
+ assertTrue(equal);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
new file mode 100644
index 0000000..8cd041c
--- /dev/null
+++ b/kerby-backend/mavibot-backend/src/test/java/org/apache/kerby/MavibotBackendTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.identity.backend.BackendTest;
+import org.apache.kerby.kerberos.kerb.identity.backend.BackendTestBase;
+import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
+import org.junit.*;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Tests for MavibotBackend.
+ *
+ * @author <a href="mailto:kerby@directory.apache.org">Apache Kerby Project</a>
+ */
+public class MavibotBackendTest extends BackendTestBase {
+ private static TemporaryFolder tmpFolder = new TemporaryFolder();
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ tmpFolder.create();
+
+ File dbFile = tmpFolder.newFile();
+ backend = new MavibotBackend(dbFile);
+ backend.initialize();
+ }
+
+ @AfterClass
+ public static void tearDown() throws KrbException {
+ tmpFolder.delete();
+ }
+
+ // overriding this cause MavibotBackend doesn't support range search
+ @Override
+ protected void testGetIdentities(IdentityBackend backend) throws KrbException {
+ KrbIdentity[] identities = createManyIdentities();
+
+ for (KrbIdentity identity : identities) {
+ backend.addIdentity(identity);
+ }
+
+ // clear the identity cache.
+ backend.release();
+
+ List<String> principals = backend.getIdentities(0, 0);
+ assertThat(principals).hasSize(identities.length);
+
+ for(KrbIdentity entry : identities) {
+ assertTrue(principals.contains(entry.getPrincipalName()));
+ }
+
+ for (KrbIdentity identity : identities) {
+ backend.deleteIdentity(identity.getPrincipalName());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot/pom.xml b/kerby-backend/mavibot/pom.xml
deleted file mode 100644
index cc5dfa8..0000000
--- a/kerby-backend/mavibot/pom.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerby-backend</artifactId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <artifactId>mavibot-backend</artifactId>
- <name>Mavibot based backend</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.directory.mavibot</groupId>
- <artifactId>mavibot</artifactId>
- <version>1.0.0-M8-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerby-config</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerb-identity</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerb-core</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerb-identity-test</artifactId>
- <version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentityComparator.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentityComparator.java b/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentityComparator.java
deleted file mode 100644
index bce3033..0000000
--- a/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentityComparator.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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;
-
-import java.util.Comparator;
-
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-
-/**
- * Comparator for KrbIdentity
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public final class KrbIdentityComparator implements Comparator<KrbIdentity> {
-
- public static final KrbIdentityComparator INSTANCE = new KrbIdentityComparator();
-
- private KrbIdentityComparator() {
- }
-
- @Override
- public int compare(KrbIdentity o1, KrbIdentity o2) {
- return o1.getPrincipalName().compareTo(o2.getPrincipalName());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentitySerializer.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentitySerializer.java b/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentitySerializer.java
deleted file mode 100644
index b63c9a4..0000000
--- a/kerby-backend/mavibot/src/main/java/org/apache/kerby/KrbIdentitySerializer.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * 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;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.Comparator;
-import java.util.Map;
-
-import org.apache.directory.mavibot.btree.serializer.BufferHandler;
-import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
-import org.apache.directory.mavibot.btree.serializer.IntSerializer;
-import org.apache.directory.mavibot.btree.serializer.LongSerializer;
-import org.apache.directory.mavibot.btree.serializer.StringSerializer;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
-
-/**
- * Serializer for KrbIdentity.
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class KrbIdentitySerializer implements ElementSerializer<KrbIdentity> {
- /** the static instance of the serializer */
- public static final KrbIdentitySerializer INSTANCE = new KrbIdentitySerializer();
-
- /** comparator for KrbIdentity */
- private KrbIdentityComparator comparator = KrbIdentityComparator.INSTANCE;
-
- @Override
- public byte[] serialize(KrbIdentity entry) {
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- try {
- // the principalName
- out.write(StringSerializer.INSTANCE.serialize(entry.getPrincipalName()));
-
- // key version
- out.write(IntSerializer.serialize(entry.getKeyVersion()));
-
- out.write(IntSerializer.serialize(entry.getKdcFlags()));
-
- // mask for disabled and lock flags
- byte mask = 0;
-
- if(entry.isDisabled()) {
- mask |= 1 << 1;
- }
-
- if(entry.isLocked()) {
- mask |= 1 << 2;
- }
-
- out.write(mask);
-
- // creation time
- out.write(LongSerializer.serialize(entry.getCreatedTime().getTime()));
-
- // expiration time
- out.write(LongSerializer.serialize(entry.getExpireTime().getTime()));
-
- Map<EncryptionType, EncryptionKey> keys = entry.getKeys();
- // num keys
- out.write(IntSerializer.serialize(keys.size()));
-
- for(EncryptionKey ek : keys.values()) {
- int type = ek.getKeyType().getValue();
- out.write(IntSerializer.serialize(type));
- byte[] data = ek.getKeyData();
- out.write(IntSerializer.serialize(data.length));
- out.write(data);
- }
-
- return out.toByteArray();
- }
- catch(Exception e) {
- throw new IllegalStateException("Failed to serialize the identity " + entry);
- }
- }
-
- @Override
- public KrbIdentity deserialize(BufferHandler bufferHandler)
- throws IOException {
- return fromBytes(bufferHandler.getBuffer());
- }
-
- @Override
- public KrbIdentity deserialize(ByteBuffer buffer) throws IOException {
- KrbIdentity id = null;
-
- String principal = StringSerializer.INSTANCE.deserialize(buffer);
-
- id = new KrbIdentity(principal);
-
- int kvno = IntSerializer.INSTANCE.deserialize(buffer);
- id.setKeyVersion(kvno);
-
- int flags = IntSerializer.INSTANCE.deserialize(buffer);
- id.setKdcFlags(flags);
-
- byte mask = buffer.get();
-
- if((mask & 2) != 0) {
- id.setDisabled(true);
- }
-
- if((mask & 4) != 0) {
- id.setLocked(true);
- }
-
- long creationTime = LongSerializer.INSTANCE.deserialize(buffer);
- id.setCreatedTime(new KerberosTime(creationTime));
-
- long exprTime = LongSerializer.INSTANCE.deserialize(buffer);
- id.setExpireTime(new KerberosTime(exprTime));
-
- int numKeys = IntSerializer.INSTANCE.deserialize(buffer);
-
- for(int i=0; i<numKeys; i++) {
- int keyType = IntSerializer.INSTANCE.deserialize(buffer);
- int keyLen = IntSerializer.INSTANCE.deserialize(buffer);
-
- byte[] keyData = new byte[keyLen];
- buffer.get(keyData);
-
- EncryptionKey ek = new EncryptionKey(keyType, keyData);
-
- id.addKey(ek);
- }
-
- return id;
- }
-
- @Override
- public KrbIdentity fromBytes(byte[] buffer) throws IOException {
- ByteBuffer buf = ByteBuffer.wrap(buffer);
- return deserialize(buf);
- }
-
- @Override
- public KrbIdentity fromBytes(byte[] buffer, int pos) throws IOException {
- ByteBuffer buf = ByteBuffer.wrap(buffer, pos, buffer.length - pos);
- return deserialize(buf);
- }
-
- @Override
- public int compare(KrbIdentity type1, KrbIdentity type2) {
- return comparator.compare(type1, type2);
- }
-
- @Override
- public Comparator<KrbIdentity> getComparator() {
- return comparator;
- }
-
- @Override
- public Class<?> getType() {
- return KrbIdentity.class;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/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
deleted file mode 100644
index f78f75a..0000000
--- a/kerby-backend/mavibot/src/main/java/org/apache/kerby/MavibotBackend.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * 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;
-
-import org.apache.directory.mavibot.btree.*;
-import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
-import org.apache.directory.mavibot.btree.serializer.StringSerializer;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A backend based on Apache Mavibot(an MVCC BTree library).
- *
- * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- */
-public class MavibotBackend extends AbstractIdentityBackend {
- //The RecordManager of Mavibot
- private RecordManager rm;
-
- //The BTree holding all data
- private BTree<String, KrbIdentity> database;
-
- //Name of the database
- private static final String DATA_TREE = "kerby-data";
-
- // Name of the database file
- private static final String DATABASE_NAME = "kerby-data.db";
-
- private static final Logger LOG = LoggerFactory.getLogger(MavibotBackend.class);
-
- /**
- * Creates a new instance of MavibotBackend.
- *
- * @param location
- * the File handle pointing to the database file or the directory
- * where it is present
- * @throws Exception
- */
- public MavibotBackend(File location) throws Exception {
- String dbPath = location.getAbsolutePath();
-
- LOG.info("Initializing the mavibot backend");
-
- if (!location.exists()) {
- location.mkdirs();
- }
-
- if (location.isDirectory()) {
- dbPath += File.separator + DATABASE_NAME;
- }
-
- rm = new RecordManager(dbPath);
-
- if (rm.getManagedTrees().contains(DATA_TREE)) {
- database = rm.getManagedTree(DATA_TREE);
- } else {
- PersistedBTreeConfiguration<String, KrbIdentity> config =
- new PersistedBTreeConfiguration<String, KrbIdentity>();
- // _no_ duplicates
- config.setAllowDuplicates(false);
- config.setBtreeType(BTreeTypeEnum.PERSISTED);
- config.setFilePath(dbPath);
- config.setKeySerializer(StringSerializer.INSTANCE);
- config.setName(DATA_TREE);
- config.setValueSerializer(KrbIdentitySerializer.INSTANCE);
-
- database = BTreeFactory.createPersistedBTree(config);
- rm.manage(database);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected List<String> doGetIdentities(int start, int limit) throws KrbException {
- List<String> keys = new ArrayList<String>();
- KeyCursor<String> cursor = null;
-
- try {
- cursor = database.browseKeys();
- while(cursor.hasNext()) {
- keys.add(cursor.next());
- }
- } catch(Exception e) {
- throw new KrbException("Errors occurred while fetching the principals", e);
- } finally {
- if(cursor != null) {
- cursor.close();
- }
- }
-
- return keys;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected KrbIdentity doGetIdentity(String principalName) throws KrbException {
- try {
- return database.get(principalName);
- } catch(KeyNotFoundException e) {
- LOG.debug("Identity {} doesn't exist", principalName);
- return null;
- } catch(IOException e) {
- throw new KrbException("Failed to get the identity " + principalName);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected synchronized KrbIdentity doAddIdentity(KrbIdentity identity) throws KrbException {
- String p = identity.getPrincipalName();
- try {
- if(database.hasKey(p)) {
- throw new KrbException("Identity already exists " + p);
- }
-
- return database.insert(p, identity);
- } catch(KeyNotFoundException e) {
- throw new KrbException("No such identity exists " + p);
- } catch(IOException e) {
- throw new KrbException("Failed to add the identity " + p);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected synchronized KrbIdentity doUpdateIdentity(KrbIdentity identity) throws KrbException {
- String p = identity.getPrincipalName();
- try {
- if(!database.hasKey(p)) {
- throw new KrbException("No identity found with the principal " + p);
- }
-
- database.delete(p);
-
- return database.insert(p, identity);
- } catch(Exception e) {
- throw new KrbException("Failed to update the identity " + p);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doDeleteIdentity(String principalName) throws KrbException {
- try {
- Tuple<String, KrbIdentity> t = database.delete(principalName);
- if (t == null) {
- throw new KrbException("Not existing, identity = " + principalName);
- }
- } catch(IOException e) {
- throw new KrbException("Failed to delete the identity " + principalName);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doStop() throws KrbException {
- try {
- rm.close();
- } catch(IOException e) {
- throw new KrbException("Failed to close the database", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java b/kerby-backend/mavibot/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java
deleted file mode 100644
index 227957a..0000000
--- a/kerby-backend/mavibot/src/test/java/org/apache/kerby/KrbIdentitySerializerTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.Map;
-
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
-import org.junit.Test;
-
-/**
- * Tests for KrbIdentity serializer.
- *
- * @author <a href="mailto:kerby@directory.apache.org">Apache Kerby Project</a>
- */
-public class KrbIdentitySerializerTest {
-
- private KrbIdentitySerializer serializer = KrbIdentitySerializer.INSTANCE;
-
- @Test
- public void testSerialization() throws Exception {
- KrbIdentity entry = new KrbIdentity("hnelson@EXAMPLE.COM");
- entry.setCreatedTime(new KerberosTime(System.currentTimeMillis()));
- entry.setDisabled(true);
- entry.setKeyVersion(1);
- entry.setLocked(true);
-
- byte[] junk = new byte[11];
- Arrays.fill(junk, (byte)1);
- EncryptionKey key1 = new EncryptionKey(EncryptionType.AES128_CTS, junk);
- entry.addKey(key1);
-
- EncryptionKey key2 = new EncryptionKey(EncryptionType.AES128_CTS_HMAC_SHA1_96, junk);
- entry.addKey(key2);
-
- byte[] serialized = serializer.serialize(entry);
-
- KrbIdentity deserialized = serializer.fromBytes(serialized);
- verifyEquality(entry, deserialized);
-
- deserialized = serializer.fromBytes(serialized, 0);
- verifyEquality(entry, deserialized);
-
- deserialized = serializer.deserialize(ByteBuffer.wrap(serialized));
- verifyEquality(entry, deserialized);
-
- try {
- deserialized = serializer.fromBytes(serialized, 1);
- fail("shouldn't deserialize");
- }
- catch(Exception e) {
- // expected
- }
- }
-
-
- private void verifyEquality(KrbIdentity expected, KrbIdentity actual) {
- assertNotNull(actual);
- assertEquals(expected.getPrincipalName(), actual.getPrincipalName());
- assertEquals(expected.getCreatedTime().getTime(), actual.getCreatedTime().getTime());
- assertEquals(expected.getExpireTime().getTime(), actual.getExpireTime().getTime());
- assertEquals(expected.isDisabled(), actual.isDisabled());
- assertEquals(expected.isLocked(), actual.isLocked());
- assertEquals(expected.getKeyVersion(), actual.getKeyVersion());
- assertEquals(expected.getKdcFlags(), actual.getKdcFlags());
- assertEquals(expected.getKeys().size(), actual.getKeys().size());
-
- Map<EncryptionType, EncryptionKey> exKeys = expected.getKeys();
- Map<EncryptionType, EncryptionKey> acKeys = actual.getKeys();
- for(EncryptionType et : exKeys.keySet() ) {
- EncryptionKey exKey = exKeys.get(et);
- EncryptionKey acKey = acKeys.get(et);
-
- assertEquals(exKey.getKvno(), acKey.getKvno());
- assertEquals(exKey.getKeyType(), acKey.getKeyType());
- boolean equal = Arrays.equals(exKey.getKeyData(), acKey.getKeyData());
- assertTrue(equal);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/58665d35/kerby-backend/mavibot/src/test/java/org/apache/kerby/MavibotBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mavibot/src/test/java/org/apache/kerby/MavibotBackendTest.java b/kerby-backend/mavibot/src/test/java/org/apache/kerby/MavibotBackendTest.java
deleted file mode 100644
index 8cd041c..0000000
--- a/kerby-backend/mavibot/src/test/java/org/apache/kerby/MavibotBackendTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.identity.backend.BackendTest;
-import org.apache.kerby.kerberos.kerb.identity.backend.BackendTestBase;
-import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
-import org.junit.*;
-import org.junit.rules.TemporaryFolder;
-
-/**
- * Tests for MavibotBackend.
- *
- * @author <a href="mailto:kerby@directory.apache.org">Apache Kerby Project</a>
- */
-public class MavibotBackendTest extends BackendTestBase {
- private static TemporaryFolder tmpFolder = new TemporaryFolder();
-
- @BeforeClass
- public static void setup() throws Exception {
- tmpFolder.create();
-
- File dbFile = tmpFolder.newFile();
- backend = new MavibotBackend(dbFile);
- backend.initialize();
- }
-
- @AfterClass
- public static void tearDown() throws KrbException {
- tmpFolder.delete();
- }
-
- // overriding this cause MavibotBackend doesn't support range search
- @Override
- protected void testGetIdentities(IdentityBackend backend) throws KrbException {
- KrbIdentity[] identities = createManyIdentities();
-
- for (KrbIdentity identity : identities) {
- backend.addIdentity(identity);
- }
-
- // clear the identity cache.
- backend.release();
-
- List<String> principals = backend.getIdentities(0, 0);
- assertThat(principals).hasSize(identities.length);
-
- for(KrbIdentity entry : identities) {
- assertTrue(principals.contains(entry.getPrincipalName()));
- }
-
- for (KrbIdentity identity : identities) {
- backend.deleteIdentity(identity.getPrincipalName());
- }
- }
-}