Am 17.09.2008 um 09:55 schrieb "Ching-Yi Chan" <[EMAIL PROTECTED]>:

Hello everybody,

I have tried to implement a BundleSecurityManager which can disable the
System.exit() method call.

I guess I don't really understand your question... Does it work like this for you and you want to know whether this is a good approach?

regards,

Karl


[code]

*public* *class* BundleSecurityManager *extends* SecurityManager {

 *public* *void* checkPermission(Permission perm, Object context) {

   *if* (perm == *null* || perm.getName() == *null*) {
     *throw* *new* NullPointerException();
   }

   *if* (perm.getName().startsWith("exitVM")) {
     *throw* *new* SecurityException();
   }
 }

 *public* *void* checkPermission(Permission perm) {

   *if* (perm == *null* || perm.getName() == *null*) {
     *throw* *new* NullPointerException();
   }

   *if* (perm.getName().startsWith("exitVM")) {
     *throw* *new* SecurityException();
   }
 }
}
[/code]

And I use it in my service boot bundle :

[code]

*public* *class* BootService {

 SecurityManager defaultSecurtiyManager = *null*;

 *public* *void* start() *throws* Exception {
   defaultSecurtiyManager = System.getSecurityManager();

   *if* (System.getSecurityManager() == *null*) {
     System.setSecurityManager(*new* BundleSecurityManager());
   }
  }

 *public* *void* stop() *throws* Exception {
   System.setSecurityManager(defaultSecurtiyManager);
 }

}[/code]

finally, we also need a security policy file
[code]

grant
{
 permission java.security.AllPermission;
}


[/code]


we can start felix :

java -Djava.security.policy=bundle.policy -jar bin\felix.jar

I don't know other way to do this, any suggestions is appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to