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);
    }
  }
Exemplo n.º 2
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");
    }
  }