1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 7158329 27 * @bug 8001208 28 * @summary NPE in sun.security.krb5.Credentials.acquireDefaultCreds() 29 * @library ../../../../java/security/testlibrary/ 30 * @modules java.base/jdk.internal.misc 31 * java.security.jgss/sun.security.krb5 32 * java.security.jgss/sun.security.krb5.internal.ccache 33 * @compile -XDignore.symbol.file EmptyCC.java 34 * @run main EmptyCC tmpcc 35 * @run main EmptyCC FILE:tmpcc 36 */ 37 import java.io.File; 38 import sun.security.krb5.Credentials; 39 import sun.security.krb5.PrincipalName; 40 import sun.security.krb5.internal.ccache.CredentialsCache; 41 42 public class EmptyCC { 43 public static void main(String[] args) throws Exception { 44 final PrincipalName pn = new PrincipalName("dummy@FOO.COM"); 45 final String ccache = args[0]; 46 47 if (args.length == 1) { 48 // Main process, write the ccache and launch sub process 49 CredentialsCache cache = CredentialsCache.create(pn, ccache); 50 cache.save(); 51 Proc p = Proc.create("EmptyCC").args(ccache, "readcc") 52 .env("KRB5CCNAME", ccache).start(); 53 p.waitFor(); 54 } else { 55 // Sub process, read the ccache 56 String cc = System.getenv("KRB5CCNAME"); 57 if (!cc.equals(ccache)) { 58 throw new Exception("env not set correctly"); 59 } 60 // 8001208: Fix for KRB5CCNAME not complete 61 // Make sure the ccache is created with bare file name 62 if (CredentialsCache.getInstance() == null) { 63 throw new Exception("Cache not instantiated"); 64 } 65 if (!new File("tmpcc").exists()) { 66 throw new Exception("File not found"); 67 } 68 Credentials.acquireTGTFromCache(pn, null); 69 } 70 } 71 }