directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zengl...@apache.org
Subject directory-kerby git commit: DIRKRB-686 Some refactor work for MySQL backend.
Date Wed, 17 Jan 2018 02:34:45 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk 11089e869 -> a8a284d9c


DIRKRB-686 Some refactor work for MySQL 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/a8a284d9
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/a8a284d9
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/a8a284d9

Branch: refs/heads/trunk
Commit: a8a284d9c77b4eead0d4d1b83aee6312c14a2c7a
Parents: 11089e8
Author: zenglinx <frank.zeng@intel.com>
Authored: Wed Jan 17 10:34:12 2018 +0800
Committer: zenglinx <frank.zeng@intel.com>
Committed: Wed Jan 17 10:34:12 2018 +0800

----------------------------------------------------------------------
 kerby-backend/mysql-backend/pom.xml             | 11 ------
 .../identitybackend/MySQLIdentityBackend.java   | 41 +++++---------------
 kerby-dist/kdc-dist/pom.xml                     | 15 +++----
 3 files changed, 17 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a8a284d9/kerby-backend/mysql-backend/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-backend/mysql-backend/pom.xml b/kerby-backend/mysql-backend/pom.xml
index d24335a..ad5a288 100644
--- a/kerby-backend/mysql-backend/pom.xml
+++ b/kerby-backend/mysql-backend/pom.xml
@@ -27,11 +27,6 @@
 
   <dependencies>
     <dependency>
-      <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-core-api</artifactId>
-      <version>2.0.0-M23</version>
-    </dependency>
-    <dependency>
       <groupId>commons-dbutils</groupId>
       <artifactId>commons-dbutils</artifactId>
       <version>1.6</version>
@@ -62,12 +57,6 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.196</version>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a8a284d9/kerby-backend/mysql-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/MySQLIdentityBackend.java
----------------------------------------------------------------------
diff --git a/kerby-backend/mysql-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/MySQLIdentityBackend.java
b/kerby-backend/mysql-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/MySQLIdentityBackend.java
index 32ede90..48c698e 100644
--- a/kerby-backend/mysql-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/MySQLIdentityBackend.java
+++ b/kerby-backend/mysql-backend/src/main/java/org/apache/kerby/kerberos/kdc/identitybackend/MySQLIdentityBackend.java
@@ -20,7 +20,6 @@
 package org.apache.kerby.kerberos.kdc.identitybackend;
 
 import org.apache.commons.dbutils.DbUtils;
-import org.apache.directory.api.util.GeneralizedTime;
 import org.apache.kerby.config.Config;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.identity.backend.AbstractIdentityBackend;
@@ -36,7 +35,6 @@ import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -51,9 +49,9 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
     private String url;
     private String user;
     private String password;
-    private static final Logger LOG = LoggerFactory.getLogger(MySQLIdentityBackend.class);
     private String identityTable;
     private String keyInfoTable;
