示例#1
0
  public static void main(String[] args) {

    RMID rmid = null;

    System.out.println("\nRegression test for bug 4510355\n");

    try {
      TestLibrary.suggestSecurityManager("java.lang.SecurityManager");

      /*
       * Install group class file in codebase.
       */
      System.err.println("install class file in codebase");
      URL groupURL = TestLibrary.installClassInCodebase("MyActivationGroupImpl", "group");
      System.err.println("class file installed");

      /*
       * Start rmid.
       */
      RMID.removeLog();
      rmid = RMID.createRMID();
      String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none";
      rmid.addOptions(new String[] {execPolicyOption});
      rmid.start();

      /*
       * Create and register descriptors for custom group and an
       * activatable object in that group.
       */
      System.err.println("register group");

      Properties p = new Properties();
      p.put("java.security.policy", TestParams.defaultGroupPolicy);

      ActivationGroupDesc groupDesc =
          new ActivationGroupDesc(
              "MyActivationGroupImpl", groupURL.toExternalForm(), null, p, null);
      ActivationGroupID groupID = ActivationGroup.getSystem().registerGroup(groupDesc);

      System.err.println("register activatable object");
      ActivationDesc desc = new ActivationDesc(groupID, "DownloadActivationGroup", null, null);
      Ping obj = (Ping) Activatable.register(desc);

      /*
       * Start group (by calling ping).
       */
      System.err.println("ping object (forces download of group's class)");
      obj.ping();
      System.err.println("TEST PASSED: group's class downloaded successfully");
      System.err.println("shutdown object");
      obj.shutdown();
      System.err.println("TEST PASSED");

    } catch (Exception e) {
      TestLibrary.bomb(e);
    } finally {
      rmid.cleanup();
    }
  }
