Search in sources :

Example 1 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class JMSService method doStart.

private synchronized void doStart(final StartContext context) throws StartException {
    final ServiceContainer serviceContainer = context.getController().getServiceContainer();
    ClassLoader oldTccl = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(getClass());
    try {
        jmsServer = new JMSServerManagerImpl(activeMQServer.getValue(), new WildFlyBindingRegistry(context.getController().getServiceContainer()));
        activeMQServer.getValue().registerActivateCallback(new ActivateCallback() {

            private volatile ServiceController<Void> activeMQActivationController;

            public void preActivate() {
            }

            public void activated() {
                if (overrideInVMSecurity) {
                    activeMQServer.getValue().getRemotingService().allowInvmSecurityOverride(new ActiveMQPrincipal(DefaultCredentials.getUsername(), DefaultCredentials.getPassword()));
                }
                //   ActiveMQ backup server is activated during failover while the WildFly server is shutting down.
                if (serviceContainer.isShutdown()) {
                    return;
                }
                if (activeMQActivationController == null) {
                    activeMQActivationController = serviceContainer.addService(ActiveMQActivationService.getServiceName(serverServiceName), new ActiveMQActivationService()).setInitialMode(Mode.ACTIVE).install();
                } else {
                    activeMQActivationController.setMode(ACTIVE);
                }
            }

            @Override
            public void activationComplete() {
            }

            public void deActivate() {
                // and *not* during AS7 service container shutdown or reload (AS7-6840 / AS7-6881)
                if (activeMQActivationController != null) {
                    if (!activeMQActivationController.getState().in(STOPPING, REMOVED)) {
                        // [WFLY-4597] When Artemis is deactivated during failover, we block until its
                        // activation controller is REMOVED before giving back control to Artemis.
                        // This allow to properly stop any service depending on the activation controller
                        // and avoid spurious warning messages because the resources used by the services
                        // are stopped outside the control of the services.
                        final CountDownLatch latch = new CountDownLatch(1);
                        activeMQActivationController.compareAndSetMode(ACTIVE, REMOVE);
                        activeMQActivationController.addListener(new AbstractServiceListener<Void>() {

                            @Override
                            public void transition(ServiceController<? extends Void> controller, ServiceController.Transition transition) {
                                if (transition.enters(REMOVED)) {
                                    latch.countDown();
                                }
                            }
                        });
                        try {
                            latch.await(5, TimeUnit.SECONDS);
                        } catch (InterruptedException e) {
                        }
                        activeMQActivationController = null;
                    }
                }
            }
        });
        jmsServer.start();
    } catch (StartException e) {
        throw e;
    } catch (Throwable t) {
        throw MessagingLogger.ROOT_LOGGER.failedToStartService(t);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
    }
}
Also used : ActiveMQPrincipal(org.apache.activemq.artemis.core.security.ActiveMQPrincipal) AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceContainer(org.jboss.msc.service.ServiceContainer) ActiveMQActivationService(org.wildfly.extension.messaging.activemq.ActiveMQActivationService) JMSServerManagerImpl(org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl) ServiceController(org.jboss.msc.service.ServiceController) StartException(org.jboss.msc.service.StartException) ActivateCallback(org.apache.activemq.artemis.core.server.ActivateCallback)

Example 2 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class QueueService method start.

