< prev index next >

test/jdk/java/security/ProtectionDomain/PreserveCombinerTest.java

Print this page




   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  *
  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.
  22  */
  23 
  24 import java.security.AccessControlContext;
  25 import java.security.AccessController;
  26 import java.security.DomainCombiner;
  27 import java.security.PrivilegedAction;
  28 import java.security.ProtectionDomain;
  29 import jdk.internal.misc.SharedSecrets;
  30 
  31 /*
  32  * @test
  33  * @bug 8064331
  34  * @summary Make sure that JavaSecurityAccess.doIntersectionPrivilege()
  35  *          is not dropping the information about the domain combiner of
  36  *          the stack ACC
  37  * @modules java.base/jdk.internal.misc
  38  */
  39 
  40 public class PreserveCombinerTest {
  41     public static void main(String[]args) throws Exception {
  42         final DomainCombiner dc = new DomainCombiner() {
  43             @Override
  44             public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
  45                 return currentDomains; // basically a no-op
  46             }
  47         };
  48 
  49         // Get an instance of the saved ACC
  50         AccessControlContext saved = AccessController.getContext();
  51         // Simulate the stack ACC with a DomainCombiner attached
  52         AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc);
  53 
  54         // Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert
  55         // whether the DomainCombiner from the stack ACC is preserved
  56         boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() {
  57             @Override


   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  *
  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.
  22  */
  23 
  24 import java.security.AccessControlContext;
  25 import java.security.AccessController;
  26 import java.security.DomainCombiner;
  27 import java.security.PrivilegedAction;
  28 import java.security.ProtectionDomain;
  29 import jdk.internal.access.SharedSecrets;
  30 
  31 /*
  32  * @test
  33  * @bug 8064331
  34  * @summary Make sure that JavaSecurityAccess.doIntersectionPrivilege()
  35  *          is not dropping the information about the domain combiner of
  36  *          the stack ACC
  37  * @modules java.base/jdk.internal.access
  38  */
  39 
  40 public class PreserveCombinerTest {
  41     public static void main(String[]args) throws Exception {
  42         final DomainCombiner dc = new DomainCombiner() {
  43             @Override
  44             public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
  45                 return currentDomains; // basically a no-op
  46             }
  47         };
  48 
  49         // Get an instance of the saved ACC
  50         AccessControlContext saved = AccessController.getContext();
  51         // Simulate the stack ACC with a DomainCombiner attached
  52         AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc);
  53 
  54         // Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert
  55         // whether the DomainCombiner from the stack ACC is preserved
  56         boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() {
  57             @Override
< prev index next >