blob: 75ba21e3d44a795f7664cd436cb3d8ec3e02cd14 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2002-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any 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=java.policy SetLogPermission
31 */
32
33import java.rmi.server.RemoteServer;
34import java.io.ByteArrayOutputStream;
35import java.net.URL;
36import java.security.*;
37import java.security.cert.Certificate;
38
39public 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}