/** {@inheritDoc} */
@Override
public synchronized void start(StartContext context) throws StartException {
    try {
        final ActiveMQServer server = this.activeMQServer.getValue();
        server.deployQueue(new SimpleString(queueConfiguration.getAddress()), new SimpleString(queueConfiguration.getName()), SimpleString.toSimpleString(queueConfiguration.getFilterString()), queueConfiguration.isDurable(), temporary);
    } catch (Exception e) {
        throw new StartException(e);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) StartException(org.jboss.msc.service.StartException) StartException(org.jboss.msc.service.StartException)

Example 3 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class SubjectFactoryService method start.

/** {@inheritDoc} */
@Override
public synchronized void start(StartContext context) throws StartException {
    SecurityLogger.ROOT_LOGGER.debugf("Starting SubjectFactoryService");
    final ISecurityManagement injectedSecurityManagement = securityManagementValue.getValue();
    int i = subjectFactoryClassName.lastIndexOf(":");
    if (i == -1)
        throw SecurityLogger.ROOT_LOGGER.missingModuleName("subject-factory-class-name attribute");
    String moduleSpec = subjectFactoryClassName.substring(0, i);
    String className = subjectFactoryClassName.substring(i + 1);
    JBossSecuritySubjectFactory subjectFactory = null;
    try {
        Class<?> subjectFactoryClazz = SecurityActions.getModuleClassLoader(moduleSpec).loadClass(className);
        subjectFactory = (JBossSecuritySubjectFactory) subjectFactoryClazz.newInstance();
    } catch (Exception e) {
        throw SecurityLogger.ROOT_LOGGER.unableToStartException("SubjectFactoryService", e);
    }
    subjectFactory.setSecurityManagement(injectedSecurityManagement);
    this.subjectFactory = subjectFactory;
}
Also used : JBossSecuritySubjectFactory(org.jboss.security.plugins.JBossSecuritySubjectFactory) ISecurityManagement(org.jboss.security.ISecurityManagement) StartException(org.jboss.msc.service.StartException)

Example 4 with StartException

use of org.jboss.msc.service.StartException in project wildfly by wildfly.

the class JaccService method start.

/** {@inheritDoc} */
@Override
public void start(StartContext context) throws StartException {
    try {
        PolicyConfigurationFactory pcf = getPolicyConfigurationFactory();
        synchronized (pcf) {
            // synchronize on the factory
            policyConfiguration = pcf.getPolicyConfiguration(contextId, false);
            if (metaData != null) {
                createPermissions(metaData, policyConfiguration);
            } else {
                SecurityLogger.ROOT_LOGGER.debugf("Cannot create permissions with 'null' metaData for id=%s", contextId);
            }
            if (!standalone) {
                PolicyConfiguration parent = parentPolicy.getValue();
                if (parent != null) {
                    parent = pcf.getPolicyConfiguration(parent.getContextID(), false);
                    parent.linkConfiguration(policyConfiguration);
                    policyConfiguration.commit();
                    parent.commit();
                } else {
                    SecurityLogger.ROOT_LOGGER.debugf("Could not retrieve parent policy for policy %s", contextId);
                }
            } else {
                policyConfiguration.commit();
            }
            // Allow the policy to incorporate the policy configs
            Policy.getPolicy().refresh();
        }
    } catch (Exception e) {
        throw SecurityLogger.ROOT_LOGGER.unableToStartException("JaccService", e);
    }
}
Also used : PolicyConfiguration(javax.security.jacc.PolicyConfiguration) PolicyConfigurationFactory(javax.security.jacc.PolicyConfigurationFactory) PolicyContextException(javax.security.jacc.PolicyContextException) ModuleLoadException(org.jboss.modules.ModuleLoadException) StartException(org.jboss.msc.service.StartException)

Example 5 with StartException

use of org.jboss.msc.service.StartException 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

StartException (org.jboss.msc.service.StartException)43 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ExecutorService (java.util.concurrent.ExecutorService)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 ORB (org.omg.CORBA.ORB)4 InetSocketAddress (java.net.InetSocketAddress)3 PrivilegedAction (java.security.PrivilegedAction)3 HashMap (java.util.HashMap)3 PostInitLoader (com.arjuna.orbportability.internal.utils.PostInitLoader)2 HandlerWrapper (io.undertow.server.HandlerWrapper)2 HttpHandler (io.undertow.server.HttpHandler)2 File (java.io.File)2 AccessControlContext (java.security.AccessControlContext)2 Map (java.util.Map)2 TempClassLoaderFactoryImpl (org.jboss.as.jpa.classloader.TempClassLoaderFactoryImpl)2 SocketBinding (org.jboss.as.network.SocketBinding)2 ModuleLoadException (org.jboss.modules.ModuleLoadException)2 Service (org.jboss.msc.service.Service)2 ServiceContainer (org.jboss.msc.service.ServiceContainer)2