8039951: com.sun.security.auth.module missing classes on some platforms
authorweijun
Thu, 08 May 2014 22:30:31 +0800
changeset 24271 19000122bb5e
parent 24270 12b6bc57472d
child 24272 91e947c10ddb
child 24273 a893e41e815e
8039951: com.sun.security.auth.module missing classes on some platforms Reviewed-by: mullan
jdk/make/CompileJavaClasses.gmk
jdk/src/share/classes/com/sun/security/auth/module/NTLoginModule.java
jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java
jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java
jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java
jdk/test/com/sun/security/auth/module/AllPlatforms.java
jdk/test/sun/security/krb5/auto/ReplayCacheTestProc.java
--- a/jdk/make/CompileJavaClasses.gmk	Thu May 08 22:30:24 2014 +0800
+++ b/jdk/make/CompileJavaClasses.gmk	Thu May 08 22:30:31 2014 +0800
@@ -84,8 +84,6 @@
       SolarisUserDefinedFileAttributeView.java \
       SolarisWatchService.java \
       SolarisAclFileAttributeView.java \
-      SolarisLoginModule.java \
-      SolarisSystem.java \
       sun/nio/ch/DevPollArrayWrapper.java \
       sun/nio/ch/DevPollSelectorImpl.java \
       sun/nio/ch/DevPollSelectorProvider.java \
@@ -100,15 +98,6 @@
   EXCLUDES += com/oracle/security
 endif
 
-ifneq ($(OPENJDK_TARGET_OS), windows)
-  # Exclude Window security related files in src/share/classes
-  EXFILES += NTLoginModule.java \
-      NTSystem.java
-else
-  EXFILES += UnixLoginModule.java \
-      UnixSystem.java
-endif
-
 ifeq ($(OPENJDK_TARGET_OS), windows)
   # Don't build GTK L&F on Windows
   EXCLUDES += com/sun/java/swing/plaf/gtk
--- a/jdk/src/share/classes/com/sun/security/auth/module/NTLoginModule.java	Thu May 08 22:30:24 2014 +0800
+++ b/jdk/src/share/classes/com/sun/security/auth/module/NTLoginModule.java	Thu May 08 22:30:31 2014 +0800
@@ -139,15 +139,17 @@
 
         succeeded = false; // Indicate not yet successful
 
