test/java/rmi/registry/altSecurityManager/AltSecurityManager.java

Print this page




  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 4183202
  26  * @summary rmid and rmiregistry could allow alternate security manager
  27  * @author Laird Dornin
  28  *
  29  * @library ../../testlibrary
  30  * @build StreamPipe TestParams TestLibrary JavaVM
  31  * @build AltSecurityManager TestSecurityManager
  32  * @run main/othervm AltSecurityManager
  33  */
  34 
  35 /**
  36  * Ensure that a user is able to specify alternate security managers to
  37  * be used in rmiregistry and rmid.  Test specifies a security manager
  38  * that throws a runtime exception in its checkListen method, this
  39  * will cause rmiregistry and rmid to exit early because those
  40  * utilities will be unable to export any remote objects; test fails
  41  * if registry and rmid take too long to exit.
  42  */
  43 public class AltSecurityManager implements Runnable {
  44 
  45     // variable to hold registry and rmid children
  46     static JavaVM vm = null;
  47 
  48     // names of utilities
  49     static String utilityToStart = null;
  50     static String registry = "sun.rmi.registry.RegistryImpl";
  51     static String rmid = "sun.rmi.server.Activation";
  52 
  53     // children should exit in at least this time.
  54     static long TIME_OUT = 15000;
  55 




  56     public void run() {
  57         try {

  58             vm = new JavaVM(utilityToStart,
  59                             " -Djava.security.manager=TestSecurityManager",
  60                             "");





  61             System.err.println("starting " + utilityToStart);
  62             vm.start();
  63             vm.getVM().waitFor();
  64 
  65         } catch (Exception e) {
  66             TestLibrary.bomb(e);
  67         }
  68     }
  69 
  70     /**
  71      * Wait to make sure that the registry and rmid exit after
  72      * their security manager is set.
  73      */
  74     public static void ensureExit(String utility) throws Exception {
  75         utilityToStart = utility;
  76 
  77         try {
  78             Thread thread = new Thread(new AltSecurityManager());

  79             System.err.println("expecting RuntimeException for " +
  80                                "checkListen in child process");
  81             long start = System.currentTimeMillis();
  82             thread.start();
  83             thread.join(TIME_OUT);
  84 
  85             long time = System.currentTimeMillis() - start;
  86             System.err.println("waited " + time + " millis for " +
  87                                utilityToStart + " to die");
  88 
  89             if (time >= TIME_OUT) {
  90 
  91                 // dont pollute other tests; increase the likelihood
  92                 // that rmid will go away if it did not exit already.
  93                 if (utility.equals(rmid)) {
  94                     RMID.shutdown();
  95                 }
  96 
  97                 TestLibrary.bomb(utilityToStart +
  98                                  " took too long to die...");
  99             } else {
 100                 System.err.println(utilityToStart +
 101                                    " terminated on time");
 102             }
 103         } finally {
 104             vm.destroy();
 105             vm = null;
 106         }
 107     }
 108 
 109     public static void main(String[] args) {
 110         try {
 111             System.err.println("\nRegression test for bug 4183202\n");
 112 
 113             // make sure the registry exits early.
 114             ensureExit(registry);


  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 4183202
  26  * @summary rmid and rmiregistry could allow alternate security manager
  27  * @author Laird Dornin
  28  *
  29  * @library ../../testlibrary
  30  * @build StreamPipe TestParams TestLibrary JavaVM RMID
  31  * @build AltSecurityManager TestSecurityManager
  32  * @run main/othervm AltSecurityManager
  33  */
  34 
  35 /**
  36  * Ensure that a user is able to specify alternate security managers to
  37  * be used in rmiregistry and rmid.  Test specifies a security manager
  38  * that throws a runtime exception in its checkListen method, this
  39  * will cause rmiregistry and rmid to exit early because those
  40  * utilities will be unable to export any remote objects; test fails
  41  * if registry and rmid take too long to exit.
  42  */
  43 public class AltSecurityManager implements Runnable {
  44     private int port = -1;
  45     // variable to hold registry and rmid children
  46     static JavaVM vm = null;
  47 
  48     // names of utilities
  49     static String utilityToStart = null;
  50     static String registry = "sun.rmi.registry.RegistryImpl";
  51     static String rmid = "sun.rmi.server.Activation";
  52 
  53     // children should exit in at least this time.
  54     static long TIME_OUT = 15000;
  55 
  56     public AltSecurityManager(int port) {
  57         this.port = port;
  58     }
  59 
  60     public void run() {
  61         try {
  62             if (utilityToStart.equals(registry)) {
  63                 vm = new JavaVM(utilityToStart,
  64                         " -Djava.security.manager=TestSecurityManager",
  65                         Integer.toString(port));
  66             } else {
  67                 vm = new JavaVM(utilityToStart,
  68                         " -Djava.security.manager=TestSecurityManager",
  69                         "-port " + Integer.toString(port));
  70             }
  71             System.err.println("starting " + utilityToStart);
  72             vm.start();
  73             vm.getVM().waitFor();
  74 
  75         } catch (Exception e) {
  76             TestLibrary.bomb(e);
  77         }
  78     }
  79 
  80     /**
  81      * Wait to make sure that the registry and rmid exit after
  82      * their security manager is set.
  83      */
  84     public static void ensureExit(String utility) throws Exception {
  85         utilityToStart = utility;
  86 
  87         try {
  88             int port = TestLibrary.getUnusedRandomPort();
  89             Thread thread = new Thread(new AltSecurityManager(port));
  90             System.err.println("expecting RuntimeException for " +
  91                                "checkListen in child process");
  92             long start = System.currentTimeMillis();
  93             thread.start();
  94             thread.join(TIME_OUT);
  95 
  96             long time = System.currentTimeMillis() - start;
  97             System.err.println("waited " + time + " millis for " +
  98                                utilityToStart + " to die");
  99 
 100             if (time >= TIME_OUT) {
 101 
 102                 // dont pollute other tests; increase the likelihood
 103                 // that rmid will go away if it did not exit already.
 104                 if (utility.equals(rmid)) {
 105                     RMID.shutdown(port);
 106                 }
 107 
 108                 TestLibrary.bomb(utilityToStart +
 109                                  " took too long to die...");
 110             } else {
 111                 System.err.println(utilityToStart +
 112                                    " terminated on time");
 113             }
 114         } finally {
 115             vm.destroy();
 116             vm = null;
 117         }
 118     }
 119 
 120     public static void main(String[] args) {
 121         try {
 122             System.err.println("\nRegression test for bug 4183202\n");
 123 
 124             // make sure the registry exits early.
 125             ensureExit(registry);