diff --git a/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java b/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java index c985887a1efa8c42a8341ae2026b0d462ec4a8b5..780b93030828d4a3fec79d5bf5040e46e0b4532b 100644 --- a/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java +++ b/src/share/classes/sun/security/krb5/internal/ccache/FileCredentialsCache.java @@ -348,7 +348,7 @@ public class FileCredentialsCache extends CredentialsCache * Returns path name of the credentials cache file. * The path name is searched in the following order: * - * 1. KRB5CCNAME + * 1. KRB5CCNAME (bare file name without FILE:) * 2. /tmp/krb5cc_ on unix systems * 3. /krb5cc_ * 4. /krb5cc (if can't get ) @@ -359,11 +359,19 @@ public class FileCredentialsCache extends CredentialsCache String stdCacheNameComponent = "krb5cc"; String name; + // The env var can start with TYPE:, we only support FILE: here. + // http://docs.oracle.com/cd/E19082-01/819-2252/6n4i8rtr3/index.html name = java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { @Override public String run() { - return System.getenv("KRB5CCNAME"); + String cache = System.getenv("KRB5CCNAME"); + if (cache != null && + (cache.length() >= 5) && + cache.regionMatches(true, 0, "FILE:", 0, 5)) { + cache = cache.substring(5); + } + return cache; } }); if (name != null) { diff --git a/test/sun/security/krb5/ccache/EmptyCC.java b/test/sun/security/krb5/ccache/EmptyCC.java index d5bfc00865199abc1b59a19884085aa436985fa2..a0cd759373dd4cb9157f821ee9e3840552ab140f 100644 --- a/test/sun/security/krb5/ccache/EmptyCC.java +++ b/test/sun/security/krb5/ccache/EmptyCC.java @@ -24,9 +24,11 @@ /* * @test * @bug 7158329 + * @bug 8001208 * @summary NPE in sun.security.krb5.Credentials.acquireDefaultCreds() * @compile -XDignore.symbol.file EmptyCC.java - * @run main EmptyCC + * @run main EmptyCC tmpcc + * @run main EmptyCC FILE:tmpcc */ import java.io.File; import java.io.InputStream; @@ -40,9 +42,9 @@ import sun.security.krb5.internal.ccache.CredentialsCache; public class EmptyCC { public static void main(String[] args) throws Exception { final PrincipalName pn = new PrincipalName("dummy@FOO.COM"); - final String ccache = "tmpcc"; + final String ccache = args[0]; - if (args.length == 0) { + if (args.length == 1) { // Main process, write the ccache and launch sub process CredentialsCache cache = CredentialsCache.create(pn, ccache); cache.save(); @@ -54,6 +56,7 @@ public class EmptyCC { "-cp", System.getProperty("test.classes"), "EmptyCC", + ccache, "readcc" ); @@ -77,6 +80,14 @@ public class EmptyCC { if (!cc.equals(ccache)) { throw new Exception("env not set correctly"); } + // 8001208: Fix for KRB5CCNAME not complete + // Make sure the ccache is created with bare file name + if (CredentialsCache.getInstance() == null) { + throw new Exception("Cache not instantiated"); + } + if (!new File("tmpcc").exists()) { + throw new Exception("File not found"); + } Credentials.acquireTGTFromCache(pn, null); } }