Search in sources :

Example 1 with ModuleClassLoaderLocator

use of org.jboss.as.security.plugins.ModuleClassLoaderLocator 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);
    }
}
Also used : Policy(java.security.Policy) CallbackHandlerPolicyContextHandler(org.jboss.security.auth.callback.CallbackHandlerPolicyContextHandler) ModuleClassLoaderLocator(org.jboss.as.security.plugins.ModuleClassLoaderLocator) ModuleLoadException(org.jboss.modules.ModuleLoadException) StartException(org.jboss.msc.service.StartException) SubjectPolicyContextHandler(org.jboss.security.jacc.SubjectPolicyContextHandler)

Aggregations

Policy (java.security.Policy)1 ModuleClassLoaderLocator (org.jboss.as.security.plugins.ModuleClassLoaderLocator)1 ModuleLoadException (org.jboss.modules.ModuleLoadException)1 StartException (org.jboss.msc.service.StartException)1 CallbackHandlerPolicyContextHandler (org.jboss.security.auth.callback.CallbackHandlerPolicyContextHandler)1 SubjectPolicyContextHandler (org.jboss.security.jacc.SubjectPolicyContextHandler)1