use of org.jboss.security.jacc.SubjectPolicyContextHandler in project wildfly by wildfly.
the class SecurityBootstrapService method initializeJacc.
private void initializeJacc() throws StartException {
if (!initializeJacc) {
SecurityLogger.ROOT_LOGGER.debugf("Legacy subsystem configured to not initialize JACC. If you want JACC support, make sure you have it properly configured in Elytron subsystem.");
return;
}
SecurityLogger.ROOT_LOGGER.debugf("Initializing JACC from legacy subsystem.");
try {
// Get the current Policy impl
oldPolicy = Policy.getPolicy();
String module = WildFlySecurityManager.getPropertyPrivileged(JACC_MODULE, null);
String provider = WildFlySecurityManager.getPropertyPrivileged(JACC_POLICY_PROVIDER, "org.jboss.security.jacc.DelegatingPolicy");
Class<?> providerClass = loadClass(module, provider);
try {
// Look for a ctor(Policy) signature
Class<?>[] ctorSig = { Policy.class };
Constructor<?> ctor = providerClass.getConstructor(ctorSig);
Object[] ctorArgs = { oldPolicy };
jaccPolicy = (Policy) ctor.newInstance(ctorArgs);
} catch (NoSuchMethodException e) {
log.debugf("Provider does not support ctor(Policy)");
try {
jaccPolicy = (Policy) providerClass.newInstance();
} catch (Exception e1) {
throw SecurityLogger.ROOT_LOGGER.unableToStartException("SecurityBootstrapService", e1);
}
} catch (Exception e) {
throw SecurityLogger.ROOT_LOGGER.unableToStartException("SecurityBootstrapService", e);
}
// Install the JACC policy provider
Policy.setPolicy(jaccPolicy);
// Have the policy load/update itself
jaccPolicy.refresh();
// Register the default active Subject PolicyContextHandler
SubjectPolicyContextHandler handler = new SubjectPolicyContextHandler();
PolicyContext.registerHandler(SecurityConstants.SUBJECT_CONTEXT_KEY, handler, true);
// Register the JAAS CallbackHandler JACC PolicyContextHandlers
CallbackHandlerPolicyContextHandler chandler = new CallbackHandlerPolicyContextHandler();
PolicyContext.registerHandler(SecurityConstants.CALLBACK_HANDLER_KEY, chandler, true);
//Register a module classloader locator
ClassLoaderLocatorFactory.set(new ModuleClassLoaderLocator(moduleLoaderValue.getValue()));
} catch (Exception e) {
throw SecurityLogger.ROOT_LOGGER.unableToStartException("SecurityBootstrapService", e);
}
}
Aggregations