author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 32834 | jdk/test/java/security/ProtectionDomain/PreserveCombinerTest.java@e1dca5fe4de3 |
child 52427 | 3c6aa484536c |
permissions | -rw-r--r-- |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
1 |
/* |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
4 |
* |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
8 |
* |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
13 |
* accompanied this code). |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
14 |
* |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
18 |
* |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
21 |
* questions. |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
22 |
*/ |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
23 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
24 |
import java.security.AccessControlContext; |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
25 |
import java.security.AccessController; |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
26 |
import java.security.DomainCombiner; |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
27 |
import java.security.PrivilegedAction; |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
28 |
import java.security.ProtectionDomain; |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30820
diff
changeset
|
29 |
import jdk.internal.misc.SharedSecrets; |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
30 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
31 |
/* |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
32 |
* @test |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
33 |
* @bug 8064331 |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
34 |
* @summary Make sure that JavaSecurityAccess.doIntersectionPrivilege() |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
35 |
* is not dropping the information about the domain combiner of |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
36 |
* the stack ACC |
32834
e1dca5fe4de3
8137056: Move SharedSecrets and interface friends out of sun.misc
chegar
parents:
30820
diff
changeset
|
37 |
* @modules java.base/jdk.internal.misc |
29027
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
38 |
*/ |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
39 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
40 |
public class PreserveCombinerTest { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
41 |
public static void main(String[]args) throws Exception { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
42 |
final DomainCombiner dc = new DomainCombiner() { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
43 |
@Override |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
44 |
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
45 |
return currentDomains; // basically a no-op |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
46 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
47 |
}; |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
48 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
49 |
// Get an instance of the saved ACC |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
50 |
AccessControlContext saved = AccessController.getContext(); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
51 |
// Simulate the stack ACC with a DomainCombiner attached |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
52 |
AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
53 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
54 |
// Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
55 |
// whether the DomainCombiner from the stack ACC is preserved |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
56 |
boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
57 |
@Override |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
58 |
public Boolean run() { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
59 |
return dc == AccessController.getContext().getDomainCombiner(); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
60 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
61 |
}, stack, saved); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
62 |
|
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
63 |
if (!ret) { |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
64 |
System.exit(1); |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
65 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
66 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
67 |
} |
2df5737b2c8a
8064331: JavaSecurityAccess.doIntersectionPrivilege() drops the information about the domain combiner of the stack ACC
jbachorik
parents:
diff
changeset
|
68 |