directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [2/2] directory-kerberos git commit: Introduced KOption and KinitOption
Date Mon, 16 Mar 2015 03:22:18 GMT
Introduced KOption and KinitOption


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

Branch: refs/heads/master
Commit: 515d3b66f8a533123207b3c8fdd69eaa1b2d025d
Parents: d8c1f20
Author: Drankye <drankye@gmail.com>
Authored: Mon Mar 16 11:21:50 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Mon Mar 16 11:21:50 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/kerberos/tool/Kinit.java   | 215 ------------------
 .../apache/kerby/kerberos/tool/kinit/Kinit.java | 216 +++++++++++++++++++
 .../kerby/kerberos/tool/kinit/KinitOption.java  | 106 +++++++++
 .../kerby/kerberos/kerb/client/KOption.java     |  35 +++
 .../kerby/kerberos/kerb/client/KrbOption.java   |  89 +++++---
 .../kerby/kerberos/kerb/client/KrbOptions.java  |  19 +-
 6 files changed, 424 insertions(+), 256 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/515d3b66/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
deleted file mode 100644
index 134eb6b..0000000
--- a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
+++ /dev/null
@@ -1,215 +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.kerberos.tool;
-
-import org.apache.kerby.config.Conf;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.client.KrbClient;
-import org.apache.kerby.kerberos.kerb.client.KrbConfig;
-
-import java.io.Console;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Scanner;
-
-/**
- * kinit like tool
- */
-public class Kinit {
-
-    private static final String COMMON_USAGE = "Usage: " +
-            Kinit.class.getSimpleName() + " [-l lifetime] [-f | -F] principal\n" +
-            "\n" +
-            "    options:\t-l lifetime\n" +
-            "\t-f forwardable\n" +
-            "\t-F not forwardable";
-
-    private void printUsage(String cmd) {
-        if ("-l".equals(cmd)) {
-            System.err.println("Usage: " + Kinit.class.getSimpleName() + " -l lifetime principal");
-        } else if ("-f".equals(cmd)) {
-            System.err.println("Usage: " + Kinit.class.getSimpleName() + " -f principal");
-        } else if ("-F".equals(cmd)) {
-            System.err.println("Usage: " + Kinit.class.getSimpleName() + " -F principal");
-        } else {
-            System.err.println(COMMON_USAGE);
-        }
-    }
-
-    /**
-     * args[0] is the configuration directory written in script.
-     * args[length - 1] is principal
-     */
-    private int execute(String[] args) {
-        if (args.length < 2 || args.length > 4) {
-            printUsage("");
-            return -1;
-        }
-
-        //no options
-        if (args.length == 2) {
-            return requestTicket(args, 1);
-        }
-
-        int exitCode = -1;
-        int i = 1;
-        String cmd = args[i];
-
-        //
-        // verify that we have enough option parameters
-        //
-        if ("-l".equals(cmd)) {
-            if (args.length != 4) {
-                printUsage(cmd);
-                return exitCode;
-            }
-        } else if ("-f".equals(cmd)) {
-            if (args.length != 3) {
-                printUsage(cmd);
-                return exitCode;
-            }
-        } else if ("-F".equals(cmd)) {
-            if (args.length != 3) {
-                printUsage(cmd);
-                return exitCode;
-            }
-        }
-
-        //
-        //execute the command
-        //
-        if ("-l".equals(cmd)) {
-            exitCode = ticketWithLifetime(args, i);
-        } else if ("-f".equals(cmd)) {
-            exitCode = ticketForwardable(args, i);
-        } else if ("-F".equals(cmd)) {
-            exitCode = ticketNonForwardable(args, i);
-        }
-
-        return exitCode;
-    }
-
-    /**
-     * Init the KrbClient
-     */
-    private KrbClient createClient(String confDirString) {
-        KrbConfig krbConfig = new KrbConfig();
-        Conf conf = krbConfig.getConf();
-
-        try {
-            File confDir = new File(confDirString);
-            File[] files = confDir.listFiles();
-            if (files == null) {
-                throw new IOException("There are no file in configuration directory: " +
confDirString);
-            }
-
-            for (File file : files) {
-                conf.addIniConfig(file);
-            }
-        } catch (IOException e) {
-            System.err.println("Something wrong with krb configuration.");
-            e.printStackTrace();
-        }
-
-        KrbClient krbClient = new KrbClient(krbConfig);
-        krbClient.init();
-        return krbClient;
-    }
-
-    /**
-     * Get password for the input principal from console
-     */
-    private String getPassword(String principal) {
-        Console console = System.console();
-        if (console == null) {
-            System.out.println("Couldn't get Console instance, maybe you're running this
from within an IDE. Use scanner to read password.");
-            System.out.println("Password for " + principal + ":");
-            Scanner scanner = new Scanner(System.in);
-            return scanner.nextLine().trim();
-        }
-        console.printf("Password for " + principal + ":");
-        char[] passwordChars = console.readPassword();
-        String password = new String(passwordChars).trim();
-        Arrays.fill(passwordChars, ' ');
-        return password;
-    }
-
-    private int requestTicket(String[] args, int i) {
-        String principal = args[i];
-        KrbClient client = createClient(args[0]);
-        String password = getPassword(principal);
-
-        try {
-            client.requestTgtTicket(principal, password, null);
-            return 0;
-        } catch (KrbException e) {
-            System.err.println("Something error.");
-            return -1;
-        }
-    }
-
-    private int ticketWithLifetime(String[] args, int i) {
-        String lifetime = args[i];
-        String principal = args[i];
-        KrbClient client = createClient(args[0]);
-        String password = getPassword(principal);
-        try {
-            //TODO
-            return 0;
-        } catch (Exception e) {
-            System.err.println("Something error.");
-            return -1;
-        }
-    }
-
-    private int ticketForwardable(String[] args, int i) {
-        String principal = args[i];
-        KrbClient client = createClient(args[0]);
-        String password = getPassword(principal);
-        try {
-            //TODO
-            return 0;
-        } catch (Exception e) {
-            System.err.println("Something error.");
-            return -1;
-        }
-    }
-
-    private int ticketNonForwardable(String[] args, int i) {
-        String principal = args[i];
-        KrbClient client = createClient(args[0]);
-        String password = getPassword(principal);
-        try {
-            //TODO
-            return 0;
-        } catch (Exception e) {
-            System.err.println("Something error.");
-            return -1;
-        }
-    }
-
-    public static void main(String[] args) throws Exception {
-        Kinit kinit = new Kinit();
-        int exitCode = kinit.execute(args);
-        System.exit(exitCode);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/515d3b66/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
new file mode 100644
index 0000000..eb76b3a
--- /dev/null
+++ b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/Kinit.java
@@ -0,0 +1,216 @@
+/**
+ *  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.kerberos.tool.kinit;
+
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.client.KrbClient;
+import org.apache.kerby.kerberos.kerb.client.KrbConfig;
+
+import java.io.Console;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Scanner;
+
+/**
+ * kinit like tool
+ */
+public class Kinit {
+
+    private static final String TOOL_NAME = Kinit.class.getSimpleName();
+    private static final String COMMON_USAGE = "Usage: " + TOOL_NAME +
+            " [-l lifetime]" +
+            " [-f | -F] principal\n" + "\n" +
+            "    options:\t-l lifetime\n" +
+            "\t-f forwardable\n" +
+            "\t-F not forwardable";
+
+    private void printUsage(String cmd) {
+        if ("-l".equals(cmd)) {
+            System.err.println("Usage: " + TOOL_NAME + " -l lifetime principal");
+        } else if ("-f".equals(cmd)) {
+            System.err.println("Usage: " + TOOL_NAME + " -f principal");
+        } else if ("-F".equals(cmd)) {
+            System.err.println("Usage: " + TOOL_NAME + " -F principal");
+        } else {
+            System.err.println(COMMON_USAGE);
+        }
+    }
+
+    /**
+     * args[0] is the configuration directory written in script.
+     * args[length - 1] is principal
+     */
+    private int execute(String[] args) {
+        if (args.length < 2 || args.length > 4) {
+            printUsage("");
+            return -1;
+        }
+
+        //no options
+        if (args.length == 2) {
+            return requestTicket(args, 1);
+        }
+
+        int exitCode = -1;
+        int i = 1;
+        String cmd = args[i];
+
+        //
+        // verify that we have enough option parameters
+        //
+        if ("-l".equals(cmd)) {
+            if (args.length != 4) {
+                printUsage(cmd);
+                return exitCode;
+            }
+        } else if ("-f".equals(cmd)) {
+            if (args.length != 3) {
+                printUsage(cmd);
+                return exitCode;
+            }
+        } else if ("-F".equals(cmd)) {
+            if (args.length != 3) {
+                printUsage(cmd);
+                return exitCode;
+            }
+        }
+
+        //
+        //execute the command
+        //
+        if ("-l".equals(cmd)) {
+            exitCode = ticketWithLifetime(args, i);
+        } else if ("-f".equals(cmd)) {
+            exitCode = ticketForwardable(args, i);
+        } else if ("-F".equals(cmd)) {
+            exitCode = ticketNonForwardable(args, i);
+        }
+
+        return exitCode;
+    }
+
+    /**
+     * Init the KrbClient
+     */
+    private KrbClient createClient(String confDirString) {
+        KrbConfig krbConfig = new KrbConfig();
+        Conf conf = krbConfig.getConf();
+
+        try {
+            File confDir = new File(confDirString);
+            File[] files = confDir.listFiles();
+            if (files == null) {
+                throw new IOException("There are no file in configuration directory: " +
confDirString);
+            }
+
+            for (File file : files) {
+                conf.addIniConfig(file);
+            }
+        } catch (IOException e) {
+            System.err.println("Something wrong with krb configuration.");
+            e.printStackTrace();
+        }
+
+        KrbClient krbClient = new KrbClient(krbConfig);
+        krbClient.init();
+        return krbClient;
+    }
+
+    /**
+     * Get password for the input principal from console
+     */
+    private String getPassword(String principal) {
+        Console console = System.console();
+        if (console == null) {
+            System.out.println("Couldn't get Console instance, maybe you're running this
from within an IDE. Use scanner to read password.");
+            System.out.println("Password for " + principal + ":");
+            Scanner scanner = new Scanner(System.in);
+            return scanner.nextLine().trim();
+        }
+        console.printf("Password for " + principal + ":");
+        char[] passwordChars = console.readPassword();
+        String password = new String(passwordChars).trim();
+        Arrays.fill(passwordChars, ' ');
+        return password;
+    }
+
+    private int requestTicket(String[] args, int i) {
+        String principal = args[i];
+        KrbClient client = createClient(args[0]);
+        String password = getPassword(principal);
+
+        try {
+            client.requestTgtTicket(principal, password, null);
+            return 0;
+        } catch (KrbException e) {
+            System.err.println("Something error.");
+            return -1;
+        }
+    }
+
+    private int ticketWithLifetime(String[] args, int i) {
+        String lifetime = args[i];
+        String principal = args[i];
+        KrbClient client = createClient(args[0]);
+        String password = getPassword(principal);
+        try {
+            //TODO
+            return 0;
+        } catch (Exception e) {
+            System.err.println("Something error.");
+            return -1;
+        }
+    }
+
+    private int ticketForwardable(String[] args, int i) {
+        String principal = args[i];
+        KrbClient client = createClient(args[0]);
+        String password = getPassword(principal);
+        try {
+            //TODO
+            return 0;
+        } catch (Exception e) {
+            System.err.println("Something error.");
+            return -1;
+        }
+    }
+
+    private int ticketNonForwardable(String[] args, int i) {
+        String principal = args[i];
+        KrbClient client = createClient(args[0]);
+        String password = getPassword(principal);
+        try {
+            //TODO
+            return 0;
+        } catch (Exception e) {
+            System.err.println("Something error.");
+            return -1;
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        Kinit kinit = new Kinit();
+        int exitCode = kinit.execute(args);
+        System.exit(exitCode);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/515d3b66/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
new file mode 100644
index 0000000..c36dda7
--- /dev/null
+++ b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/kinit/KinitOption.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.kerberos.tool.kinit;
+
+import org.apache.kerby.kerberos.kerb.client.KOption;
+
+public enum KinitOption implements KOption {
+    NONE("NONE"),
+    LIFE_TIME("-l", "lifetime"),
+    START_TIME("-s", "start time"),
+    RENEWABLE_TIME("-r", "renewable lifetime"),
+    FORWARDABLE("-f", "forwardable"),
+    NOT_FORWARDABLE("-F", "not forwardable"),
+    PROXIABLE("-p", "proxiable"),
+    NOT_PROXIABLE("-P", "not proxiable"),
+    ANONYMOUS("-n", "anonymous"),
+    INCLUDE_ADDRESSES("-a", "include addresses"),
+    NOT_INCLUDE_ADDRESSES("-A", "do not include addresses"),
+    VALIDATE("-v", "validate"),
+    RENEW("-R", "renew"),
+    CANONICALIZE("-C", "canonicalize"),
+    AS_ENTERPRISE_PN("-E", "client is enterprise principal name"),
+    USE_KEYTAB("-k", "use keytab"),
+    USE_DFT_KEYTAB("-i", "use default client keytab (with -k)"),
+    USER_KEYTAB_FILE("-t", "filename of keytab to use"),
+    KRB5_CACHE("-c", "Kerberos 5 cache name"),
+    SERVICE("-S", "service"),
+    ARMOR_CACHE("-T", "armor credential cache"),
+    XATTR("-X", "<attribute>[=<value>]"),
+    ;
+
+    private String name;
+    private String description;
+    private Object value;
+
+    KinitOption(String description) {
+        this.description = description;
+    }
+
+    KinitOption(String name, String description) {
+        this.name = name;
+        this.description = description;
+    }
+
+    @Override
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public String getName() {
+        if (name != null) {
+            return name;
+        }
+        return name();
+    }
+
+    @Override
+    public String getDescription() {
+        return this.description;
+    }
+
+    @Override
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    @Override
+    public Object getValue() {
+        return value;
+    }
+
+    public static KinitOption fromName(String name) {
+        if (name != null) {
+            for (KinitOption ko : values()) {
+                if (ko.getName().equals(name)) {
+                    return (KinitOption) ko;
+                }
+            }
+        }
+        return NONE;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/515d3b66/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
new file mode 100644
index 0000000..cb30d34
--- /dev/null
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KOption.java
@@ -0,0 +1,35 @@
+/**
+ *  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.kerberos.kerb.client;
+
+public interface KOption {
+
+    public void setName(String name);
+
+    public String getName();
+
+    public void setDescription(String description);
+
+    public String getDescription();
+
+    public void setValue(Object value);
+
+    public Object getValue();
+}

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/515d3b66/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 64d0d56..bc44937 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
@@ -19,41 +19,41 @@
  */
 package org.apache.kerby.kerberos.kerb.client;
 
-public enum KrbOption {
-    LIFE_TIME("-l lifetime"),
-    START_TIME("-s start time"),
-    RENEWABLE_TIME("-r renewable lifetime"),
-    FORWARDABLE("-f forwardable"),
-    NOT_FORWARDABLE("-F not forwardable"),
-    PROXIABLE("-p proxiable"),
-    NOT_PROXIABLE("-P not proxiable"),
-    ANONYMOUS("-n anonymous"),
-    INCLUDE_ADDRESSES("-a include addresses"),
-    NOT_INCLUDE_ADDRESSES("-A do not include addresses"),
-    VALIDATE("-v validate"),
-    RENEW("-R renew"),
-    CANONICALIZE("-C canonicalize"),
-    AS_ENTERPRISE_PN("-E client is enterprise principal name"),
-    USE_KEYTAB("-k use keytab"),
-    USE_DFT_KEYTAB("-i use default client keytab (with -k)"),
-    USER_KEYTAB_FILE("-t filename of keytab to use"),
-    KRB5_CACHE("-c Kerberos 5 cache name"),
-    SERVICE("-S service"),
-    ARMOR_CACHE("-T armor credential cache"),
-    XATTR("-X <attribute>[=<value>]"),
+public enum KrbOption implements KOption {
+    NONE("NONE"),
+    LIFE_TIME("lifetime"),
+    START_TIME("start-time"),
+    RENEWABLE_TIME("renewable-lifetime"),
+    FORWARDABLE("forwardable"),
+    NOT_FORWARDABLE("not-forwardable"),
+    PROXIABLE("proxiable"),
+    NOT_PROXIABLE("not-proxiable"),
+    ANONYMOUS("anonymous"),
+    INCLUDE_ADDRESSES("include-addresses"),
+    NOT_INCLUDE_ADDRESSES("do-not-include-addresses"),
+    VALIDATE("validate"),
+    RENEW("renew"),
+    CANONICALIZE("canonicalize"),
+    AS_ENTERPRISE_PN("as-enterprise-pn", "client is enterprise principal name"),
+    USE_KEYTAB("use-keytab", "use-keytab"),
+    USE_DFT_KEYTAB("user-default-keytab", "use default client keytab"),
+    USER_KEYTAB_FILE("user-keytab-file", "filename of keytab to use"),
+    KRB5_CACHE("krb5-cache", "K5 cache name"),
+    SERVICE("service"),
+    ARMOR_CACHE("armor-cache", "armor credential cache"),
 
-    USER_PASSWD("user_passwd", "User plain password"),
+    USER_PASSWD("user-passwd", "User plain password"),
 
-    PKINIT_X509_IDENTITY("x509_identities", "X509 user private key and cert"),
-    PKINIT_X509_PRIVATE_KEY("x509_privatekey", "X509 user private key"),
-    PKINIT_X509_CERTIFICATE("x509_cert", "X509 user certificate"),
-    PKINIT_X509_ANCHORS("x509_anchors", "X509 anchors"),
-    PKINIT_X509_ANONYMOUS("x509_anonymous", "X509 anonymous"),
-    PKINIT_USING_RSA("using_rsa_or_dh", "Using RSA or DH"),
+    PKINIT_X509_IDENTITY("x509-identities", "X509 user private key and cert"),
+    PKINIT_X509_PRIVATE_KEY("x509-privatekey", "X509 user private key"),
+    PKINIT_X509_CERTIFICATE("x509-cert", "X509 user certificate"),
+    PKINIT_X509_ANCHORS("x509-anchors", "X509 anchors"),
+    PKINIT_X509_ANONYMOUS("x509-anonymous", "X509 anonymous"),
+    PKINIT_USING_RSA("using-rsa-or-dh", "Using RSA or DH"),
 
-    TOKEN_USING_IDTOKEN("using_id_token", "Using identity token"),
-    TOKEN_USER_ID_TOKEN("user_id_token", "User identity token"),
-    TOKEN_USER_AC_TOKEN("user_ac_token", "User access token"),
+    TOKEN_USING_IDTOKEN("using-id-token", "Using identity token"),
+    TOKEN_USER_ID_TOKEN("user-id-token", "User identity token"),
+    TOKEN_USER_AC_TOKEN("user-ac-token", "User access token"),
 
     ;
 
@@ -70,6 +70,17 @@ public enum KrbOption {
         this.description = description;
     }
 
+    @Override
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
     public String getName() {
         if (name != null) {
             return name;
@@ -77,15 +88,29 @@ public enum KrbOption {
         return name();
     }
 
+    @Override
     public String getDescription() {
         return this.description;
     }
 
+    @Override
     public void setValue(Object value) {
         this.value = value;
     }
 
+    @Override
     public Object getValue() {
         return value;
     }
+
+    public static KrbOption fromName(String name) {
+        if (name != null) {
+            for (KrbOption ko : values()) {
+                if (ko.getName().equals(name)) {
+                    return (KrbOption) ko;
+                }
+            }
+        }
+        return NONE;
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/515d3b66/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 b3333ca..2ea4eb2 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
@@ -24,26 +24,27 @@ import java.util.Map;
 
 public class KrbOptions {
 
-    private final Map<KrbOption, KrbOption> options = new HashMap<KrbOption, KrbOption>(4);
+    private final Map<KOption, KOption> options =
+            new HashMap<KOption, KOption>();
 
-    public void add(KrbOption option) {
+    public void add(KOption option) {
         if (option != null) {
             options.put(option, option);
         }
     }
 
-    public void add(KrbOption option, Object optionValue) {
+    public void add(KOption option, Object optionValue) {
         if (option != null) {
             option.setValue(optionValue);
             add(option);
         }
     }
 
-    public boolean contains(KrbOption option) {
+    public boolean contains(KOption option) {
         return options.containsKey(option);
     }
 
-    public KrbOption getOption(KrbOption option) {
+    public KOption getOption(KOption option) {
         if (! options.containsKey(option)) {
             return null;
         }
@@ -51,14 +52,14 @@ public class KrbOptions {
         return options.get(option);
     }
 
-    public Object getOptionValue(KrbOption option) {
+    public Object getOptionValue(KOption option) {
         if (! contains(option)) {
             return null;
         }
         return options.get(option).getValue();
     }
 
-    public String getStringOption(KrbOption option) {
+    public String getStringOption(KOption option) {
         Object value = getOptionValue(option);
         if (value instanceof String) {
             return (String) value;
@@ -66,7 +67,7 @@ public class KrbOptions {
         return null;
     }
 
-    public boolean getBooleanOption(KrbOption option) {
+    public boolean getBooleanOption(KOption option) {
         Object value = getOptionValue(option);
         if (value instanceof String) {
             String strVal = (String) value;
@@ -81,7 +82,7 @@ public class KrbOptions {
         return false;
     }
 
-    public int getIntegerOption(KrbOption option) {
+    public int getIntegerOption(KOption option) {
         Object value = getOptionValue(option);
         if (value instanceof String) {
             String strVal = (String) value;


Mime
View raw message