+    private static final Logger LOG = LoggerFactory.getLogger(MySQLIdentityBackend.class);
 
     /**
      * Constructing an instance using specified config that contains anything
@@ -136,8 +134,8 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
                 + " (principal varchar(255) NOT NULL, key_version INTEGER "
                 + "DEFAULT 1, kdc_flags INTEGER DEFAULT 0, disabled bool "
                 + "DEFAULT NULL, locked bool DEFAULT NULL, created_time "
-                + "VARCHAR(255) DEFAULT NULL, expire_time VARCHAR(255) "
-                + "DEFAULT NULL, PRIMARY KEY (principal) ) ENGINE=INNODB "
+                + "BIGINT DEFAULT 0, expire_time BIGINT DEFAULT 0, "
+                + "PRIMARY KEY (principal) ) ENGINE=INNODB "
                 + "DEFAULT CHARSET=utf8;";
             preIdentity = connection.prepareStatement(stmIdentity);
             preIdentity.executeUpdate();
@@ -194,15 +192,6 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
     }
 
     /**
-     * Convert a KerberosTime type object to a generalized time form of String.
-     * @param kerberosTime The kerberos time to convert
-     */
-    private String toGeneralizedTime(final KerberosTime kerberosTime) {
-        GeneralizedTime generalizedTime = new GeneralizedTime(kerberosTime.getValue());
-        return generalizedTime.toString();
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
@@ -212,8 +201,8 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
         int kdcFlags = identity.getKdcFlags();
         boolean disabled = identity.isDisabled();
         boolean locked = identity.isLocked();
-        String createdTime = toGeneralizedTime(identity.getCreatedTime());
-        String expireTime = toGeneralizedTime(identity.getExpireTime());
+        long createdTime = identity.getCreatedTime().getTime();
+        long expireTime = identity.getExpireTime().getTime();
         Map<EncryptionType, EncryptionKey> keys = identity.getKeys();
 
         PreparedStatement preIdentity = null;
@@ -239,8 +228,8 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
                 preIdentity.setInt(3, kdcFlags);
                 preIdentity.setBoolean(4, disabled);
                 preIdentity.setBoolean(5, locked);
-                preIdentity.setString(6, createdTime);
-                preIdentity.setString(7, expireTime);
+                preIdentity.setLong(6, createdTime);
+                preIdentity.setLong(7, expireTime);
                 preIdentity.executeUpdate();
 
                 // Insert keys to key table
@@ -275,16 +264,6 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
     }
 
     /**
-     * Create kerberos time.
-     * @param generalizedTime generalized time
-     * @throws ParseException parse exception
-     */
-    private KerberosTime createKerberosTime(final String generalizedTime) throws ParseException
{
-        long time = new GeneralizedTime(generalizedTime).getTime();
-        return new KerberosTime(time);
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
@@ -313,8 +292,8 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
                 krbIdentity.setKdcFlags(resIdentity.getInt("kdc_flags"));
                 krbIdentity.setDisabled(resIdentity.getBoolean("disabled"));
                 krbIdentity.setLocked(resIdentity.getBoolean("locked"));
-                krbIdentity.setCreatedTime(createKerberosTime(resIdentity.getString("created_time")));
-                krbIdentity.setExpireTime(createKerberosTime(resIdentity.getString("expire_time")));
+                krbIdentity.setCreatedTime(new KerberosTime(resIdentity.getLong("created_time")));
+                krbIdentity.setExpireTime(new KerberosTime(resIdentity.getLong("expire_time")));
             }
 
             // Get keys from key table
@@ -337,8 +316,6 @@ public class MySQLIdentityBackend extends AbstractIdentityBackend {
         } catch (SQLException e) {
             LOG.error("Error occurred while getting identity.");
             throw new KrbException("Failed to get identity. ", e);
-        } catch (ParseException e) {
-            throw new KrbException("Failed to get identity. ", e);
         } finally {
             DbUtils.closeQuietly(preIdentity);
             DbUtils.closeQuietly(resIdentity);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a8a284d9/kerby-dist/kdc-dist/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/pom.xml b/kerby-dist/kdc-dist/pom.xml
index 3a5de2d..ed48c91 100644
--- a/kerby-dist/kdc-dist/pom.xml
+++ b/kerby-dist/kdc-dist/pom.xml
@@ -77,6 +77,14 @@
     </dependency>
     -->
 
+    <!-- For mysql backend
+    <dependency>
+      <groupId>org.apache.kerby</groupId>
+      <artifactId>mysql-backend</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    -->
+
     <!-- For json backend -->
     <dependency>
       <groupId>org.apache.kerby</groupId>
@@ -89,13 +97,6 @@
       <version>${gson.version}</version>
     </dependency>
 
-    <!-- For mysql backend -->
-    <dependency>
-      <groupId>org.apache.kerby</groupId>
-      <artifactId>mysql-backend</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-
     <!-- For common and misc -->
     <dependency>
       <groupId>org.slf4j</groupId>


Mime
View raw message