You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by ph...@apache.org on 2012/06/30 08:30:59 UTC

svn commit: r1355651 - in /zookeeper/trunk: CHANGES.txt src/java/main/org/apache/zookeeper/server/auth/KerberosName.java src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java

Author: phunt
Date: Sat Jun 30 06:30:58 2012
New Revision: 1355651

URL: http://svn.apache.org/viewvc?rev=1355651&view=rev
Log:
ZOOKEEPER-1236. Security uses proprietary Sun APIs (Adalberto Medeiros via phunt)

Added:
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1355651&r1=1355650&r2=1355651&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Sat Jun 30 06:30:58 2012
@@ -197,6 +197,9 @@ BUGFIXES:
   ZOOKEEPER-1210. Can't build ZooKeeper RPM with RPM >= 4.6.0 (i.e. on
     RHEL 6 and Fedora >= 10) (Tadeusz Andrzej Kadłubowski via phunt)
 
+  ZOOKEEPER-1236. Security uses proprietary Sun APIs
+    (Adalberto Medeiros via phunt)
+
 IMPROVEMENTS:
 
   ZOOKEEPER-1170. Fix compiler (eclipse) warnings: unused imports,

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java?rev=1355651&r1=1355650&r2=1355651&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java Sat Jun 30 06:30:58 2012
@@ -32,8 +32,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import sun.security.krb5.Config;
-import sun.security.krb5.KrbException;
+
+import org.apache.zookeeper.server.util.KerberosUtil;
 
 /**
  * This class implements parsing and handling of Kerberos principal names. In 
@@ -79,17 +79,17 @@ public class KerberosName {
   private static List<Rule> rules;
 
   private static String defaultRealm;
-  private static Config kerbConf;
   
   static {
     try {
-      kerbConf = Config.getInstance();
-      defaultRealm = kerbConf.getDefaultRealm();
-    } catch (KrbException ke) {
+      defaultRealm = KerberosUtil.getDefaultRealm();
+    } catch (Exception ke) {
       if ((System.getProperty("zookeeper.requireKerberosConfig") != null) &&
           (System.getProperty("zookeeper.requireKerberosConfig").equals("true"))) {
         throw new IllegalArgumentException("Can't get Kerberos configuration",ke);
       }
+      else
+        defaultRealm="";
     }
     try {
       // setConfiguration() will work even if the above try() fails due

Added: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java?rev=1355651&view=auto
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java (added)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java Sat Jun 30 06:30:58 2012
@@ -0,0 +1,45 @@
+/*
+ * 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.zookeeper.server.util;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class KerberosUtil {
+
+  public static String getDefaultRealm() 
+      throws ClassNotFoundException, NoSuchMethodException, 
+      IllegalArgumentException, IllegalAccessException, 
+      InvocationTargetException {
+    Object kerbConf;
+    Class<?> classRef;
+    Method getInstanceMethod;
+    Method getDefaultRealmMethod;
+    if (System.getProperty("java.vendor").contains("IBM")) {
+      classRef = Class.forName("com.ibm.security.krb5.internal.Config");
+    } else {
+      classRef = Class.forName("sun.security.krb5.Config");
+    }
+    getInstanceMethod = classRef.getMethod("getInstance", new Class[0]);
+    kerbConf = getInstanceMethod.invoke(classRef, new Object[0]);
+    getDefaultRealmMethod = classRef.getDeclaredMethod("getDefaultRealm",
+         new Class[0]);
+    return (String)getDefaultRealmMethod.invoke(kerbConf, new Object[0]);
+  }
+}