use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class RaAdd method performRuntime.
@Override
public void performRuntime(final OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
final ModelNode model = resource.getModel();
// TODO WFLY-15231 -- this logic is using the wrong attributes, so it's currently doing nothing
if (ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
if (model.hasDefined(SECURITY_DOMAIN.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
else if (model.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
else if (model.hasDefined(APPLICATION.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(APPLICATION.getName(), ELYTRON_ENABLED.getName());
} else {
if (model.hasDefined(AUTHENTICATION_CONTEXT.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
else if (model.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
}
// do the same for recovery security attributes
if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) {
if (model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
} else {
if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()))
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
}
// Compensating is remove
final String name = context.getCurrentAddressValue();
final String archiveOrModuleName;
final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, model).asBoolean();
if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
}
if (model.get(ARCHIVE.getName()).isDefined()) {
archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
} else {
archiveOrModuleName = model.get(MODULE.getName()).asString();
}
ModifiableResourceAdapter resourceAdapter = RaOperationUtil.buildResourceAdaptersObject(name, context, operation, archiveOrModuleName);
List<ServiceController<?>> newControllers = new ArrayList<ServiceController<?>>();
if (model.get(ARCHIVE.getName()).isDefined()) {
RaOperationUtil.installRaServices(context, name, resourceAdapter, newControllers);
} else {
RaOperationUtil.installRaServicesAndDeployFromModule(context, name, resourceAdapter, archiveOrModuleName, newControllers);
if (context.isBooting()) {
context.addStep(new OperationStepHandler() {
public void execute(final OperationContext context, ModelNode operation) throws OperationFailedException {
// Next lines activate configuration on module deployed rar
// in case there is 2 different resource-adapter config using same module deployed rar
// a Deployment sercivice could be already present and need a restart to consider also this
// newly added configuration
ServiceName restartedServiceName = RaOperationUtil.restartIfPresent(context, archiveOrModuleName, name);
if (restartedServiceName == null) {
RaOperationUtil.activate(context, name, archiveOrModuleName);
}
context.completeStep(new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
RaOperationUtil.removeIfActive(context, archiveOrModuleName, name);
} catch (OperationFailedException e) {
}
}
});
}
}, OperationContext.Stage.RUNTIME);
}
}
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, name));
Activation raxml = (Activation) RaxmlController.getValue();
ServiceName serviceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, name);
String bootStrapCtxName = DEFAULT_NAME;
if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
bootStrapCtxName = raxml.getBootstrapContext();
}
ResourceAdapterStatisticsService raStatsService = new ResourceAdapterStatisticsService(context.getResourceRegistrationForUpdate(), name, statsEnabled);
ServiceBuilder statsServiceBuilder = context.getServiceTarget().addService(ServiceName.of(ConnectorServices.RA_SERVICE, name).append(ConnectorServices.STATISTICS_SUFFIX), raStatsService);
statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, raStatsService.getBootstrapContextInjector()).addDependency(serviceName, Object.class, raStatsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
PathElement peStats = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
resource.registerChild(peStats, statsResource);
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class ConnectionDefinitionAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
PathAddress path = context.getCurrentAddress();
final String jndiName = JNDINAME.resolveModelAttribute(context, operation).asString();
final String raName = path.getParent().getLastElement().getValue();
final String archiveOrModuleName;
ModelNode raModel = context.readResourceFromRoot(path.getParent(), false).getModel();
final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
}
ModelNode resourceModel = resource.getModel();
final boolean elytronEnabled = ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean();
final boolean elytronRecoveryEnabled = RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, resourceModel).asBoolean();
final ModelNode credentialReference = RECOVERY_CREDENTIAL_REFERENCE.resolveModelAttribute(context, resourceModel);
// add extra security validation: authentication contexts should only be defined when Elytron Enabled is false
// domains should only be defined when Elytron enabled is undefined or false (default value)
boolean hasSecurityDomain = resourceModel.hasDefined(SECURITY_DOMAIN.getName());
boolean hasSecurityDomainAndApp = resourceModel.hasDefined(SECURITY_DOMAIN_AND_APPLICATION.getName());
if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName()) && !elytronEnabled) {
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT.getName(), ELYTRON_ENABLED.getName());
} else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName()) && !elytronEnabled) {
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
} else if (hasSecurityDomain && elytronEnabled) {
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN.getName(), ELYTRON_ENABLED.getName());
} else if (hasSecurityDomainAndApp && elytronEnabled) {
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(SECURITY_DOMAIN_AND_APPLICATION.getName(), ELYTRON_ENABLED.getName());
}
boolean hasRecoverySecurityDomain = resourceModel.hasDefined(RECOVERY_SECURITY_DOMAIN.getName());
if (resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()) && !elytronRecoveryEnabled) {
throw SUBSYSTEM_RA_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName());
} else if (hasRecoverySecurityDomain && elytronRecoveryEnabled) {
throw SUBSYSTEM_RA_LOGGER.attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName());
}
if (raModel.get(ARCHIVE.getName()).isDefined()) {
archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
} else {
archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
}
final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
try {
ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
final ModifiableResourceAdapter ravalue = ((ModifiableResourceAdapter) context.getServiceRegistry(false).getService(raServiceName).getValue());
boolean isXa = ravalue.getTransactionSupport() == TransactionSupportEnum.XATransaction;
final ServiceTarget serviceTarget = context.getServiceTarget();
final ConnectionDefinitionService service = new ConnectionDefinitionService();
service.getConnectionDefinitionSupplierInjector().inject(() -> RaOperationUtil.buildConnectionDefinitionObject(context, resourceModel, poolName, isXa, service.getCredentialSourceSupplier().getOptionalValue()));
final ServiceBuilder<ModifiableConnDef> cdServiceBuilder = serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector());
// and this should be changed to use a proper capability in the future.
if (elytronEnabled) {
if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT.getName())) {
cdServiceBuilder.requires(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
} else if (resourceModel.hasDefined(AUTHENTICATION_CONTEXT_AND_APPLICATION.getName())) {
cdServiceBuilder.requires(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, AUTHENTICATION_CONTEXT_AND_APPLICATION.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
}
}
if (elytronRecoveryEnabled && resourceModel.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName())) {
cdServiceBuilder.requires(context.getCapabilityServiceName(Capabilities.AUTHENTICATION_CONTEXT_CAPABILITY, RECOVERY_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, resourceModel).asString(), AuthenticationContext.class));
}
if (!elytronEnabled || !elytronRecoveryEnabled) {
if (hasSecurityDomain || hasSecurityDomainAndApp || hasRecoverySecurityDomain || RaAdd.requiresLegacySecurity(context, raModel)) {
// We can't satisfy the config, so fail with a meaningful error
context.setRollbackOnly();
throw SUBSYSTEM_RA_LOGGER.legacySecurityNotAvailable(path.getLastElement().getValue(), path.getParent().getLastElement().getValue());
}
// else there's no legacy security. We're not configured for elytron, but our RA's WM doesn't require legacy security nor do we.
}
if (credentialReference.isDefined()) {
service.getCredentialSourceSupplier().inject(CredentialReference.getCredentialSourceSupplier(context, RECOVERY_CREDENTIAL_REFERENCE, resourceModel, cdServiceBuilder));
}
// Install the ConnectionDefinitionService
cdServiceBuilder.install();
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
Activation raxml = (Activation) RaxmlController.getValue();
ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
String bootStrapCtxName = DEFAULT_NAME;
if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
bootStrapCtxName = raxml.getBootstrapContext();
}
ConnectionDefinitionStatisticsService connectionDefinitionStatisticsService = new ConnectionDefinitionStatisticsService(context.getResourceRegistrationForUpdate(), jndiName, poolName, statsEnabled);
ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), connectionDefinitionStatisticsService);
statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, connectionDefinitionStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, Object.class, connectionDefinitionStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
PathElement peCD = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
final Resource cdResource = new IronJacamarResource.IronJacamarRuntimeResource();
resource.registerChild(peCD, cdResource);
PathElement peExtended = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
final Resource extendedResource = new IronJacamarResource.IronJacamarRuntimeResource();
resource.registerChild(peExtended, extendedResource);
} catch (Exception e) {
throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("ConnectionDefinition", operation, e.getLocalizedMessage())));
}
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class AdminObjectAdd method performRuntime.
@Override
protected void performRuntime(OperationContext context, ModelNode operation, final Resource resource) throws OperationFailedException {
final ModelNode address = operation.require(OP_ADDR);
PathAddress path = PathAddress.pathAddress(address);
final String raName = context.getCurrentAddress().getParent().getLastElement().getValue();
final String archiveOrModuleName;
ModelNode raModel = context.readResourceFromRoot(path.subAddress(0, path.size() - 1), false).getModel();
final boolean statsEnabled = STATISTICS_ENABLED.resolveModelAttribute(context, raModel).asBoolean();
if (!raModel.hasDefined(ARCHIVE.getName()) && !raModel.hasDefined(MODULE.getName())) {
throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
}
if (raModel.get(ARCHIVE.getName()).isDefined()) {
archiveOrModuleName = ARCHIVE.resolveModelAttribute(context, raModel).asString();
} else {
archiveOrModuleName = MODULE.resolveModelAttribute(context, raModel).asString();
}
final String poolName = PathAddress.pathAddress(address).getLastElement().getValue();
final ModifiableAdminObject adminObjectValue;
try {
adminObjectValue = RaOperationUtil.buildAdminObjects(context, operation, poolName);
} catch (ValidateException e) {
throw new OperationFailedException(e, new ModelNode().set(ConnectorLogger.ROOT_LOGGER.failedToCreate("AdminObject", operation, e.getLocalizedMessage())));
}
ServiceName serviceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName, poolName);
ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, raName);
final ServiceTarget serviceTarget = context.getServiceTarget();
final AdminObjectService service = new AdminObjectService(adminObjectValue);
serviceTarget.addService(serviceName, service).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(raServiceName, ModifiableResourceAdapter.class, service.getRaInjector()).install();
ServiceRegistry registry = context.getServiceRegistry(true);
final ServiceController<?> RaxmlController = registry.getService(ServiceName.of(ConnectorServices.RA_SERVICE, raName));
Activation raxml = (Activation) RaxmlController.getValue();
ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(archiveOrModuleName, raName);
String bootStrapCtxName = DEFAULT_NAME;
if (raxml.getBootstrapContext() != null && !raxml.getBootstrapContext().equals("undefined")) {
bootStrapCtxName = raxml.getBootstrapContext();
}
AdminObjectStatisticsService adminObjectStatisticsService = new AdminObjectStatisticsService(context.getResourceRegistrationForUpdate(), poolName, statsEnabled);
ServiceBuilder statsServiceBuilder = serviceTarget.addService(serviceName.append(ConnectorServices.STATISTICS_SUFFIX), adminObjectStatisticsService);
statsServiceBuilder.addDependency(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootStrapCtxName), Object.class, adminObjectStatisticsService.getBootstrapContextInjector()).addDependency(deploymentServiceName, Object.class, adminObjectStatisticsService.getResourceAdapterDeploymentInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
PathElement peAO = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
final Resource aoResource = new IronJacamarResource.IronJacamarRuntimeResource();
resource.registerChild(peAO, aoResource);
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class JdbcDriverRemove method performRuntime.
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
final String driverName = model.get(DRIVER_NAME.getName()).asString();
final ServiceRegistry registry = context.getServiceRegistry(true);
ServiceName jdbcServiceName = ServiceName.JBOSS.append("jdbc-driver", driverName.replaceAll("\\.", "_"));
ServiceController<?> jdbcServiceController = registry.getService(jdbcServiceName);
context.removeService(jdbcServiceController);
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class JaccEjbDeploymentProcessor method undeploy.
@Override
public void undeploy(DeploymentUnit deploymentUnit) {
AbstractSecurityDeployer<?> deployer = null;
deployer = new EjbSecurityDeployer();
deployer.undeploy(deploymentUnit);
// Jakarta Enterprise Beans maybe included directly in war deployment
ServiceName jaccServiceName = getJaccServiceName(deploymentUnit);
ServiceRegistry registry = deploymentUnit.getServiceRegistry();
if (registry != null) {
ServiceController<?> serviceController = registry.getService(jaccServiceName);
if (serviceController != null) {
serviceController.setMode(ServiceController.Mode.REMOVE);
}
}
}
Aggregations