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);
}
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations