directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject directory-kerberos git commit: More refactoring
Date Thu, 05 Feb 2015 14:56:48 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master 4ae948c6c -> 58b44ebed


More refactoring


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

Branch: refs/heads/master
Commit: 58b44ebed994e20dbf6f636e41d1e961b1edcdcd
Parents: 4ae948c
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Feb 5 14:55:05 2015 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Feb 5 14:55:05 2015 +0000

----------------------------------------------------------------------
 .../kerberos/kerb/common/EncryptionUtil.java    |  8 +++---
 .../kerberos/kerb/common/KrbConfHelper.java     |  3 +--
 .../kerberos/kerb/common/KrbErrorUtil.java      |  2 +-
 .../kerb/preauth/pkinit/PkinitIdenity.java      |  3 +--
 .../kerberos/kerb/ccache/CredentialCache.java   |  5 ++--
 .../kerby/kerberos/kerb/keytab/Keytab.java      | 26 +++++++++++---------
 .../kerby/kerberos/kerb/keytab/KeytabEntry.java | 24 +++++++++++++-----
 .../kerberos/kerb/keytab/KeytabInputStream.java |  3 +--
 .../kerby/kerberos/kerb/util/KeysTest.java      |  7 +++---
 9 files changed, 45 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
index aa9618d..86944b0 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/EncryptionUtil.java
@@ -37,9 +37,8 @@ public class EncryptionUtil {
 
     public static List<EncryptionKey> generateKeys(List<EncryptionType> encryptionTypes)
throws KrbException {
         List<EncryptionKey> results = new ArrayList<EncryptionKey>(encryptionTypes.size());
-        EncryptionKey encKey;
         for (EncryptionType eType : encryptionTypes) {
-            encKey = EncryptionHandler.random2Key(eType);
+            EncryptionKey encKey = EncryptionHandler.random2Key(eType);
             results.add(encKey);
         }
 
@@ -49,9 +48,8 @@ public class EncryptionUtil {
     public static List<EncryptionKey> generateKeys(String principal, String passwd,
                                                    List<EncryptionType> encryptionTypes)
throws KrbException {
         List<EncryptionKey> results = new ArrayList<EncryptionKey>(encryptionTypes.size());
-        EncryptionKey encKey;
         for (EncryptionType eType : encryptionTypes) {
-            encKey = EncryptionHandler.string2Key(principal, passwd, eType);
+            EncryptionKey encKey = EncryptionHandler.string2Key(principal, passwd, eType);
             results.add(encKey);
         }
 
@@ -69,7 +67,7 @@ public class EncryptionUtil {
         return null;
     }
 
-    public static EncryptedData seal(AbstractAsn1Type asn1Type,
+    public static EncryptedData seal(AbstractAsn1Type<?> asn1Type,
                                      EncryptionKey key, KeyUsage usage) throws KrbException
{
         byte[] encoded = asn1Type.encode();
         EncryptedData encrypted = EncryptionHandler.encrypt(encoded, key, usage);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbConfHelper.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbConfHelper.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbConfHelper.java
index 0100b0b..0564981 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbConfHelper.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbConfHelper.java
@@ -91,9 +91,8 @@ public class KrbConfHelper {
     public static List<EncryptionType> getEncryptionTypes(List<String> encTypeNames)
{
         List<EncryptionType> results = new ArrayList<EncryptionType>(encTypeNames.size());
 
-        EncryptionType eType;
         for (String eTypeName : encTypeNames) {
-            eType = EncryptionType.fromName(eTypeName);
+            EncryptionType eType = EncryptionType.fromName(eTypeName);
             if (eType != EncryptionType.NONE) {
                 results.add(eType);
             }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbErrorUtil.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbErrorUtil.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbErrorUtil.java
index e252d5b..650f825 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbErrorUtil.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/common/KrbErrorUtil.java
@@ -42,7 +42,7 @@ public class KrbErrorUtil {
                 return getEtypes(pd.getPaDataValue());
             }
         }
-        return Collections.EMPTY_LIST;
+        return Collections.emptyList();
     }
 
     private static List<EncryptionType> getEtypes(byte[] data) throws IOException {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitIdenity.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitIdenity.java
b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitIdenity.java
index f080231..575974a 100644
--- a/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitIdenity.java
+++ b/kerby-kerb/kerb-common/src/main/java/org/apache/kerby/kerberos/kerb/preauth/pkinit/PkinitIdenity.java
@@ -67,10 +67,9 @@ public class PkinitIdenity {
 
     public static void parseFileOption(IdentityOpts identityOpts, String residual) {
         String[] parts = residual.split(",");
-        String certName = null;
+        String certName = parts[0];
         String keyName = null;
 
-        certName = parts[0];
         if (parts.length > 1) {
             keyName = parts[1];
         }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredentialCache.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredentialCache.java
b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredentialCache.java
index 3598e90..343521a 100644
--- a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredentialCache.java
+++ b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/ccache/CredentialCache.java
@@ -185,7 +185,7 @@ public class CredentialCache implements KrbCredentialCache
 
         Credential cred;
         while (ccis.available() > 0) {
-            cred =  new Credential();
+            cred = new Credential();
             cred.load(ccis, version);
 
             results.add(cred);
@@ -267,9 +267,8 @@ public class CredentialCache implements KrbCredentialCache
         CredentialCache cc = new CredentialCache();
         cc.load(new File(cacheFile));
 
-        Ticket tkt;
         for (Credential cred : cc.getCredentials()) {
-            tkt = cred.getTicket();
+            Ticket tkt = cred.getTicket();
             System.out.println("Tkt server name: " + tkt.getSname().getName());
             System.out.println("Tkt client name: " + cred.getClientName().getName());
             System.out.println("Tkt encrypt type: " + tkt.getEncryptedEncPart().getEType().getName());

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/Keytab.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/Keytab.java
b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/Keytab.java
index 46891d0..4ffd058 100644
--- a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/Keytab.java
+++ b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/Keytab.java
@@ -19,14 +19,22 @@
  */
 package org.apache.kerby.kerberos.kerb.keytab;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
 import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
 import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
 
-import java.io.*;
-import java.nio.ByteBuffer;
-import java.util.*;
-
 public class Keytab implements KrbKeytab {
 
     public static final int V501 = 0x0501;
@@ -63,9 +71,8 @@ public class Keytab implements KrbKeytab {
         List<KeytabEntry> entries = principalEntries.get(principal);
         if (entries != null) {
             Iterator<KeytabEntry> iter = entries.iterator();
-            KeytabEntry tmp;
             while (iter.hasNext()) {
-                tmp = iter.next();
+                KeytabEntry tmp = iter.next();
                 if (entry.equals(tmp)) {
                     iter.remove();
                     break;
@@ -138,15 +145,12 @@ public class Keytab implements KrbKeytab {
     private List<KeytabEntry> readEntries(KeytabInputStream kis) throws IOException
{
         List<KeytabEntry> entries = new ArrayList<KeytabEntry>();
 
-        int entrySize;
-        ByteBuffer entryData;
-        KeytabEntry entry;
         while (kis.available() > 0) {
-            entrySize = kis.readInt();
+            int entrySize = kis.readInt();
             if (kis.available() < entrySize) {
                 throw new IOException("Bad input stream with less data than expected: " +
entrySize);
             }
-            entry = readEntry(kis);
+            KeytabEntry entry = readEntry(kis);
             entries.add(entry);
         }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntry.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntry.java
b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntry.java
index a0b7351..a9463bb 100644
--- a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntry.java
+++ b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabEntry.java
@@ -97,15 +97,27 @@ public class KeytabEntry
 
     @Override
     public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
 
         KeytabEntry that = (KeytabEntry) o;
 
-        if (kvno != that.kvno) return false;
-        if (!key.equals(that.key)) return false;
-        if (!principal.equals(that.principal)) return false;
-        if (!timestamp.equals(that.timestamp)) return false;
+        if (kvno != that.kvno) {
+            return false;
+        }
+        if (!key.equals(that.key)) {
+            return false;
+        }
+        if (!principal.equals(that.principal)) {
+            return false;
+        }
+        if (!timestamp.equals(that.timestamp)) {
+            return false;
+        }
 
         return true;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabInputStream.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabInputStream.java
b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabInputStream.java
index 4638080..b5bbc4a 100644
--- a/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabInputStream.java
+++ b/kerby-kerb/kerb-util/src/main/java/org/apache/kerby/kerberos/kerb/keytab/KeytabInputStream.java
@@ -53,9 +53,8 @@ public class KeytabInputStream extends KrbInputStream
         String realm = readCountedString();
 
         List<String> nameStrings = new ArrayList<String>();
-        String component;
         for (int i = 0; i < numComponents; i++) { // sub 1 if version 0x501
-            component = readCountedString();
+            String component = readCountedString();
             nameStrings.add(component);
         }
         int type = readInt(); // not present if version 0x501

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/58b44ebe/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeysTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeysTest.java
b/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeysTest.java
index 52bd024..8246e71 100644
--- a/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeysTest.java
+++ b/kerby-kerb/kerb-util/src/test/java/org/apache/kerby/kerberos/kerb/util/KeysTest.java
@@ -65,12 +65,11 @@ public class KeysTest {
         List<PrincipalName> principals = keytab.getPrincipals();
         PrincipalName principal = principals.get(0);
         List<KeytabEntry> entries = keytab.getKeytabEntries(principal);
-        EncryptionKey genKey;
-        EncryptionType keyType;
+
         for (KeytabEntry ke : entries) {
-            keyType = ke.getKey().getKeyType();
+            EncryptionType keyType = ke.getKey().getKeyType();
             if (EncryptionHandler.isImplemented(keyType)) {
-                genKey = EncryptionHandler.string2Key(principal.getName(),
+                EncryptionKey genKey = EncryptionHandler.string2Key(principal.getName(),
                         TEST_PASSWORD, keyType);
                 if(! ke.getKey().equals(genKey)) {
                     fail("str2key failed for key type: " + keyType.getName());


Mime
View raw message