示例#2
0
  /**
   * Registers an activation descriptor (with the specified location, data, and restart mode) for
   * the specified object, and exports that object with the specified port, and the specified client
   * and server socket factories.
   *
   * <p><strong>Note:</strong> Using this method (as well as the <code>Activatable</code>
   * constructors that both register and export an activatable remote object) is strongly
   * discouraged because the actions of registering and exporting the remote object are <i>not</i>
   * guaranteed to be atomic. Instead, an application should register an activation descriptor and
   * export a remote object separately, so that exceptions can be handled properly.
   *
   * <p>This method first registers an activation descriptor for the specified object as follows. It
   * obtains the activation system by invoking the method {@link ActivationGroup#getSystem
   * ActivationGroup.getSystem}. This method then obtains an {@link ActivationID} for the object by
   * invoking the activation system's {@link ActivationSystem#registerObject registerObject} method
   * with an {@link ActivationDesc} constructed with the specified object's class name, and the
   * specified location, data, and restart mode. If an exception occurs obtaining the activation
   * system or registering the activation descriptor, that exception is thrown to the caller.
   *
   * <p>Next, this method exports the object by invoking the {@link
   * #exportObject(Remote,ActivationID,int,RMIClientSocketFactory,RMIServerSocketFactory)
   * exportObject} method with the specified remote object, the activation identifier obtained from
   * registration, the specified port, and the specified client and server socket factories. If an
   * exception occurs exporting the object, this method attempts to unregister the activation
   * identifier (obtained from registration) by invoking the activation system's {@link
   * ActivationSystem#unregisterObject unregisterObject} method with the activation identifier. If
   * an exception occurs unregistering the identifier, that exception is ignored, and the original
   * exception that occurred exporting the object is thrown to the caller.
   *
   * <p>Finally, this method invokes the {@link ActivationGroup#activeObject activeObject} method on
   * the activation group in this VM with the activation identifier and the specified remote object,
   * and returns the activation identifier to the caller.
   *
   * @param obj the object being exported
   * @param location the object's code location
   * @param data the object's bootstrapping data
   * @param restart if true, the object is restarted (reactivated) when either the activator is
   *     restarted or the object's activation group is restarted after an unexpected crash; if
   *     false, the object is only activated on demand. Specifying <code>restart</code> to be <code>
   *     true</code> does not force an initial immediate activation of a newly registered object;
   *     initial activation is lazy.
   * @param port the port on which the object is exported (an anonymous port is used if port=0)
   * @param csf the client-side socket factory for making calls to the remote object
   * @param ssf the server-side socket factory for receiving remote calls
   * @return the activation identifier obtained from registering the descriptor with the activation
   *     system
   * @exception ActivationException if activation group is not active
   * @exception RemoteException if object registration or export fails
   * @exception UnsupportedOperationException if and only if activation is not supported by this
   *     implementation
   * @since 1.2
   */
  public static ActivationID exportObject(
      Remote obj,
      String location,
      MarshalledObject<?> data,
      boolean restart,
      int port,
      RMIClientSocketFactory csf,
      RMIServerSocketFactory ssf)
      throws ActivationException, RemoteException {
    ActivationDesc desc = new ActivationDesc(obj.getClass().getName(), location, data, restart);
    /*
     * Register descriptor.
     */
    ActivationSystem system = ActivationGroup.getSystem();
    ActivationID id = system.registerObject(desc);

    /*
     * Export object.
     */
    try {
      exportObject(obj, id, port, csf, ssf);
    } catch (RemoteException e) {
      /*
       * Attempt to unregister activation descriptor because export
       * failed and register/export should be atomic (see 4323621).
       */
      try {
        system.unregisterObject(id);
      } catch (Exception ex) {
      }
      /*
       * Report original exception.
       */
      throw e;
    }

    /*
     * This call can't fail (it is a local call, and the only possible
     * exception, thrown if the group is inactive, will not be thrown
     * because the group is not inactive).
     */
    ActivationGroup.currentGroup().activeObject(id, obj);

    return id;
  }
  public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6261402\n");
    System.setProperty(
        "java.rmi.activation.port",
        Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;
    try {
      /*
       * Export callback object and bind in registry.
       */
      System.err.println("export callback object and bind in registry");
      obj = new CallbackImpl();
      Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0);
      Registry registry =
          LocateRegistry.createRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
      registry.bind("Callback", proxy);

      /*
       * Start rmid.
       */
      System.err.println("start rmid with inherited channel");
      RMID.removeLog();
      rmid =
          RMID.createRMID(
              System.out,
              System.err,
              true,
              true,
              TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
      rmid.addOptions(
          new String[] {
            "-Djava.nio.channels.spi.SelectorProvider=" + "InheritedChannelNotServerSocket$SP"
          });
      rmid.start();

      /*
       * Get activation system and wait to be notified via callback
       * from rmid's selector provider.
       */
      System.err.println("get activation system");
      ActivationSystem system = ActivationGroup.getSystem();
      System.err.println("ActivationSystem = " + system);
      synchronized (lock) {
        while (!notified) {
          lock.wait();
        }
      }
      System.err.println("TEST PASSED");
    } finally {
      if (obj != null) {
        UnicastRemoteObject.unexportObject(obj, true);
      }
      ActivationLibrary.rmidCleanup(rmid);
    }
  }
  /**
   * Create the new instance of the activation group, using the class name and location information,
   * stored in the passed descriptor. The method expects the group class to have the two parameter
   * constructor, the first parameter being the {@link ActivationGroupID} and the second the {@link
   * MarshalledObject}. The group must be first be registered with the ActivationSystem. Once a
   * group is created, the currentGroupID method returns the identifier for this group until the
   * group becomes inactive.
   *
   * @param id the activation group id
   * @param desc the group descriptor, providing the information, necessary to create the group
   * @param incarnation the incarnation number
   * @return the created group instance
   * @throws ActivationException if the activation fails due any reason
   */
  public static ActivationGroup createGroup(
      ActivationGroupID id, ActivationGroupDesc desc, long incarnation) throws ActivationException {
    // If the activation system is not yet set, set it to the system.
    // passed in the group id.
    if (system == null) system = id.system;

    ActivationGroup group = null;

    // TODO at the moment all groups are created on the current jre and the
    // group class must be reachable via thread context class loader.
    Class groupClass;

    if (desc.className != null) {
      try {
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        groupClass = loader.loadClass(desc.className);
      } catch (ClassNotFoundException e) {
        ActivationException acex = new ActivationException("Cannot load " + desc.className);
        acex.detail = e;
        throw acex;
      }
    } else groupClass = DefaultActivationGroup.class;

    try {
      Constructor constructor = groupClass.getConstructor(cConstructorTypes);
      group = (ActivationGroup) constructor.newInstance(new Object[] {id, desc.data});
    } catch (Exception e) {
      ActivationException acex = new ActivationException("Cannot instantiate " + desc.className);
      acex.detail = e;
      throw acex;
    }

    currentGroupId = id;
    try {
      group.monitor = getSystem().activeGroup(id, group, incarnation);
      return group;
    } catch (RemoteException e) {
      ActivationException acex = new ActivationException("createGroup");
      acex.detail = e;
      throw acex;
    }
  }
