0N/A/*
2362N/A * Copyright (c) 1999, 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 * @author Gary Ellison
0N/A * @bug 4232694
0N/A * @summary PermissionCollection.setReadOnly() does not preclude using add()
0N/A */
0N/A
0N/Aimport java.security.*;
0N/Aimport java.net.SocketPermission;
0N/Aimport java.io.FilePermission;
0N/Aimport java.util.PropertyPermission;
0N/A
0N/Apublic class AddToReadOnlyPermissionCollection {
0N/A public static void main(String args[]) throws Exception {
0N/A
0N/A try {
0N/A if (args.length == 0) {
0N/A tryAllPC();
0N/A tryBasicPC();
0N/A tryFilePC();
0N/A tryPropPC();
0N/A trySockPC();
0N/A } else {
0N/A for (int i=0; i <args.length; i++) {
0N/A switch (args[i].toLowerCase().charAt(1)) {
0N/A case 'a':
0N/A tryAllPC();
0N/A break;
0N/A case 'b':
0N/A tryBasicPC();
0N/A break;
0N/A case 'f':
0N/A tryFilePC();
0N/A break;
0N/A case 'p':
0N/A tryPropPC();
0N/A break;
0N/A case 's':
0N/A trySockPC();
0N/A break;
0N/A default:
0N/A throw new Exception("usage: AddToReadOnlyPermissonCollection [-a -b -f -p -s]");
0N/A }
0N/A }
0N/A }
0N/A } catch (Exception e) {
0N/A throw e;
0N/A }
0N/A System.out.println("Passed. OKAY");
0N/A }
0N/A
0N/A static void tryPropPC() throws Exception {
0N/A try {
0N/A PropertyPermission p0 = new PropertyPermission("user.home","read");
0N/A PermissionCollection pc = p0.newPermissionCollection();
0N/A pc.setReadOnly(); // this should lock out future adds
0N/A //
0N/A PropertyPermission p1 = new PropertyPermission("java.home","read");
0N/A pc.add(p1);
0N/A throw new
0N/A Exception("Failed...PropertyPermission added to readonly PropertyPermissionCollection.");
0N/A
0N/A } catch (SecurityException se) {
0N/A System.out.println("PropertyPermissionCollection passed");
0N/A }
0N/A }
0N/A
0N/A static void trySockPC() throws Exception {
0N/A try {
0N/A SocketPermission p0= new SocketPermission("example.com","connect");
0N/A PermissionCollection pc = p0.newPermissionCollection();
0N/A pc.setReadOnly(); // this should lock out future adds
0N/A //
0N/A SocketPermission p1= new SocketPermission("example.net","connect");
0N/A pc.add(p1);
0N/A throw new
0N/A Exception("Failed...SocketPermission added to readonly SocketPermissionCollection.");
0N/A
0N/A } catch (SecurityException se) {
0N/A System.out.println("SocketPermissionCollection passed");
0N/A }
0N/A
0N/A }
0N/A
0N/A static void tryFilePC() throws Exception {
0N/A try {
0N/A FilePermission p0 = new FilePermission("/home/foobar","read");
0N/A PermissionCollection pc = p0.newPermissionCollection();
0N/A pc.setReadOnly(); // this should lock out future adds
0N/A //
0N/A FilePermission p1 = new FilePermission("/home/quux","read");
0N/A pc.add(p1);
0N/A throw new
0N/A Exception("Failed...FilePermission added to readonly FilePermissionCollection.");
0N/A
0N/A } catch (SecurityException se) {
0N/A System.out.println("FilePermissionCollection passed");
0N/A }
0N/A }
0N/A
0N/A static void tryBasicPC() throws Exception {
0N/A try {
0N/A MyBasicPermission p0 = new MyBasicPermission("BasicPermision");
0N/A PermissionCollection pc = p0.newPermissionCollection();
0N/A pc.setReadOnly(); // this should lock out future adds
0N/A //
0N/A MyBasicPermission p1 = new MyBasicPermission("EvenMoreBasic");
0N/A pc.add(p1);
0N/A throw new
0N/A Exception("Failed...BasicPermission added to readonly BasicPermissionCollection.");
0N/A
0N/A } catch (SecurityException se) {
0N/A System.out.println("BasicPermissionCollection passed");
0N/A }
0N/A }
0N/A
0N/A static void tryAllPC() throws Exception {
0N/A try {
0N/A AllPermission p0 = new AllPermission("AllOfIt","read");
0N/A PermissionCollection pc = p0.newPermissionCollection();
0N/A pc.setReadOnly(); // this should lock out future adds
0N/A //
0N/A AllPermission p1 = new AllPermission("SomeOfIt","read");
0N/A pc.add(p1);
0N/A throw new
0N/A Exception("Failed...AllPermission added to readonly AllPermissionCollection.");
0N/A
0N/A } catch (SecurityException se) {
0N/A System.out.println("AllPermissionCollection passed");
0N/A }
0N/A }
0N/A
0N/A}
0N/A
0N/Aclass MyBasicPermission extends BasicPermission {
0N/A public MyBasicPermission(String name) {
0N/A super(name);
0N/A }
0N/A}