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