directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerberos git commit: Pass down kinit options to krb client call
Date Mon, 16 Mar 2015 09:24:01 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master 37895fa08 -> e98333ad7


Pass down kinit options to krb client call


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

Branch: refs/heads/master
Commit: e98333ad777d8096ee365f537faa00eac390190b
Parents: 37895fa
Author: Drankye <drankye@gmail.com>
Authored: Mon Mar 16 17:19:04 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Mon Mar 16 17:19:04 2015 +0800

----------------------------------------------------------------------
 .../apache/kerby/kerberos/tool/ToolUtil.java    | 20 ++++++++++++++++++++
 .../apache/kerby/kerberos/tool/kinit/Kinit.java |  9 ++++-----
 .../kerby/kerberos/tool/kinit/KinitOption.java  |  7 +++++++
 .../kerby/kerberos/kerb/client/KOption.java     |  2 ++
 .../kerby/kerberos/kerb/client/KrbOption.java   | 16 ++++++++++++++++
 .../kerby/kerberos/kerb/client/KrbOptions.java  |  6 ++++++
 6 files changed, 55 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e98333ad/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/ToolUtil.java
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/ToolUtil.java
b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/ToolUtil.java
index 6e81d9e..3fb9d68 100644
--- a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/ToolUtil.java
+++ b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/ToolUtil.java
@@ -21,6 +21,9 @@ package org.apache.kerby.kerberos.tool;
 
 import org.apache.kerby.kerberos.kerb.client.KOption;
 import org.apache.kerby.kerberos.kerb.client.KOptionType;
+import org.apache.kerby.kerberos.kerb.client.KrbOption;
+import org.apache.kerby.kerberos.kerb.client.KrbOptions;
+import org.apache.kerby.kerberos.tool.kinit.KinitOption;
 
 import java.io.File;
 
@@ -68,4 +71,21 @@ public class ToolUtil {
 
         return true;
     }
+
+    /**
+     * Convert tool (like kinit) options to KrbOptions.
+     * @param krbOptions
+     * @return krb options
+     */
+    public static KrbOptions convertOptions(KrbOptions krbOptions) {
+        KrbOptions results = new KrbOptions();
+
+        for (KOption toolOpt : krbOptions.getOptions()) {
+            KrbOption krbOpt = KrbOption.fromOptionName(toolOpt.getOptionName());
+            krbOpt.setValue(toolOpt.getValue());
+            results.add(krbOpt);
+        }
+
+        return results;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e98333ad/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/Kinit.java
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/Kinit.java
b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/Kinit.java
index f7cf76d..8e3678f 100644
--- a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/Kinit.java
+++ b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/Kinit.java
@@ -20,9 +20,7 @@
 package org.apache.kerby.kerberos.tool.kinit;
 
 import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.client.KOptionType;
-import org.apache.kerby.kerberos.kerb.client.KrbClient;
-import org.apache.kerby.kerberos.kerb.client.KrbOptions;
+import org.apache.kerby.kerberos.kerb.client.*;
 import org.apache.kerby.kerberos.kerb.spec.ticket.TgtTicket;
 import org.apache.kerby.kerberos.tool.ToolUtil;
 
@@ -96,14 +94,15 @@ public class Kinit {
         return password;
     }
 
-    public static int requestTicket(String principal, KrbOptions options) {
+    private static int requestTicket(String principal, KrbOptions kinitOptions) {
         KrbClient krbClient = new KrbClient();
         krbClient.init();
 
         String password = getPassword(principal);
 
         try {
-            TgtTicket tgt = krbClient.requestTgtTicket(principal, password, null);
+            TgtTicket tgt = krbClient.requestTgtTicket(principal, password,
+                    ToolUtil.convertOptions(kinitOptions));
             // TODO: write tgt into credentials cache.
             return 0;
         } catch (KrbException e) {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e98333ad/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
index eb5e23f..cade8a8 100644
--- a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
+++ b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.java
@@ -71,10 +71,17 @@ public enum KinitOption implements KOption {
         this.type = type;
     }
 
+    @Override
+    public String getOptionName() {
+        return name();
+    }
+
+    @Override
     public void setType(KOptionType type) {
         this.type = type;
     }
 
+    @Override
     public KOptionType getType() {
         return this.type;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e98333ad/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KOption.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KOption.java
b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KOption.java
index f5253f1..6a85ad6 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KOption.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KOption.java
@@ -25,6 +25,8 @@ public interface KOption {
 
     public KOptionType getType();
 
+    public String getOptionName();
+
     public void setName(String name);
 
     public String getName();

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e98333ad/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOption.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOption.java
b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOption.java
index a5a3a18..3e6740b 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOption.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOption.java
@@ -82,6 +82,11 @@ public enum KrbOption implements KOption {
         this.type = type;
     }
 
+    @Override
+    public String getOptionName() {
+        return name();
+    }
+
     public void setType(KOptionType type) {
         this.type = type;
     }
@@ -133,4 +138,15 @@ public enum KrbOption implements KOption {
         }
         return NONE;
     }
+
+    public static KrbOption fromOptionName(String optionName) {
+        if (optionName != null) {
+            for (KrbOption ko : values()) {
+                if (ko.getOptionName().equals(optionName)) {
+                    return (KrbOption) ko;
+                }
+            }
+        }
+        return NONE;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/e98333ad/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOptions.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOptions.java
b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOptions.java
index 2ea4eb2..1670673 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOptions.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbOptions.java
@@ -19,7 +19,9 @@
  */
 package org.apache.kerby.kerberos.kerb.client;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 public class KrbOptions {
@@ -44,6 +46,10 @@ public class KrbOptions {
         return options.containsKey(option);
     }
 
+    public List<KOption> getOptions() {
+        return new ArrayList<>(options.keySet());
+    }
+
     public KOption getOption(KOption option) {
         if (! options.containsKey(option)) {
             return null;


Mime
View raw message