zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r1355650 - in /zookeeper/branches/branch-3.4: CHANGES.txt src/java/main/org/apache/zookeeper/server/auth/KerberosName.java src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
Date Sat, 30 Jun 2012 06:29:46 GMT
Author: phunt
Date: Sat Jun 30 06:29:45 2012
New Revision: 1355650

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

Added:
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
Modified:
    zookeeper/branches/branch-3.4/CHANGES.txt
    zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java

Modified: zookeeper/branches/branch-3.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/CHANGES.txt?rev=1355650&r1=1355649&r2=1355650&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.4/CHANGES.txt Sat Jun 30 06:29:45 2012
@@ -68,6 +68,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-1389. it would be nice if start-foreground used exec $JAVA

Modified: zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java?rev=1355650&r1=1355649&r2=1355650&view=diff
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
(original)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/auth/KerberosName.java
Sat Jun 30 06:29:45 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/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java?rev=1355650&view=auto
==============================================================================
--- zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
(added)
+++ zookeeper/branches/branch-3.4/src/java/main/org/apache/zookeeper/server/util/KerberosUtil.java
Sat Jun 30 06:29:45 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]);
+  }
+}



Mime
View raw message