/**
* Installs a SecurityManager on behalf of the application
*/
public void installSecurityManager(){
Policy policy = Policy.getPolicy();
BatikSecurityManager securityManager = new BatikSecurityManager();
//
// If there is a java.security.policy property defined,
// it takes precedence over the one passed to this object.
// Otherwise, we default to the one passed to the constructor
//
ClassLoader cl = appMainClass.getClassLoader();
String securityPolicyProperty
= System.getProperty(PROPERTY_JAVA_SECURITY_POLICY);
if (securityPolicyProperty == null || securityPolicyProperty.equals("")) {
// Specify app's security policy in the
// system property.
URL policyURL = getPolicyURL();
System.setProperty(PROPERTY_JAVA_SECURITY_POLICY,
policyURL.toString());
}
//
// The following detects whether the application is running in the
// development environment, in which case it will set the
// app.dev.base property or if it is running in the binary
// distribution, in which case it will set the app.jar.base
// property. These properties are expanded in the security
// policy files.
// Property expansion is used to provide portability of the
// policy files between various code bases (e.g., file base,
// server base, etc..).
//
URL mainClassURL = cl.getResource(appMainClassRelativeURL);
if (mainClassURL == null){
// Something is really wrong: we would be running a class
// which can't be found....
throw new Error(appMainClassRelativeURL);
}
String expandedMainClassName = mainClassURL.toString();
if (expandedMainClassName.startsWith(JAR_PROTOCOL) ) {
setJarBase(expandedMainClassName);
} else {
setDevBase(expandedMainClassName);
}
// Install new security manager
System.setSecurityManager(securityManager);
lastSecurityManagerInstalled = securityManager;
// Forces re-loading of the security policy
policy.refresh();
if (securityPolicyProperty == null || securityPolicyProperty.equals("")) {
System.setProperty(PROPERTY_JAVA_SECURITY_POLICY, "");
}
}