1 /* 2 * Copyright (c) 2002, 2016, 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 /* 25 * @test 26 * @bug 4510355 27 * @key intermittent 28 * @summary ActivationGroup implementations cannot be downloaded by default; 29 * Creates a custom activation group without setting a security manager 30 * in activation group's descriptor. The custom activation group 31 * implementation should be downloaded when first object within that group 32 * is activated. 33 * @author Ann Wollrath 34 * 35 * @library ../../../testlibrary 36 * @modules java.rmi/sun.rmi.registry 37 * java.rmi/sun.rmi.server 38 * java.rmi/sun.rmi.transport 39 * java.rmi/sun.rmi.transport.tcp 40 * @build TestLibrary RMID ActivationLibrary 41 * DownloadActivationGroup MyActivationGroupImpl DownloadActivationGroup_Stub 42 * @run main/othervm/policy=security.policy/timeout=240 DownloadActivationGroup 43 */ 44 45 import java.net.URL; 46 import java.rmi.MarshalledObject; 47 import java.rmi.Remote; 48 import java.rmi.RemoteException; 49 import java.rmi.activation.Activatable; 50 import java.rmi.activation.ActivationDesc; 51 import java.rmi.activation.ActivationException; 52 import java.rmi.activation.ActivationGroup; 53 import java.rmi.activation.ActivationGroupDesc; 54 import java.rmi.activation.ActivationGroupDesc.CommandEnvironment; 55 import java.rmi.activation.ActivationGroupID; 56 import java.rmi.activation.ActivationID; 57 import java.rmi.server.UnicastRemoteObject; 58 import java.util.Properties; 59 60 public class DownloadActivationGroup 61 implements Ping, Runnable 62 { 63 64 private ActivationID id; 65 66 public DownloadActivationGroup(ActivationID id, MarshalledObject mobj) 67 throws ActivationException, RemoteException 68 { 69 this.id = id; 70 Activatable.exportObject(this, id, 0); 71 System.err.println("object activated in group"); 72 } 73 74 public DownloadActivationGroup() throws RemoteException { 75 UnicastRemoteObject.exportObject(this, 0); 76 } 77 78 /** 79 * Used to activate object. 80 */ 81 public void ping() { 82 System.err.println("received ping"); 83 } 84 85 /** 86 * Spawns a thread to deactivate the object (and thus, shuts down the 87 * activation group). 88 */ 89 public void shutdown() throws Exception 90 { 91 (new Thread(this,"DownloadActivationGroup")).start(); 92 } 93 94 /** 95 * Thread to deactivate object. 96 */ 97 public void run() { 98 ActivationLibrary.deactivate(this, getID()); 99 } 100 101 public ActivationID getID() { 102 return id; 103 } 104 105 106 public static void main(String[] args) { 107 108 RMID rmid = null; 109 110 System.out.println("\nRegression test for bug 4510355\n"); 111 112 try { 113 TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); 114 115 /* 116 * Install group class file in codebase. 117 */ 118 System.err.println("install class file in codebase"); 119 URL groupURL = TestLibrary.installClassInCodebase( 120 "MyActivationGroupImpl", "group"); 121 System.err.println("class file installed"); 122 123 /* 124 * Start rmid. 125 */ 126 RMID.removeLog(); 127 rmid = RMID.createRMID(); 128 String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none"; 129 rmid.addOptions(new String[] { execPolicyOption }); 130 rmid.start(); 131 132 /* 133 * Create and register descriptors for custom group and an 134 * activatable object in that group. 135 */ 136 System.err.println("register group"); 137 138 Properties p = new Properties(); 139 p.put("java.security.policy", TestParams.defaultGroupPolicy); 140 CommandEnvironment cmd = new ActivationGroupDesc.CommandEnvironment( 141 null, 142 new String[] { 143 "-XaddExports:java.rmi/sun.rmi.registry=ALL-UNNAMED", 144 "-XaddExports:java.rmi/sun.rmi.server=ALL-UNNAMED", 145 "-XaddExports:java.rmi/sun.rmi.transport=ALL-UNNAMED", 146 "-XaddExports:java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED" }); 147 148 ActivationGroupDesc groupDesc = 149 new ActivationGroupDesc("MyActivationGroupImpl", 150 groupURL.toExternalForm(), 151 null, p, cmd); 152 ActivationGroupID groupID = 153 ActivationGroup.getSystem().registerGroup(groupDesc); 154 155 156 System.err.println("register activatable object"); 157 ActivationDesc desc = 158 new ActivationDesc(groupID, "DownloadActivationGroup", 159 null, null); 160 Ping obj = (Ping) Activatable.register(desc); 161 162 /* 163 * Start group (by calling ping). 164 */ 165 System.err.println( 166 "ping object (forces download of group's class)"); 167 obj.ping(); 168 System.err.println( 169 "TEST PASSED: group's class downloaded successfully"); 170 System.err.println("shutdown object"); 171 obj.shutdown(); 172 System.err.println("TEST PASSED"); 173 174 } catch (Exception e) { 175 TestLibrary.bomb(e); 176 } finally { 177 rmid.cleanup(); 178 } 179 } 180 } 181 182 interface Ping extends Remote { 183 public void ping() throws RemoteException; 184 public void shutdown() throws Exception; 185 }