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-372 Set the conf dir as the default backend data dir.
Date Thu, 16 Jul 2015 06:24:24 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 4ddcf983a -> ddd6aed98


DIRKRB-372 Set the conf dir as the default backend data dir.


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

Branch: refs/heads/master
Commit: ddd6aed98fe6af5988e8be00bd195f3fdcbb7dd3
Parents: 4ddcf98
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Thu Jul 16 14:29:55 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Thu Jul 16 14:29:55 2015 +0800

----------------------------------------------------------------------
 README.md                                       |  2 +-
 .../identitybackend/JsonIdentityBackend.java    | 15 +++++--
 .../kerb/identity/backend/JsonBackendTest.java  |  2 +-
 .../ZookeeperIdentityBackend.java               | 47 ++++++++++----------
 kerby-dist/README.md                            |  2 +-
 kerby-dist/kdc-dist/conf/backend.conf           |  5 ++-
 .../kerby/kerberos/kdc/JsonBackendKdcTest.java  |  2 +-
 .../kdc/OnlyTcpForNettyKdcNetworkTest.java      |  2 +-
 .../kdc/OnlyUdpForNettyKdcNetworkTest.java      |  2 +-
 .../backend/AbstractIdentityBackend.java        |  7 +++
 .../kerby/kerberos/kerb/server/KdcServer.java   |  2 +
 11 files changed, 54 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 55dcd40..1f3f0e7 100644
--- a/README.md
+++ b/README.md
@@ -68,7 +68,7 @@ A standalone KDC server that can integrate various identity back ends including:
 - MemoryIdentityBackend.
   - It is default Identity Backend, and no cofiguration is needed. This backend is for no
permanent storage requirements.
 - JsonIdentityBackend.
-  - It implemented by Gson which is used to convert Java Objects into their JSON representation
and convert a JSON string to an equivalent Java object. A json file will be created in "backend.json.file".
This backend is for small, easy, development and test environment.
+  - It implemented by Gson which is used to convert Java Objects into their JSON representation
and convert a JSON string to an equivalent Java object. A json file will be created in "backend.json.dir".
This backend is for small, easy, development and test environment.
 - ZookeeperIdentityBackend.
   - Currently it uses an embedded Zookeeper. In follow up it will be enhanced to support
standalone Zookeeper cluster for
   replication and reliability. Zookeeper backend would be a good choice for high reliability,
