You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2014/12/14 17:42:02 UTC

ambari git commit: AMBARI-8705. Kerberos wizard: API call to save krb5-conf configuration fails with server error. (Robert Levas via yusaku)

Repository: ambari
Updated Branches:
  refs/heads/trunk a1b2d1dd7 -> 7f2cfb47d


AMBARI-8705. Kerberos wizard: API call to save krb5-conf configuration fails with server error. (Robert Levas via yusaku)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7f2cfb47
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7f2cfb47
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7f2cfb47

Branch: refs/heads/trunk
Commit: 7f2cfb47d18c4dfa60fc7882dcd28d144734c3c9
Parents: a1b2d1d
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Sun Dec 14 08:41:40 2014 -0800
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Sun Dec 14 08:41:40 2014 -0800

----------------------------------------------------------------------
 .../server/serveraction/kerberos/KDCType.java   | 20 ++++++++++-
 .../kerberos/KerberosServerAction.java          |  2 +-
 .../serveraction/kerberos/KDCTypeTest.java      | 37 ++++++++++++++++++++
 3 files changed, 57 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7f2cfb47/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KDCType.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KDCType.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KDCType.java
index 51dcdd2..57b267d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KDCType.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KDCType.java
@@ -18,6 +18,8 @@
 
 package org.apache.ambari.server.serveraction.kerberos;
 
+import com.sun.istack.NotNull;
+
 /**
  * Enumerates the supported KDC types
  */
@@ -30,5 +32,21 @@ public enum KDCType {
   /**
    * Indicates a Microsoft Active Directory
    */
-  ACTIVE_DIRECTORY
+  ACTIVE_DIRECTORY;
+
+  /**
+   * Translates a String to a KDCType.
+   * <p/>
+   * The translation logic attempts to nicely convert a String to a KDCType by replacing all '-'
+   * characters to '_' characters and converting the String to uppercase. Allowing for values like
+   * "mit_kdc" to be translated to "MIT_KDC".
+   *
+   * @param value a String value to convert to a KDCType
+   * @return A KDCType
+   * @throws java.lang.IllegalArgumentException if this enum type has no constant with the specified name
+   * @throws java.lang.NullPointerException if the value to translate is null
+   */
+  public static KDCType translate(@NotNull String value) {
+    return KDCType.valueOf(value.replace("-", "_").toUpperCase());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/7f2cfb47/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
index 7a2412c..832602f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/KerberosServerAction.java
@@ -121,7 +121,7 @@ public abstract class KerberosServerAction extends AbstractServerAction {
 
     return ((kdcType == null) || kdcType.isEmpty())
         ? KDCType.MIT_KDC
-        : KDCType.valueOf(kdcType.toUpperCase().replace("-", "_"));
+        : KDCType.translate(kdcType);
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/7f2cfb47/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KDCTypeTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KDCTypeTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KDCTypeTest.java
new file mode 100644
index 0000000..a45eac2
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/KDCTypeTest.java
@@ -0,0 +1,37 @@
+package org.apache.ambari.server.serveraction.kerberos;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+public class KDCTypeTest {
+
+  @Test
+  public void testTranslateExact() {
+    Assert.assertEquals(KDCType.MIT_KDC, KDCType.translate("MIT_KDC"));
+  }
+
+  @Test
+  public void testTranslateCaseInsensitive() {
+    Assert.assertEquals(KDCType.MIT_KDC, KDCType.translate("mit_kdc"));
+  }
+
+  @Test
+  public void testTranslateHyphen() {
+    Assert.assertEquals(KDCType.MIT_KDC, KDCType.translate("MIT-KDC"));
+  }
+
+  @Test(expected = NullPointerException.class)
+  public void testTranslateNull() {
+    KDCType.translate(null);
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testTranslateEmptyString() {
+    KDCType.translate("");
+  }
+
+  @Test(expected = IllegalArgumentException.class)
+  public void testTranslateNoTranslation() {
+    KDCType.translate("NO TRANSLATION");
+  }
+}
\ No newline at end of file