8039951: com.sun.security.auth.module missing classes on some platforms

Reviewed-by: mullan
This commit is contained in:
Weijun Wang 2014-05-08 22:30:31 +08:00
parent db6cc0853b
commit 79cdf6ad7f
7 changed files with 151 additions and 84 deletions

View File

@ -84,8 +84,6 @@ ifneq ($(OPENJDK_TARGET_OS), solaris)
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 @@ ifneq ($(OPENJDK_TARGET_OS), solaris)
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

View File

@ -139,15 +139,17 @@ public class NTLoginModule implements LoginModule {
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) {

View File

@ -129,39 +129,39 @@ public class SolarisLoginModule implements LoginModule {
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]);
}
}
succeeded = true;
return true;
"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);
}
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;
}
/**

View File

@ -122,40 +122,40 @@ public class UnixLoginModule implements LoginModule {
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);
}
}
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;
"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]);
}
}
succeeded = true;
return true;
}
/**

View File

@ -39,6 +39,7 @@ import java.nio.file.attribute.PosixFilePermission;
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 @@ public class DflCache extends ReplayCache {
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;
}
}

View File

@ -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());
}
}

View File

@ -39,6 +39,8 @@ import java.nio.file.StandardCopyOption;
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 @@ public class ReplayCacheTestProc {
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 @@ public class ReplayCacheTestProc {
}
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;
}