0N/A/*
2362N/A * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4373996
0N/A * @summary parser incorrectly ignores a principal if the principal name
0N/A * expands to nothing. this test is a bit complicated.
0N/A *
0N/A * 1) PrincipalExpansionError.java
0N/A * the test itself. this test creates a Subject with a
0N/A * SolarisPrincipal("TestPrincipal") and calls doAs
0N/A * with a PrincipalExpansionErrorAction.
0N/A *
0N/A * 2) PrincipalExpansionErrorAction
0N/A * this action tries to read the file, /testfile
0N/A *
0N/A * 3) to run the test:
0N/A * a) jtreg -verbose:all -testjdk:<your_jdk>/build/sparc
0N/A * PrincipalExpansionError.java
0N/A * b) PrincipalExpansionError is compiled and put into
0N/A * the "test.classes" directory
0N/A * c) PrincipalExpansionErrorAction is compiled and put into
0N/A * the "test.classes"/apackage directory
0N/A * (since it belongs to the 'apackage' package
0N/A * d) the PrincipalExpansionError shell script moves
0N/A * test.classes/apackage to test.src/apackage.
0N/A * this guarantees that the test will run
0N/A * with codebase test.classes, and the action
0N/A * will run with codebase test.src.
0N/A * e) the test is executed. permissions to read the file,
0N/A * /testfile, were granted to the PrincipalExpansionError.
0N/A * the policy entry for PrincipalExpansionErrorAction
0N/A * running as SolarisPrincipal("TestPrincipal")
0N/A * was also granted the file permission,
0N/A * but it has a bogus second SolarisPrincipal with
0N/A * a name that can't be property-expanded.
0N/A *
0N/A * the old behavior of the code would ignore the
0N/A * bogus entry and incorrectly grants the file permission
0N/A * to SolarisPrincipal("TestPrincipal").
0N/A * the new behavior correctly ignores the entire
0N/A * policy entry.
0N/A * Please note that the jtreg needs to be granted
0N/A * allpermissions for this test to succeed. If the codebase
0N/A * for jtreg changes, the PrincipalExpansionError.policy
0N/A * needs to be updated.
0N/A *
0N/A * f) original @ tags:
0N/A * compile PrincipalExpansionErrorAction.java
0N/A * run shell PrincipalExpansionError.sh
0N/A * run main/othervm/policy=PrincipalExpansionError.policy
0N/A * -Djava.security.debug=access,domain,failure
0N/A * PrincipalExpansionError
0N/A *
0N/A * @ignore unable to rely on location or javatest.jar
0N/A * (so we can grant it AllPermission)
0N/A */
0N/A
0N/Aimport javax.security.auth.*;
0N/Aimport com.sun.security.auth.*;
0N/Aimport java.util.Set;
0N/Aimport apackage.PrincipalExpansionErrorAction;
0N/A
0N/Apublic class PrincipalExpansionError {
0N/A
0N/A public static void main(String[] args) {
0N/A
0N/A Subject s = new Subject();
0N/A
0N/A try {
0N/A Set principals = s.getPrincipals();
0N/A principals.add(new SolarisPrincipal("TestPrincipal"));
0N/A } catch (SecurityException se) {
0N/A // test incorrectly set up
0N/A throw new SecurityException
0N/A ("PrincipalExpansionError test incorrectly set up:" + se);
0N/A }
0N/A
0N/A try {
0N/A Subject.doAs(s, new PrincipalExpansionErrorAction());
0N/A
0N/A // test failed
0N/A System.out.println("PrincipalExpansionError test failed");
0N/A throw new SecurityException("PrincipalExpansionError test failed");
0N/A
0N/A } catch (java.security.PrivilegedActionException pae) {
0N/A Exception e = pae.getException();
0N/A
0N/A if (e instanceof java.io.FileNotFoundException) {
0N/A System.out.println
0N/A ("PrincipalExpansionError test failed (file not found)");
0N/A java.io.FileNotFoundException fnfe =
0N/A (java.io.FileNotFoundException)e;
0N/A throw new SecurityException("PrincipalExpansionError" +
0N/A "test failed (file not found)");
0N/A } else {
0N/A // i don't know???
0N/A System.out.println("what happened?");
0N/A pae.printStackTrace();
0N/A }
0N/A } catch (SecurityException se) {
0N/A // good! test succeeded
0N/A System.out.println("PrincipalExpansionError test succeeded");
0N/A se.printStackTrace();
0N/A }
0N/A }
0N/A}