Custom Security Manager Questions

Benjamin Renaud (br@doppio)
Fri, 3 Jan 1997 17:53:25 -0800

Date: Fri, 3 Jan 1997 17:53:25 -0800
From: br@doppio (Benjamin Renaud)
Message-Id: <199701040153.RAA21425@springbank.eng.sun.com>
To: "Ed Smiley" <esmiley@meridian-data.com>
Subject: Custom Security Manager Questions
In-Reply-To: <9700038523.AA852340527@smtpgate.meridian-data.com>

Hi Ed,

This is indeed the right address for your questions.

[...]

| Say I have an application called Exec_er.class.
| Also I have applications called a1.class, a2.class, etc.
| Exec_er installs a custom Security Manager right off in its main method.
| It then launches a thread that loops through a periodically updated list
| of classes and proceeds to instantiate a1, a2, ... as a1inst, a2inst etc.
| then invoking a1inst.main(); a2inst.main()...
|
| The reason I am looking at this design is that I want to launch
| "fork off" complete child applications determined at runtime from a
| runtime engine (which I call Exec_er). Rather than doing a true launch
| through the OS (exec'ing "java a1"...), I want to get the applications
| running independently in tandem, but restricted by the Security Manager I
| put in place.
|
| My questions are as follows:
| 1. Will each class inherit the Security Manager in effect when the main()
| method was called, that is to say, in Exec_er? I'd think yes.

It depends on how you end up doing it. There is one SecurityManager
per VM. This means, that when you type

> java Exec_er

at the command line, you're starting one java VM. If from that VM you
"load and start" other classes such as your a* classes), they will
share the same VM, and consequently the same security manager.

Note that if you were to use Runtime.exec, you would be starting a
different Java VM, with a different SecurityManager.

| 2. Will each main() method (a1inst.main(); a2inst.main()...)get a
| separate thread of execution? I would think so as well.

main is a normal static method. It is used by the interpreter to as a
bootstrap mechanism, but when it is invoked normally at runtime, it is
simply just another static method.

To do what you want to do, you should have a1, a2, etc be runnable,
and start separate threads for each one from Exec_er. See the Java
Programming Language by Ken Arnold and James Gosling,
Addison-Wesley. Chapter 9 is on how to use threads.

I hope this answers your questions.

Cheers,
-- Benjamin
JavaSoft, Security Group