示例#5
0
 public static void main(String args[]) {
   // INIZIALIZZAZIONI
   String policyGroup = System.getProperty("servers.policy");
   String implCodebase = System.getProperty("servers.impl.codebase");
   String classeserver = System.getProperty("servers.classeserver");
   String trustStore = System.getProperty("javax.net.ssl.trustStore");
   String trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
   String keyStore = System.getProperty("javax.net.ssl.keyStore");
   String keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
   // LANCIO IL SECURITY MANAGER
   System.setSecurityManager(new RMISecurityManager());
   try {
     Properties prop = new Properties();
     prop.put("java.security.policy", policyGroup);
     prop.put("servers.impl.codebase", implCodebase);
     prop.put("java.class.path", "no_classpath");
     prop.put("javax.net.ssl.trustStore", trustStore);
     prop.put("javax.net.ssl.trustStorePassword", trustStorePassword);
     prop.put("javax.net.ssl.keyStore", keyStore);
     prop.put("javax.net.ssl.keyStorePassword", keyStorePassword);
     // FASE 1: CREAZIONE DEL GRUPPO DI ATTIVAZIONE
     ActivationGroupDesc groupDesc = new ActivationGroupDesc(prop, null);
     // FASE 2: REGISTRAZIONE DEL GRUPPO DI ATTIVAZIONE
     ActivationGroupID groupID = ActivationGroup.getSystem().registerGroup(groupDesc);
     System.out.println(
         "Il gruppo e' stato creato,  registrato col sistema d'attivazione, ed ha identificativo = "
             + groupID);
     // FASE 3: CREAZIONE DELL'ACTIVATION DESCRIPTOR ASSOCIATO AL SERVER
     ActivationDesc actDesc = new ActivationDesc(groupID, classeserver, implCodebase, null);
     // FASE 4: REGISTRAZIONE DEL SERVER ATTIVABILE COL SISTEMA
     // D'ATTIVAZIONE
     IGame stub_server = (IGame) Activatable.register(actDesc);
     System.out.println(
         "E' stato creato l'activation descriptor del server che e' stato registrato col demone d'attivazione");
     System.out.println(
         "Il server attivabile che adesso puo' essere acceduto attraverso lo stub: "
             + stub_server);
     System.out.println("Notate come la RemoteRef dello stub sia a null");
     // FASE 5: BINDING DEL SERVER ATTIVABILE SUL REGISTRO RMI
     System.out.println(
         "Faccio il binding dello stub del server attivabile nel registro RMI alla porta 1098 dove gia' si trova registrato il sistema di attivazione ");
     InetAddress ip = InetAddress.getLocalHost();
     String ipp = ip.getHostAddress().toString();
     // String ipp = "157.27.184.217";
     // Registry registry = LocateRegistry.createRegistry(5552, new SslRMIClientSocketFactory(),
     // new SslRMIServerSocketFactory(null, null, true));
     Registry registry =
         LocateRegistry.getRegistry("localhost", 5552, new SslRMIClientSocketFactory());
     registry.rebind("//" + ipp + ":5552/GameServer", (Remote) stub_server);
     // Thread.sleep(10000);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
示例#6
0
  public static void main(String[] args) {

    try {
      Properties props = new Properties();
      props.setProperty("java.security.policy", POLICY_FILE);

      ActivationGroupDesc agd = new ActivationGroupDesc(props, null);

      ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(agd);

      ACTIVATION_DESC = new ActivationDesc(agid, CLASS_NAME, CODE_LOCATION, DATA, false);
    } catch (Exception e) {
      System.err.println("Exception: " + e);
      e.printStackTrace();
    }

    setup();
  }
示例#7
0
  public static void main(String[] args) {
    System.setSecurityManager(new RMISecurityManager());

    Properties prop = new Properties();
    prop.put("java.security.policy", "java.policy");
    ActivationGroupDesc grp = new ActivationGroupDesc(prop, null);

    try {
      ActivationGroupID agid = ActivationGroup.getSystem().registerGroup(grp);
      ActivationDesc desc = new ActivationDesc(agid, "ActiveEchoServer", args[0], null);

      Echo server = (Echo) Activatable.register(desc);
      System.out.println("Stworzona instancja stub serwera");
      Naming.rebind(args[1], server);
      System.out.println("Setup: zarejestrowalem stub servera");
    } catch (Exception e) {
      System.err.println("Setup wyjatek: " + e.getMessage());
      e.printStackTrace();
    }
    System.exit(0);
  }
示例#8
0
 /** Main program to start a VM for an activation group. */
 public static void main(String args[]) {
   try {
     if (System.getSecurityManager() == null) {
       System.setSecurityManager(new SecurityManager());
     }
     MarshalInputStream in =
         new MarshalInputStream(
             System.in,
             ActivationGroupInit.class.getClassLoader(),
             false,
             null,
             Collections.EMPTY_LIST);
     in.useCodebaseAnnotations();
     ActivationGroupID id = (ActivationGroupID) in.readObject();
     ActivationGroupDesc desc = (ActivationGroupDesc) in.readObject();
     long incarnation = in.readLong();
     Class cl = RMIClassLoader.loadClass(desc.getLocation(), desc.getClassName());
     try {
       Method create =
           cl.getMethod(
               "createGroup",
               new Class[] {ActivationGroupID.class, ActivationGroupDesc.class, long.class});
       create.invoke(null, new Object[] {id, desc, new Long(incarnation)});
     } catch (NoSuchMethodException e) {
       ActivationGroup.createGroup(id, desc, incarnation);
     }
   } catch (Exception e) {
     System.err.println("Exception in starting ActivationGroupInit:");
     e.printStackTrace();
   } finally {
     try {
       System.in.close();
       // note: system out/err shouldn't be closed
       // since the parent may want to read them.
     } catch (Exception ex) {
       // ignore exceptions
     }
   }
 }
示例#9
0
 /**
  * Revokes previous registration for the activation descriptor associated with <code>id</code>. An
  * object can no longer be activated via that <code>id</code>.
  *
  * @param id the object's activation identifier
  * @exception UnknownObjectException if object (<code>id</code>) is unknown
  * @exception ActivationException if activation system is not running
  * @exception RemoteException if remote call to activation system fails
  * @exception UnsupportedOperationException if and only if activation is not supported by this
  *     implementation
  * @since 1.2
  */
 public static void unregister(ActivationID id)
     throws UnknownObjectException, ActivationException, RemoteException {
   ActivationGroup.getSystem().unregisterObject(id);
 }
示例#10
0
 /**
  * Informs the system that the object with the corresponding activation <code>id</code> is
  * currently inactive. If the object is currently active, the object is "unexported" from the RMI
  * runtime (only if there are no pending or in-progress calls) so the that it can no longer
  * receive incoming calls. This call informs this VM's ActivationGroup that the object is
  * inactive, that, in turn, informs its ActivationMonitor. If this call completes successfully, a
  * subsequent activate request to the activator will cause the object to reactivate. The operation
  * may still succeed if the object is considered active but has already unexported itself.
  *
  * @param id the object's activation identifier
  * @return true if the operation succeeds (the operation will succeed if the object in currently
  *     known to be active and is either already unexported or is currently exported and has no
  *     pending/executing calls); false is returned if the object has pending/executing calls in
  *     which case it cannot be deactivated
  * @exception UnknownObjectException if object is not known (it may already be inactive)
  * @exception ActivationException if group is not active
  * @exception RemoteException if call informing monitor fails
  * @exception UnsupportedOperationException if and only if activation is not supported by this
  *     implementation
  * @since 1.2
  */
 public static boolean inactive(ActivationID id)
     throws UnknownObjectException, ActivationException, RemoteException {
   return ActivationGroup.currentGroup().inactiveObject(id);
 }
示例#11
0
 /**
  * Register an object descriptor for an activatable remote object so that is can be activated on
  * demand.
  *
  * @param desc the object's descriptor
  * @return the stub for the activatable remote object
  * @exception UnknownGroupException if group id in <code>desc</code> is not registered with the
  *     activation system
  * @exception ActivationException if activation system is not running
  * @exception RemoteException if remote call fails
  * @exception UnsupportedOperationException if and only if activation is not supported by this
  *     implementation
  * @since 1.2
  */
 public static Remote register(ActivationDesc desc)
     throws UnknownGroupException, ActivationException, RemoteException {
   // register object with activator.
   ActivationID id = ActivationGroup.getSystem().registerObject(desc);
   return sun.rmi.server.ActivatableRef.getStub(desc, id);
 }
  public static void main(String[] args) {

    System.out.println("\nRegression test for bug 4095165, 4140736\n");

    TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");

    RMID rmid = null;
    RestartCrashedService unicastObj = null;

    try {
      RMID.removeLog();
      rmid = RMID.createRMID();
      rmid.start();

      /* Cause activation groups to have a security policy that will
       * allow security managers to be downloaded and installed
       */
      final Properties p = new Properties();
      // this test must always set policies/managers in its
      // activation groups
      p.put("java.security.policy", TestParams.defaultGroupPolicy);
      p.put("java.security.manager", TestParams.defaultSecurityManager);

      /*
       * Create unicast object to be contacted when service is activated.
       */
      unicastObj = new RestartCrashedService();
      /*
       * Create and register descriptors for a restartable and
       * non-restartable service (respectively) in a group other than
       * this VM's group.
       */
      System.err.println("Creating descriptors");

      Object[] stuff = new Object[] {RESTARTABLE, unicastObj};
      MarshalledObject restartMobj = new MarshalledObject(stuff);
      ActivationGroupDesc groupDesc = new ActivationGroupDesc(p, null);

      stuff[0] = ACTIVATABLE;
      MarshalledObject activateMobj = new MarshalledObject(stuff);
      ActivationGroupID groupID = ActivationGroup.getSystem().registerGroup(groupDesc);
      ActivationDesc restartableDesc =
          new ActivationDesc(groupID, "RestartCrashedService", null, restartMobj, true);

      ActivationDesc activatableDesc =
          new ActivationDesc(groupID, "RestartCrashedService", null, activateMobj, false);

      System.err.println("Registering descriptors");
      ActivateMe restartableObj = (ActivateMe) Activatable.register(restartableDesc);

      ActivateMe activatableObj = (ActivateMe) Activatable.register(activatableDesc);

      /*
       * Restart rmid; it should start up the restartable service
       */
      rmid.restart();

      /*
       * Wait for service to be automatically restarted.
       */
      int repeat = 1;

      do {

        for (int i = 0; i < 15; i++) {
          synchronized (lock) {
            if (unicastObj.receivedPing(RESTARTABLE) != true) {
              lock.wait(5000);
              if (unicastObj.receivedPing(RESTARTABLE) == true) {
                System.err.println("Test1 passed: rmid " + "restarted service");
                break;
              }
            } else {
              break;
            }
          }
        }

        if (unicastObj.receivedPing(RESTARTABLE) != true)
          TestLibrary.bomb("Test1 failed: service not restarted by timeout", null);

        /*
         * Make sure activatable services wasn't automatically
         * restarted.
         */
        synchronized (lock) {
          if (unicastObj.receivedPing(ACTIVATABLE) != true) {
            lock.wait(5000);
            if (unicastObj.receivedPing(ACTIVATABLE) != true) {
              System.err.println("Test2 passed: rmid did not " + "restart activatable service");
            } else {
              TestLibrary.bomb("Test2 failed: activatable service restarted", null);
            }
          } else {
            TestLibrary.bomb("Test2 failed: activatable service restarted!", null);
          }
        }

        if (repeat > 0) {
          try {
            System.err.println("\nCrash restartable object");
            unicastObj.resetResponders();
            restartableObj.crash();
          } catch (Exception e) {
          }
        }

      } while (repeat-- > 0);

    } catch (Exception e) {
      TestLibrary.bomb("test failed", e);
    } finally {
      ActivationLibrary.rmidCleanup(rmid);
      TestLibrary.unexport(unicastObj);
    }
  }
  public static void main(String args[]) {
    /*
     * The following line is required with the JDK 1.2 VM so that the
     * VM can exit gracefully when this test completes.  Otherwise, the
     * conservative garbage collector will find a handle to the server
     * object on the native stack and not clear the weak reference to
     * it in the RMI runtime's object table.
     */
    Object dummy1 = new Object();
    RMID rmid = null;

    System.err.println("\nRegression test for bug/rfe 4109103\n");

    try {

      // Set security manager according to the
      // testlibrary.
      TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);

      // start an rmid.
      RMID.removeLog();
      rmid = RMID.createRMID(rmidOut, rmidErr, false);
      rmid.start();

      /* Cause activation groups to have a security policy that will
       * allow security managers to be downloaded and installed
       */
      Properties p = new Properties();
      // this test must always set policies/managers in its
      // activation groups
      p.put("java.security.policy", TestParams.defaultGroupPolicy);
      p.put("java.security.manager", TestParams.defaultSecurityManager);

      /* new desc - we will reuse in order to get multiple vms.*/
      System.err.println("Create activation group in this VM");
      ActivationGroupDesc groupDesc = new ActivationGroupDesc(p, null);
      ActivationSystem system = ActivationGroup.getSystem();
      ActivationGroupID groupID = system.registerGroup(groupDesc);
      ActivationGroup.createGroup(groupID, groupDesc, 0);

      ActivationDesc desc = new ActivationDesc("CheckAnnotations", null, null);
      myRMI = (MyRMI) Activatable.register(desc);

      /* The test-
       * Loop a bunch of times to force activator to
       * spawn VMs (groups)
       */
      for (int i = 0; i < 3; i++) {

        // object activated in annotation check via method call
        if (!checkAnnotations(i - 1)) {
          TestLibrary.bomb("Test failed: output improperly annotated.");
        }

        /*
         * Clean up object too.
         */
        System.err.println("Deactivate object via method call");
        myRMI.shutdown();
      }
      System.err.println("\nsuccess: CheckAnnotations test passed ");

    } catch (Exception e) {
      TestLibrary.bomb("\nfailure: unexpected exception ", e);
    } finally {
      try {
        Thread.sleep(4000);
      } catch (InterruptedException e) {
      }

      myRMI = null;
      System.err.println("rmid shut down");
      ActivationLibrary.rmidCleanup(rmid);
    }
  }
示例#14
0
  public static void main(String args[]) {

    sameGroup = true;

    RMID rmid = null;

    System.err.println("\nRegression test for bug/rfe 4179055\n");

    try {
      TestLibrary.suggestSecurityManager("java.lang.SecurityManager");

      registry = java.rmi.registry.LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);

      // must run with java.lang.SecurityManager or the test
      // result will be nullified if running with a build where
      // 4180392 has not been fixed.
      String smClassName = System.getSecurityManager().getClass().getName();
      if (!smClassName.equals("java.lang.SecurityManager")) {
        TestLibrary.bomb("Test must run with java.lang.SecurityManager");
      }

      // start an rmid.
      RMID.removeLog();
      rmid = RMID.createRMID();
      rmid.start();

      // rmid.addOptions(new String[] {"-C-Djava.rmi.server.logCalls=true"});

      // Ensure that activation groups run with the correct
      // security manager.
      //
      Properties p = new Properties();
      p.put("java.security.policy", TestParams.defaultGroupPolicy);
      p.put("java.security.manager", "java.lang.SecurityManager");

      // This action causes the following classes to be created
      // in this VM (RMI must permit the creation of these classes):
      //
      // sun.rmi.server.Activation$ActivationSystemImpl_Stub
      // sun.rmi.server.Activation$ActivationMonitorImpl_Stub
      //
      System.err.println("Create activation group, in a new VM");
      ActivationGroupDesc groupDesc = new ActivationGroupDesc(p, null);
      ActivationSystem system = ActivationGroup.getSystem();
      ActivationGroupID groupID = system.registerGroup(groupDesc);

      System.err.println("register activatable");
      // Fix for: 4271615: make sure activation group runs in a new VM
      ActivationDesc desc = new ActivationDesc(groupID, "StubClassesPermitted", null, null);
      canCreateStubs = (CanCreateStubs) Activatable.register(desc);

      // ensure registry stub can be passed in a remote call
      System.err.println("getting the registry");
      registry = canCreateStubs.getRegistry();

      // make sure a client cant load just any sun.* class, just
      // as a sanity check, try to create a class we are not
      // allowed to access but which was passed in a remote call
      try {
        System.err.println("accessing forbidden class");
        Object secureRandom = canCreateStubs.getForbiddenClass();

        TestLibrary.bomb(
            "test allowed to access forbidden class," + " sun.security.provider.SecureRandom");
      } catch (java.security.AccessControlException e) {

        // Make sure we received a *local* AccessControlException
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        PrintStream ps = new PrintStream(bout);
        e.printStackTrace(ps);
        ps.flush();
        String trace = new String(bout.toByteArray());
        if ((trace.indexOf("exceptionReceivedFromServer") >= 0) || trace.equals("")) {
          throw e;
        }
        System.err.println("received expected local access control exception");
      }

      // make sure that an ActivationGroupID can be passed in a
      // remote call; this is slightly more inclusive than
      // just passing a reference to the activation system
      System.err.println("returning group desc");
      canCreateStubs.returnGroupID();

      // Clean up object
      System.err.println("Deactivate object via method call");
      canCreateStubs.shutdown();

      System.err.println("\nsuccess: StubClassesPermitted test passed ");

    } catch (Exception e) {
      TestLibrary.bomb("\nfailure: unexpected exception ", e);
    } finally {
      try {
        Thread.sleep(4000);
      } catch (InterruptedException e) {
      }

      canCreateStubs = null;
      ActivationLibrary.rmidCleanup(rmid);
      System.err.println("rmid shut down");
    }
  }
示例#15
0
 /**
  * Ensures that an activation group id can be passed in a remote call (class may contain a remote
  * reference to the activation system implementation).
  */
 public ActivationGroupID returnGroupID() throws RemoteException {
   return ActivationGroup.currentGroupID();
 }