Hello everybody,

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

[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.

Reply via email to