-        ntSystem = new NTSystem(debugNative);
-        if (ntSystem == null) {
+        try {
+            ntSystem = new NTSystem(debugNative);
+        } catch (UnsatisfiedLinkError ule) {
             if (debug) {
                 System.out.println("\t\t[NTLoginModule] " +
                                    "Failed in NT login");
             }
             throw new FailedLoginException
                 ("Failed in attempt to import the " +
-                 "underlying NT system identity information");
+                 "underlying NT system identity information" +
+                 " on " + System.getProperty("os.name"));
         }
 
         if (ntSystem.getName() == null) {
--- a/jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java	Thu May 08 22:30:24 2014 +0800
+++ b/jdk/src/share/classes/com/sun/security/auth/module/SolarisLoginModule.java	Thu May 08 22:30:31 2014 +0800
@@ -129,39 +129,39 @@
 
         long[] solarisGroups = null;
 
-        ss = new SolarisSystem();
-
-        if (ss == null) {
+        try {
+            ss = new SolarisSystem();
+        } catch (UnsatisfiedLinkError ule) {
             succeeded = false;
             throw new FailedLoginException
                                 ("Failed in attempt to import " +
-                                "the underlying system identity information");
-        } else {
-            userPrincipal = new SolarisPrincipal(ss.getUsername());
-            UIDPrincipal = new SolarisNumericUserPrincipal(ss.getUid());
-            GIDPrincipal = new SolarisNumericGroupPrincipal(ss.getGid(), true);
-            if (ss.getGroups() != null && ss.getGroups().length > 0)
-                solarisGroups = ss.getGroups();
-                for (int i = 0; i < solarisGroups.length; i++) {
-                    SolarisNumericGroupPrincipal ngp =
-                        new SolarisNumericGroupPrincipal
-                        (solarisGroups[i], false);
-                    if (!ngp.getName().equals(GIDPrincipal.getName()))
-                        supplementaryGroups.add(ngp);
-                }
-            if (debug) {
-                System.out.println("\t\t[SolarisLoginModule]: " +
-                        "succeeded importing info: ");
-                System.out.println("\t\t\tuid = " + ss.getUid());
-                System.out.println("\t\t\tgid = " + ss.getGid());
-                solarisGroups = ss.getGroups();
-                for (int i = 0; i < solarisGroups.length; i++) {
-                    System.out.println("\t\t\tsupp gid = " + solarisGroups[i]);
-                }
+                                "the underlying system identity information" +
+                                " on " + System.getProperty("os.name"));
+        }
+        userPrincipal = new SolarisPrincipal(ss.getUsername());
+        UIDPrincipal = new SolarisNumericUserPrincipal(ss.getUid());
+        GIDPrincipal = new SolarisNumericGroupPrincipal(ss.getGid(), true);
+        if (ss.getGroups() != null && ss.getGroups().length > 0)
+            solarisGroups = ss.getGroups();
+            for (int i = 0; i < solarisGroups.length; i++) {
+                SolarisNumericGroupPrincipal ngp =
+                    new SolarisNumericGroupPrincipal
+                    (solarisGroups[i], false);
+                if (!ngp.getName().equals(GIDPrincipal.getName()))
+                    supplementaryGroups.add(ngp);
             }
-            succeeded = true;
-            return true;
+        if (debug) {
+            System.out.println("\t\t[SolarisLoginModule]: " +
+                    "succeeded importing info: ");
+            System.out.println("\t\t\tuid = " + ss.getUid());
+            System.out.println("\t\t\tgid = " + ss.getGid());
+            solarisGroups = ss.getGroups();
+            for (int i = 0; i < solarisGroups.length; i++) {
+                System.out.println("\t\t\tsupp gid = " + solarisGroups[i]);
+            }
         }
+        succeeded = true;
+        return true;
     }
 
     /**
--- a/jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java	Thu May 08 22:30:24 2014 +0800
+++ b/jdk/src/share/classes/com/sun/security/auth/module/UnixLoginModule.java	Thu May 08 22:30:31 2014 +0800
@@ -122,40 +122,40 @@
 
         long[] unixGroups = null;
 
-        ss = new UnixSystem();
-
-        if (ss == null) {
+        try {
+            ss = new UnixSystem();
+        } catch (UnsatisfiedLinkError ule) {
             succeeded = false;
             throw new FailedLoginException
                                 ("Failed in attempt to import " +
-                                "the underlying system identity information");
-        } else {
-            userPrincipal = new UnixPrincipal(ss.getUsername());
-            UIDPrincipal = new UnixNumericUserPrincipal(ss.getUid());
-            GIDPrincipal = new UnixNumericGroupPrincipal(ss.getGid(), true);
-            if (ss.getGroups() != null && ss.getGroups().length > 0) {
-                unixGroups = ss.getGroups();
-                for (int i = 0; i < unixGroups.length; i++) {
-                    UnixNumericGroupPrincipal ngp =
-                        new UnixNumericGroupPrincipal
-                        (unixGroups[i], false);
-                    if (!ngp.getName().equals(GIDPrincipal.getName()))
-                        supplementaryGroups.add(ngp);
-                }
+                                "the underlying system identity information" +
+                                " on " + System.getProperty("os.name"));
+        }
+        userPrincipal = new UnixPrincipal(ss.getUsername());
+        UIDPrincipal = new UnixNumericUserPrincipal(ss.getUid());
+        GIDPrincipal = new UnixNumericGroupPrincipal(ss.getGid(), true);
+        if (ss.getGroups() != null && ss.getGroups().length > 0) {
+            unixGroups = ss.getGroups();
+            for (int i = 0; i < unixGroups.length; i++) {
+                UnixNumericGroupPrincipal ngp =
+                    new UnixNumericGroupPrincipal
+                    (unixGroups[i], false);
+                if (!ngp.getName().equals(GIDPrincipal.getName()))
+                    supplementaryGroups.add(ngp);
             }
-            if (debug) {
-                System.out.println("\t\t[UnixLoginModule]: " +
-                        "succeeded importing info: ");
-                System.out.println("\t\t\tuid = " + ss.getUid());
-                System.out.println("\t\t\tgid = " + ss.getGid());
-                unixGroups = ss.getGroups();
-                for (int i = 0; i < unixGroups.length; i++) {
-                    System.out.println("\t\t\tsupp gid = " + unixGroups[i]);
-                }
+        }
+        if (debug) {
+            System.out.println("\t\t[UnixLoginModule]: " +
+                    "succeeded importing info: ");
+            System.out.println("\t\t\tuid = " + ss.getUid());
+            System.out.println("\t\t\tgid = " + ss.getGid());
+            unixGroups = ss.getGroups();
+            for (int i = 0; i < unixGroups.length; i++) {
+                System.out.println("\t\t\tsupp gid = " + unixGroups[i]);
             }
-            succeeded = true;
-            return true;
         }
+        succeeded = true;
+        return true;
     }
 
     /**
--- a/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java	Thu May 08 22:30:24 2014 +0800
+++ b/jdk/src/share/classes/sun/security/krb5/internal/rcache/DflCache.java	Thu May 08 22:30:31 2014 +0800
@@ -39,6 +39,7 @@
 import java.security.AccessController;
 import java.util.*;
 
+import com.sun.security.auth.module.UnixSystem;
 import sun.security.action.GetPropertyAction;
 import sun.security.krb5.internal.KerberosTime;
 import sun.security.krb5.internal.Krb5;
@@ -105,14 +106,14 @@
 
     private final String source;
 
-    private static int uid;
+    private static long uid;
     static {
         try {
             // Available on Solaris, Linux and Mac. Otherwise, no _euid suffix
-            Class<?> clazz = Class.forName("com.sun.security.auth.module.UnixSystem");
-            uid = (int)(long)(Long)
-                    clazz.getMethod("getUid").invoke(clazz.newInstance());
-        } catch (Exception e) {
+            UnixSystem us = new com.sun.security.auth.module.UnixSystem();
+            uid = us.getUid();
+        } catch (Throwable e) {
+            // Cannot be only Exception, might be UnsatisfiedLinkError
             uid = -1;
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/security/auth/module/AllPlatforms.java	Thu May 08 22:30:31 2014 +0800
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8039951
+ * @summary com.sun.security.auth.module missing classes on some platforms
+ * @run main/othervm AllPlatforms
+ */
+
+import javax.security.auth.login.Configuration;
+import javax.security.auth.login.LoginContext;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+public class AllPlatforms {
+    public static void main(String[] args) throws Exception {
+        login("cross-platform",
+                "UnixLoginModule", "optional",
+                "NTLoginModule", "optional",
+                "SolarisLoginModule", "optional");
+        try {
+            login("windows", "NTLoginModule", "required");
+            login("unix", "UnixLoginModule", "required");
+            login("solaris", "SolarisLoginModule", "required");
+        } catch (Exception e) {
+            e.printStackTrace(System.out);
+            if (e.toString().contains("UnsatisfiedLinkError")) {
+                throw new Exception("This is ugly");
+            }
+        }
+    }
+
+    static void login(String test, String... conf) throws Exception {
+        System.out.println("Testing " + test + "...");
+
+        StringBuilder sb = new StringBuilder();
+        sb.append("hello {\n");
+        for (int i=0; i<conf.length; i+=2) {
+            sb.append("    com.sun.security.auth.module." + conf[i]
+                    + " " + conf[i+1] + ";\n");
+        }
+        sb.append("};\n");
+        Files.write(Paths.get(test), sb.toString().getBytes());
+
+        // Must be called. Configuration has an internal static field.
+        Configuration.setConfiguration(null);
+        System.setProperty("java.security.auth.login.config", test);
+
+        LoginContext lc = new LoginContext("hello");
+        lc.login();
+        System.out.println(lc.getSubject());
+    }
+}
--- a/jdk/test/sun/security/krb5/auto/ReplayCacheTestProc.java	Thu May 08 22:30:24 2014 +0800
+++ b/jdk/test/sun/security/krb5/auto/ReplayCacheTestProc.java	Thu May 08 22:30:31 2014 +0800
@@ -39,6 +39,8 @@
 import java.nio.file.StandardOpenOption;
 import java.security.MessageDigest;
 import java.util.*;
+
+import com.sun.security.auth.module.UnixSystem;
 import sun.security.jgss.GSSUtil;
 import sun.security.krb5.internal.APReq;
 import sun.security.krb5.internal.rcache.AuthTime;
@@ -59,7 +61,7 @@
                 System.getProperty("user.dir");
 
 
-    private static int uid;
+    private static long uid;
 
     public static void main0(String[] args) throws Exception {
         System.setProperty("java.security.krb5.conf", OneKDC.KRB5_CONF);
@@ -78,11 +80,10 @@
             }
 
             try {
-                Class<?> clazz = Class.forName(
-                        "com.sun.security.auth.module.UnixSystem");
-                uid = (int)(long)(Long)
-                        clazz.getMethod("getUid").invoke(clazz.newInstance());
-            } catch (Exception e) {
+                UnixSystem us = new com.sun.security.auth.module.UnixSystem();
+                uid = us.getUid();
+            } catch (Throwable e) {
+                // Cannot be only Exception, might be UnsatisfiedLinkError
                 uid = -1;
             }