high performance and high scalability requirement and scenarios. 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/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 b6b4206..c45e4ae 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
@@ -49,7 +49,7 @@ import java.util.Map;
  *
  */
 public class JsonIdentityBackend extends AbstractIdentityBackend {
-    public static final String JSON_IDENTITY_BACKEND_FILE = "backend.json.file";
+    public static final String JSON_IDENTITY_BACKEND_DIR = "backend.json.dir";
     private File jsonKdbFile;
     private Gson gson;
     private static final Logger LOG = LoggerFactory.getLogger(JsonIdentityBackend.class);
@@ -87,12 +87,19 @@ public class JsonIdentityBackend extends AbstractIdentityBackend {
      */
     private void load() throws KrbException {
         LOG.info("Loading the identities from json file.");
-        String jsonFile = getConfig().getString(JSON_IDENTITY_BACKEND_FILE);
+        String jsonFile = getConfig().getString(JSON_IDENTITY_BACKEND_DIR);
+        File jsonFileDir;
         if (jsonFile == null || jsonFile.isEmpty()) {
-            throw new KrbException("No json kdb file is found");
+            jsonFileDir = getBackendConfig().getConfDir();
+        } else {
+            jsonFileDir = new File(jsonFile);
+            if (!jsonFileDir.exists() && !jsonFileDir.mkdirs()) {
+                throw new KrbException("could not create json file dir " + jsonFileDir);
+            }
         }
 
-        jsonKdbFile = new File(jsonFile);
+        jsonKdbFile = new File(jsonFileDir, "json_identity_backend_file");
+
         if (!jsonKdbFile.exists()) {
             try {
                 jsonKdbFile.createNewFile();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
----------------------------------------------------------------------
diff --git a/kerby-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
b/kerby-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
index 8a974dc..2d4951e 100644
--- a/kerby-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
+++ b/kerby-backend/json-backend/src/test/java/org/apache/kerby/kerberos/kerb/identity/backend/JsonBackendTest.java
@@ -41,7 +41,7 @@ public class JsonBackendTest extends BackendTestBase {
         String jsonBackendFileString = jsonBackendFile.getAbsolutePath();
 
         Config backendConfig = new Conf();
-        backendConfig.setString(JsonIdentityBackend.JSON_IDENTITY_BACKEND_FILE, jsonBackendFileString);
+        backendConfig.setString(JsonIdentityBackend.JSON_IDENTITY_BACKEND_DIR, jsonBackendFileString);
         backend = new JsonIdentityBackend(backendConfig);
         backend.initialize();
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/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 841a653..f2204cc 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
@@ -50,8 +50,8 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend {
     private final ZooKeeperServerMain zooKeeperServer = new ZooKeeperServerMain();
     private String zkHost;
     private int zkPort;
-    private File dataFile;
-    private File dataLogFile;
+    private File dataDir;
+    private File dataLogDir;
     private ZooKeeper zooKeeper;
     private static final Logger LOG = LoggerFactory.getLogger(ZookeeperIdentityBackend.class);
 
@@ -84,29 +84,30 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
         zkHost = getConfig().getString(ZKConfKey.ZK_HOST);
         zkPort = getConfig().getInt(ZKConfKey.ZK_PORT);
 
-        String dataDir = getConfig().getString(ZKConfKey.DATA_DIR);
-        if (dataDir == null || dataDir.isEmpty()) {
-            LOG.warn("Data dir " + dataDir + "is found while initialization the zookeeper
server.");
-            throw new RuntimeException("No data dir is found");
+        String dataDirString = getConfig().getString(ZKConfKey.DATA_DIR);
+        if (dataDirString == null || dataDirString.isEmpty()) {
+            File zooKeeperDir = new File(getBackendConfig().getConfDir(), "zookeeper");
+            dataDir = new File(zooKeeperDir, "data");
+        } else {
+            dataDir = new File(dataDirString);
         }
 
-        dataFile = new File(dataDir);
-        if (!dataFile.exists() && !dataFile.mkdirs()) {
-            throw new KrbException("Dir file not exits");
+        if (!dataDir.exists() && !dataDir.mkdirs()) {
+            throw new KrbException("could not create data file dir " + dataDir);
         }
 
-        String dataLogDir = getConfig().getString(ZKConfKey.DATA_LOG_DIR);
-        if (dataLogDir == null || dataLogDir.isEmpty()) {
-            LOG.warn("Data log dir " + dataLogDir
-                + "is found while initialization the zookeeper server.");
-            throw new RuntimeException("No data log dir is found");
-        }
-
-        dataLogFile = new File(dataLogDir);
+        LOG.info("Data dir: " + dataDir);
 
+        String dataLogDirString = getConfig().getString(ZKConfKey.DATA_LOG_DIR);
+        if (dataLogDirString == null || dataLogDirString.isEmpty()) {
+            File zooKeeperDir = new File(getBackendConfig().getConfDir(), "zookeeper");
+            dataLogDir = new File(zooKeeperDir, "datalog");
+        } else {
+            dataLogDir = new File(dataLogDirString);
+        }
 
-        if (!dataLogFile.exists() && !dataFile.mkdirs()) {
-            throw new KrbException("DataLogfile file not exits");
+        if (!dataLogDir.exists() && !dataLogDir.mkdirs()) {
+            throw new KrbException("could not create data log file dir " + dataLogDir);
         }
 
         startEmbeddedZookeeper();
@@ -143,8 +144,8 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
      */
     private void startEmbeddedZookeeper() throws KrbException {
         Properties startupProperties = new Properties();
-        startupProperties.put("dataDir", dataFile.getAbsolutePath());
-        startupProperties.put("dataLogDir", dataLogFile.getAbsolutePath());
+        startupProperties.put("dataDir", dataDir.getAbsolutePath());
+        startupProperties.put("dataLogDir", dataLogDir.getAbsolutePath());
         startupProperties.put("clientPort", zkPort);
 
         QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
@@ -215,7 +216,7 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
         if (doGetIdentity(identity.getPrincipalName()) != null) {
              LOG.error("Error occurred while adding identity, principal "
                 + identity.getPrincipalName() + " already exists.");
-            throw new RuntimeException("Principal already exists.");
+            throw new KrbException("Principal already exists.");
         }
         try {
             setIdentity(identity);
@@ -233,7 +234,7 @@ public class ZookeeperIdentityBackend extends AbstractIdentityBackend
{
         if (doGetIdentity(identity.getPrincipalName()) == null) {
             LOG.error("Error occured while updating identity, principal "
                 + identity.getPrincipalName() + " does not exists.");
-            throw new RuntimeException("Principal does not exist.");
+            throw new KrbException("Principal does not exist.");
         }
         try {
             setIdentity(identity);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-dist/README.md
----------------------------------------------------------------------
diff --git a/kerby-dist/README.md b/kerby-dist/README.md
index 29585ea..35be8db 100644
--- a/kerby-dist/README.md
+++ b/kerby-dist/README.md
@@ -39,7 +39,7 @@ An example of kdc.conf:
 An example of json backend backend.conf:
 ```
 kdc_identity_backend = org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend
-backend.json.file = /tmp/kerby/jsonbackend
+backend.json.dir = /tmp/kerby/jsonbackend
 ```
 An example of zookeeper backend backend.conf:
 ```

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-dist/kdc-dist/conf/backend.conf
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/conf/backend.conf b/kerby-dist/kdc-dist/conf/backend.conf
index 363024c..5991f48 100644
--- a/kerby-dist/kdc-dist/conf/backend.conf
+++ b/kerby-dist/kdc-dist/conf/backend.conf
@@ -16,4 +16,7 @@
 # limitations under the License.
 #
 
-kdc_identity_backend = org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend
+kdc_identity_backend = org.apache.kerby.kerberos.kdc.identitybackend.ZookeeperIdentityBackend
+backend.json.dir = /home/kerby/jsonbackend
+data_dir = /home/kerby/zookeeper/data
+data_log_dir = /home/kerby/zookeeper/datalog

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
index e0334a5..1292aa9 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
@@ -41,7 +41,7 @@ public class JsonBackendKdcTest extends KerbyKdcTest {
 
         BackendConfig backendConfig = getKdcServer().getBackendConfig();
         backendConfig.setString(
-                JsonIdentityBackend.JSON_IDENTITY_BACKEND_FILE, jsonBackendFileString);
+                JsonIdentityBackend.JSON_IDENTITY_BACKEND_DIR, jsonBackendFileString);
         backendConfig.setString(KdcConfigKey.KDC_IDENTITY_BACKEND,
             "org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend");
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyTcpForNettyKdcNetworkTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyTcpForNettyKdcNetworkTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyTcpForNettyKdcNetworkTest.java
index b9cc02f..fcc3722 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyTcpForNettyKdcNetworkTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyTcpForNettyKdcNetworkTest.java
@@ -57,7 +57,7 @@ public class OnlyTcpForNettyKdcNetworkTest extends KerbyKdcTest {
 
         BackendConfig backendConfig = getKdcServer().getBackendConfig();
         backendConfig.setString(
-                JsonIdentityBackend.JSON_IDENTITY_BACKEND_FILE, jsonBackendFileString);
+                JsonIdentityBackend.JSON_IDENTITY_BACKEND_DIR, jsonBackendFileString);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyUdpForNettyKdcNetworkTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyUdpForNettyKdcNetworkTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyUdpForNettyKdcNetworkTest.java
index 4afc9e5..6662897 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyUdpForNettyKdcNetworkTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/OnlyUdpForNettyKdcNetworkTest.java
@@ -57,7 +57,7 @@ public class OnlyUdpForNettyKdcNetworkTest extends KerbyKdcTest {
 
         BackendConfig backendConfig = getKdcServer().getBackendConfig();
         backendConfig.setString(
-                JsonIdentityBackend.JSON_IDENTITY_BACKEND_FILE,
+                JsonIdentityBackend.JSON_IDENTITY_BACKEND_DIR,
                 jsonBackendFileString);
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractIdentityBackend.java
b/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractIdentityBackend.java
index 1918bb4..05aa448 100644
--- a/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractIdentityBackend.java
+++ b/kerby-kerb/kerb-identity/src/main/java/org/apache/kerby/kerberos/kerb/identity/backend/AbstractIdentityBackend.java
@@ -39,6 +39,13 @@ public abstract class AbstractIdentityBackend
             LoggerFactory.getLogger(AbstractIdentityBackend.class);
 
     /**
+     * Get the Backend Config.
+     */
+    protected BackendConfig getBackendConfig() {
+        return (BackendConfig) getConfig();
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/ddd6aed9/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
index 5541a9e..61031fb 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
@@ -22,6 +22,7 @@ package org.apache.kerby.kerberos.kerb.server;
 import org.apache.kerby.KOptions;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.identity.IdentityService;
+import org.apache.kerby.kerberos.kerb.identity.backend.BackendConfig;
 import org.apache.kerby.kerberos.kerb.server.impl.DefaultInternalKdcServerImpl;
 import org.apache.kerby.kerberos.kerb.server.impl.InternalKdcServer;
 
@@ -72,6 +73,7 @@ public class KdcServer {
         if (tmpBackendConfig == null) {
             tmpBackendConfig = new BackendConfig();
         }
+        tmpBackendConfig.setConfDir(confDir);
         this.backendConfig = tmpBackendConfig;
 
         startupOptions = new KOptions();


Mime
View raw message