Path: blob/master/test/jdk/java/security/BasicPermission/Homogeneity.java
41149 views
/*1* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 429161026* @summary BasicPermission.newPermissionCollection collection does not27* enforce homogeneity28*/2930import java.security.BasicPermission;3132public class Homogeneity {3334public static void main(String[] args) {3536java.lang.RuntimePermission rp = new java.lang.RuntimePermission37("*");38java.lang.RuntimePermission rp2 = new java.lang.RuntimePermission39("exitVM");40java.net.NetPermission np = new java.net.NetPermission41("setDefaultAuthenticator");4243// should be able to add identical BasicPermission subclasses to the44// same collection45java.security.PermissionCollection perms = rp.newPermissionCollection();46try {47perms.add(rp);48perms.add(rp2);49} catch (IllegalArgumentException iae) {50throw new SecurityException("GOOD ADD TEST FAILED");51}5253// make sure you can't add different BasicPermission subclasses54// to the same collection55try {56// this should fail57perms.add(np);58throw new SecurityException("BAD ADD TEST FAILED");59} catch (IllegalArgumentException iae) {60// good61}6263// make sure a BasicPermissionCollection doesn't imply64// random BasicPermission subclasses65if (perms.implies(np)) {66throw new SecurityException("IMPLIES TEST FAILED");67}68}69}707172