author | jlaskey |
Fri, 20 May 2016 11:41:29 -0300 | |
changeset 38445 | 0a88d86065f9 |
parent 23357 | 7225e28e91dd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4373996 |
|
27 |
* @summary parser incorrectly ignores a principal if the principal name |
|
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
28 |
* expands to nothing. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
29 |
* @run main/manual PrincipalExpansionError |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
30 |
*/ |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
31 |
|
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
32 |
/* |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
33 |
* This test is a bit complicated. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
34 |
* 1) PrincipalExpansionError.java |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
35 |
* the test itself. this test creates a Subject with a |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
36 |
* SolarisPrincipal("TestPrincipal") and calls doAs |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
37 |
* with a PrincipalExpansionErrorAction. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
38 |
* 2) PrincipalExpansionErrorAction |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
39 |
* this action tries to read the file, /testfile |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
40 |
* 3) to run the test: |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
41 |
* a) jtreg -verbose:all -testjdk:<your_jdk>/build/sparc |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
42 |
* PrincipalExpansionError.java |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
43 |
* b) PrincipalExpansionError is compiled and put into |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
44 |
* the "test.classes" directory |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
45 |
* c) PrincipalExpansionErrorAction is compiled and put into |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
46 |
* the "test.classes"/apackage directory |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
47 |
* (since it belongs to the 'apackage' package |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
48 |
* d) the PrincipalExpansionError shell script moves |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
49 |
* test.classes/apackage to test.src/apackage. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
50 |
* this guarantees that the test will run |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
51 |
* with codebase test.classes, and the action |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
52 |
* will run with codebase test.src. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
53 |
* e) the test is executed. permissions to read the file, |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
54 |
* /testfile, were granted to the PrincipalExpansionError. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
55 |
* the policy entry for PrincipalExpansionErrorAction |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
56 |
* running as SolarisPrincipal("TestPrincipal") |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
57 |
* was also granted the file permission, |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
58 |
* but it has a bogus second SolarisPrincipal with |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
59 |
* a name that can't be property-expanded. |
2 | 60 |
* |
23357
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
61 |
* the old behavior of the code would ignore the |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
62 |
* bogus entry and incorrectly grants the file permission |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
63 |
* to SolarisPrincipal("TestPrincipal"). |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
64 |
* the new behavior correctly ignores the entire |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
65 |
* policy entry. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
66 |
* Please note that the jtreg needs to be granted |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
67 |
* allpermissions for this test to succeed. If the codebase |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
68 |
* for jtreg changes, the PrincipalExpansionError.policy |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
69 |
* needs to be updated. |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
70 |
* f) original @ tags: |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
71 |
* compile PrincipalExpansionErrorAction.java |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
72 |
* run shell PrincipalExpansionError.sh |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
73 |
* run main/othervm/policy=PrincipalExpansionError.policy |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
74 |
* -Djava.security.debug=access,domain,failure |
7225e28e91dd
8033271: Manual security tests have @ignore rather than @run main/manual
wetmore
parents:
5506
diff
changeset
|
75 |
* PrincipalExpansionError |
2 | 76 |
*/ |
77 |
||
78 |
import javax.security.auth.*; |
|
79 |
import com.sun.security.auth.*; |
|
80 |
import java.util.Set; |
|
81 |
import apackage.PrincipalExpansionErrorAction; |
|
82 |
||
83 |
public class PrincipalExpansionError { |
|
84 |
||
85 |
public static void main(String[] args) { |
|
86 |
||
87 |
Subject s = new Subject(); |
|
88 |
||
89 |
try { |
|
90 |
Set principals = s.getPrincipals(); |
|
91 |
principals.add(new SolarisPrincipal("TestPrincipal")); |
|
92 |
} catch (SecurityException se) { |
|
93 |
// test incorrectly set up |
|
94 |
throw new SecurityException |
|
95 |
("PrincipalExpansionError test incorrectly set up:" + se); |
|
96 |
} |
|
97 |
||
98 |
try { |
|
99 |
Subject.doAs(s, new PrincipalExpansionErrorAction()); |
|
100 |
||
101 |
// test failed |
|
102 |
System.out.println("PrincipalExpansionError test failed"); |
|
103 |
throw new SecurityException("PrincipalExpansionError test failed"); |
|
104 |
||
105 |
} catch (java.security.PrivilegedActionException pae) { |
|
106 |
Exception e = pae.getException(); |
|
107 |
||
108 |
if (e instanceof java.io.FileNotFoundException) { |
|
109 |
System.out.println |
|
110 |
("PrincipalExpansionError test failed (file not found)"); |
|
111 |
java.io.FileNotFoundException fnfe = |
|
112 |
(java.io.FileNotFoundException)e; |
|
113 |
throw new SecurityException("PrincipalExpansionError" + |
|
114 |
"test failed (file not found)"); |
|
115 |
} else { |
|
116 |
// i don't know??? |
|
117 |
System.out.println("what happened?"); |
|
118 |
pae.printStackTrace(); |
|
119 |
} |
|
120 |
} catch (SecurityException se) { |
|
121 |
// good! test succeeded |
|
122 |
System.out.println("PrincipalExpansionError test succeeded"); |
|
123 |
se.printStackTrace(); |
|
124 |
} |
|
125 |
} |
|
126 |
} |