5358N/A/*
5358N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5358N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5358N/A *
5358N/A * This code is free software; you can redistribute it and/or modify it
5358N/A * under the terms of the GNU General Public License version 2 only, as
5358N/A * published by the Free Software Foundation.
5358N/A *
5358N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5358N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5358N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5358N/A * version 2 for more details (a copy is included in the LICENSE file that
5358N/A * accompanied this code).
5358N/A *
5358N/A * You should have received a copy of the GNU General Public License version
5358N/A * 2 along with this work; if not, write to the Free Software Foundation,
5358N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5358N/A *
5358N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5358N/A * or visit www.oracle.com if you need additional information or have any
5358N/A * questions.
5358N/A */
5358N/A
5358N/A/*
5358N/A * @test
5358N/A * @bug 7158329
5387N/A * @bug 8001208
5358N/A * @summary NPE in sun.security.krb5.Credentials.acquireDefaultCreds()
5358N/A * @compile -XDignore.symbol.file EmptyCC.java
5387N/A * @run main EmptyCC tmpcc
5387N/A * @run main EmptyCC FILE:tmpcc
5358N/A */
5358N/Aimport java.io.File;
5358N/Aimport java.io.InputStream;
5358N/Aimport java.util.ArrayList;
5358N/Aimport java.util.Arrays;
5358N/Aimport java.util.List;
5358N/Aimport sun.security.krb5.Credentials;
5358N/Aimport sun.security.krb5.PrincipalName;
5358N/Aimport sun.security.krb5.internal.ccache.CredentialsCache;
5358N/A
5358N/Apublic class EmptyCC {
5358N/A public static void main(String[] args) throws Exception {
5358N/A final PrincipalName pn = new PrincipalName("dummy@FOO.COM");
5387N/A final String ccache = args[0];
5358N/A
5387N/A if (args.length == 1) {
5358N/A // Main process, write the ccache and launch sub process
5358N/A CredentialsCache cache = CredentialsCache.create(pn, ccache);
5358N/A cache.save();
5358N/A
5358N/A // java -cp $test.classes EmptyCC readcc
5358N/A ProcessBuilder pb = new ProcessBuilder(
5358N/A new File(new File(System.getProperty("java.home"), "bin"),
5358N/A "java").getPath(),
5358N/A "-cp",
5358N/A System.getProperty("test.classes"),
5358N/A "EmptyCC",
5387N/A ccache,
5358N/A "readcc"
5358N/A );
5358N/A
5358N/A pb.environment().put("KRB5CCNAME", ccache);
5358N/A pb.redirectErrorStream(true);
5358N/A
5358N/A Process p = pb.start();
5358N/A try (InputStream ins = p.getInputStream()) {
5358N/A byte[] buf = new byte[8192];
5358N/A int n;
5358N/A while ((n = ins.read(buf)) > 0) {
5358N/A System.out.write(buf, 0, n);
5358N/A }
5358N/A }
5358N/A if (p.waitFor() != 0) {
5358N/A throw new Exception("Test failed");
5358N/A }
5358N/A } else {
5358N/A // Sub process, read the ccache
5358N/A String cc = System.getenv("KRB5CCNAME");
5358N/A if (!cc.equals(ccache)) {
5358N/A throw new Exception("env not set correctly");
5358N/A }
5387N/A // 8001208: Fix for KRB5CCNAME not complete
5387N/A // Make sure the ccache is created with bare file name
5387N/A if (CredentialsCache.getInstance() == null) {
5387N/A throw new Exception("Cache not instantiated");
5387N/A }
5387N/A if (!new File("tmpcc").exists()) {
5387N/A throw new Exception("File not found");
5387N/A }
5358N/A Credentials.acquireTGTFromCache(pn, null);
5358N/A }
5358N/A }
5358N/A}