1 /* 2 * Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved. 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 * 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 /* @test 25 * @bug 4533390 26 * @summary SecurityException can be obtained but is not specified. 27 * The RemoteServer.setLog method requires 28 * java.util.log.LoggingPermission("control"). 29 * @author Ann Wollrath 30 * @run main/othervm/policy=security.policy SetLogPermission 31 */ 32 33 import java.rmi.server.RemoteServer; 34 import java.io.ByteArrayOutputStream; 35 import java.net.URL; 36 import java.security.*; 37 import java.security.cert.Certificate; 38 39 public class SetLogPermission { 40 41 public static void main(String[] args) throws Exception { 42 43 System.err.println("\nRegression test for bug 4533390\n"); 44 45 if (System.getSecurityManager() == null) { 46 System.setSecurityManager(new SecurityManager()); 47 } 48 49 CodeSource codesource = new CodeSource(null, (Certificate[]) null); 50 Permissions perms = null; 51 ProtectionDomain pd = new ProtectionDomain(codesource, perms); 52 AccessControlContext acc = 53 new AccessControlContext(new ProtectionDomain[] { pd }); 54 55 java.security.AccessController.doPrivileged( 56 new java.security.PrivilegedAction() { 57 public Object run() { 58 try { 59 System.err.println( 60 "Attempt to set log without permission"); 61 RemoteServer.setLog(new ByteArrayOutputStream()); 62 throw new RuntimeException( 63 "TEST FAILED: set log without permission"); 64 } catch (SecurityException e) { 65 System.err.println( 66 "TEST PASSED: unable to set log without permission"); 67 } 68 return null; 69 }}, acc); 70 71 try { 72 System.err.println("Attempt to set log with permission"); 73 RemoteServer.setLog(new ByteArrayOutputStream()); 74 System.err.println( 75 "TEST PASSED: sufficient permission to set log"); 76 } catch (SecurityException e) { 77 System.err.println("TEST FAILED: unable to set log"); 78 throw e; 79 } 80 } 81 }