public void startService() throws Exception {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL policyURL = loader.getResource(policyFile);
if( policyURL == null )
throw new FileNotFoundException("Failed to find URL for policy resource: "+policyFile);
System.out.println("Loading policy file from: "+policyURL);
policySource = new SecurityPolicyParser(policyURL);
securityPolicy = new SecurityPolicy(policySource);
policySource.refresh();
InitialContext ctx = new InitialContext();
NonSerializableFactory.rebind(jndiName, securityPolicy);
// Bind a reference to securityPolicy using NonSerializableFactory as the ObjectFactory
String className = securityPolicy.getClass().getName();
String factory = NonSerializableFactory.class.getName();
StringRefAddr addr = new StringRefAddr("nns", jndiName);
Reference memoryRef = new Reference(className, addr, factory, null);
ctx.rebind(jndiName, memoryRef);
// Install securityPolicy as the JAAS Policy
Policy.setPolicy(securityPolicy);
// Install securityPolicy as the JAAS Configuration
Configuration.setConfiguration(securityPolicy.getLoginConfiguration());
}
|