use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class IronJacamarResourceCreator method addAdminObject.
private void addAdminObject(final Resource parent, AdminObject adminObject) {
final Resource adminObjectResource = new IronJacamarResource.IronJacamarRuntimeResource();
final ModelNode model = adminObjectResource.getModel();
setAttribute(model, CLASS_NAME, adminObject.getClassName());
setAttribute(model, JNDINAME, adminObject.getJndiName());
setAttribute(model, USE_JAVA_CONTEXT, adminObject.isUseJavaContext());
setAttribute(model, ENABLED, adminObject.isEnabled());
if (adminObject.getConfigProperties() != null) {
for (Map.Entry<String, String> config : adminObject.getConfigProperties().entrySet()) {
addConfigProperties(adminObjectResource, config.getKey(), config.getValue());
}
}
final PathElement element = PathElement.pathElement(Constants.ADMIN_OBJECTS_NAME, adminObject.getJndiName());
parent.registerChild(element, adminObjectResource);
}
use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class IronJacamarResourceCreator method addConfigProperties.
private void addConfigProperties(final Resource parent, String name, String value) {
final Resource config = new IronJacamarResource.IronJacamarRuntimeResource();
final ModelNode model = config.getModel();
model.get(Constants.CONFIG_PROPERTY_VALUE.getName()).set(value);
final PathElement element = PathElement.pathElement(Constants.CONFIG_PROPERTIES.getName(), name);
parent.registerChild(element, config);
}
use of org.jboss.as.controller.PathElement in project wildfly by wildfly.
the class IronJacamarResourceCreator method addResourceAdapter.
private void addResourceAdapter(final Resource parent, String name, Activation ironJacamarMetadata) {
final Resource ijResourceAdapter = new IronJacamarResource.IronJacamarRuntimeResource();
final ModelNode model = ijResourceAdapter.getModel();
model.get(Constants.ARCHIVE.getName()).set(name);
setAttribute(model, Constants.BOOTSTRAP_CONTEXT, ironJacamarMetadata.getBootstrapContext());
if (ironJacamarMetadata.getTransactionSupport() != null)
model.get(Constants.TRANSACTION_SUPPORT.getName()).set(ironJacamarMetadata.getTransactionSupport().name());
if (ironJacamarMetadata.getWorkManager() != null && ironJacamarMetadata.getWorkManager().getSecurity() != null) {
org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity security = ironJacamarMetadata.getWorkManager().getSecurity();
model.get(Constants.WM_SECURITY.getName()).set(true);
if (security.getDefaultGroups() != null) {
for (String group : security.getDefaultGroups()) {
model.get(Constants.WM_SECURITY_DEFAULT_GROUPS.getName()).add(group);
}
}
if (security.getDefaultPrincipal() != null)
model.get(Constants.WM_SECURITY_DEFAULT_PRINCIPAL.getName()).set(security.getDefaultPrincipal());
model.get(Constants.WM_SECURITY_MAPPING_REQUIRED.getName()).set(security.isMappingRequired());
if (security instanceof WorkManagerSecurity && ((WorkManagerSecurity) security).isElytronEnabled()) {
model.get(Constants.WM_ELYTRON_SECURITY_DOMAIN.getName()).set(security.getDomain());
} else {
model.get(Constants.WM_SECURITY_DOMAIN.getName()).set(security.getDomain());
}
if (security.getGroupMappings() != null) {
for (Map.Entry<String, String> entry : security.getGroupMappings().entrySet()) {
final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource();
final ModelNode subModel = mapping.getModel();
subModel.get(Constants.WM_SECURITY_MAPPING_FROM.getName()).set(entry.getKey());
subModel.get(Constants.WM_SECURITY_MAPPING_TO.getName()).set(entry.getKey());
final PathElement element = PathElement.pathElement(Constants.WM_SECURITY_MAPPING_GROUPS.getName(), WM_SECURITY_MAPPING_GROUP.getName());
ijResourceAdapter.registerChild(element, mapping);
}
}
if (security.getUserMappings() != null) {
for (Map.Entry<String, String> entry : security.getUserMappings().entrySet()) {
final Resource mapping = new IronJacamarResource.IronJacamarRuntimeResource();
final ModelNode subModel = mapping.getModel();
subModel.get(Constants.WM_SECURITY_MAPPING_FROM.getName()).set(entry.getKey());
subModel.get(Constants.WM_SECURITY_MAPPING_TO.getName()).set(entry.getKey());
final PathElement element = PathElement.pathElement(Constants.WM_SECURITY_MAPPING_USERS.getName(), WM_SECURITY_MAPPING_USER.getName());
ijResourceAdapter.registerChild(element, mapping);
}
}
}
if (ironJacamarMetadata.getBeanValidationGroups() != null) {
for (String bv : ironJacamarMetadata.getBeanValidationGroups()) {
model.get(Constants.BEANVALIDATION_GROUPS.getName()).add(new ModelNode().set(bv));
}
}
if (ironJacamarMetadata.getConfigProperties() != null) {
for (Map.Entry<String, String> config : ironJacamarMetadata.getConfigProperties().entrySet()) {
addConfigProperties(ijResourceAdapter, config.getKey(), config.getValue());
}
}
if (ironJacamarMetadata.getConnectionDefinitions() != null) {
for (ConnectionDefinition connDef : ironJacamarMetadata.getConnectionDefinitions()) {
addConnectionDefinition(ijResourceAdapter, connDef);
}
}
if (ironJacamarMetadata.getAdminObjects() != null) {
for (AdminObject adminObject : ironJacamarMetadata.getAdminObjects()) {
addAdminObject(ijResourceAdapter, adminObject);
}
}
final Resource statsResource = new IronJacamarResource.IronJacamarRuntimeResource();
ijResourceAdapter.registerChild(PathElement.pathElement(Constants.STATISTICS_NAME, "local"), statsResource);
final PathElement element = PathElement.pathElement(Constants.RESOURCEADAPTER_NAME, name);
parent.registerChild(element, ijResourceAdapter);
}
use of org.jboss.as.controller.PathElement 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.as.controller.PathElement in project wildfly by wildfly.
the class DistributedWorkManagerAdd method performRuntime.
@Override
protected void performRuntime(final OperationContext context, final ModelNode operation, final Resource resource) throws OperationFailedException {
ModelNode model = resource.getModel();
String name = JcaDistributedWorkManagerDefinition.DWmParameters.NAME.getAttribute().resolveModelAttribute(context, model).asString();
boolean elytronEnabled = JcaWorkManagerDefinition.WmParameters.ELYTRON_ENABLED.getAttribute().resolveModelAttribute(context, resource.getModel()).asBoolean();
String policy = JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute().resolveModelAttribute(context, model).asString();
String selector = JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR.getAttribute().resolveModelAttribute(context, model).asString();
ServiceTarget serviceTarget = context.getServiceTarget();
NamedDistributedWorkManager namedDistributedWorkManager = new NamedDistributedWorkManager(name, elytronEnabled);
if (policy != null && !policy.trim().isEmpty()) {
switch(JcaDistributedWorkManagerDefinition.PolicyValue.valueOf(policy)) {
case NEVER:
{
namedDistributedWorkManager.setPolicy(new Never());
break;
}
case ALWAYS:
{
namedDistributedWorkManager.setPolicy(new Always());
break;
}
case WATERMARK:
{
namedDistributedWorkManager.setPolicy(new WaterMark());
break;
}
default:
throw ROOT_LOGGER.unsupportedPolicy(policy);
}
Injection injector = new Injection();
for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute()).unwrap(context, model).entrySet()) {
try {
injector.inject(namedDistributedWorkManager.getPolicy(), entry.getKey(), entry.getValue());
} catch (Exception e) {
ROOT_LOGGER.unsupportedPolicyOption(entry.getKey());
}
}
} else {
namedDistributedWorkManager.setPolicy(new WaterMark());
}
if (selector != null && !selector.trim().isEmpty()) {
switch(JcaDistributedWorkManagerDefinition.SelectorValue.valueOf(selector)) {
case FIRST_AVAILABLE:
{
namedDistributedWorkManager.setSelector(new FirstAvailable());
break;
}
case MAX_FREE_THREADS:
{
namedDistributedWorkManager.setSelector(new MaxFreeThreads());
break;
}
case PING_TIME:
{
namedDistributedWorkManager.setSelector(new PingTime());
break;
}
default:
throw ROOT_LOGGER.unsupportedSelector(selector);
}
Injection injector = new Injection();
for (Map.Entry<String, String> entry : ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.SELECTOR_OPTIONS.getAttribute()).unwrap(context, model).entrySet()) {
try {
injector.inject(namedDistributedWorkManager.getSelector(), entry.getKey(), entry.getValue());
} catch (Exception e) {
ROOT_LOGGER.unsupportedSelectorOption(entry.getKey());
}
}
} else {
namedDistributedWorkManager.setSelector(new PingTime());
}
DistributedWorkManagerService wmService = new DistributedWorkManagerService(namedDistributedWorkManager);
ServiceBuilder<NamedDistributedWorkManager> builder = serviceTarget.addService(ConnectorServices.WORKMANAGER_SERVICE.append(name), wmService);
builder.addDependency(ClusteringDefaultRequirement.COMMAND_DISPATCHER_FACTORY.getServiceName(context), CommandDispatcherFactory.class, wmService.getCommandDispatcherFactoryInjector());
if (resource.hasChild(PathElement.pathElement(Element.LONG_RUNNING_THREADS.getLocalName()))) {
builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_LONG_RUNNING).append(name), Executor.class, wmService.getExecutorLongInjector());
}
builder.addDependency(ThreadsServices.EXECUTOR.append(WORKMANAGER_SHORT_RUNNING).append(name), Executor.class, wmService.getExecutorShortInjector());
builder.addDependency(TxnServices.JBOSS_TXN_CONTEXT_XA_TERMINATOR, JBossContextXATerminator.class, wmService.getXaTerminatorInjector()).setInitialMode(ServiceController.Mode.ON_DEMAND).install();
WorkManagerStatisticsService wmStatsService = new WorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true);
serviceTarget.addService(ConnectorServices.WORKMANAGER_STATS_SERVICE.append(name), wmStatsService).addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), WorkManager.class, wmStatsService.getWorkManagerInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
DistributedWorkManagerStatisticsService dwmStatsService = new DistributedWorkManagerStatisticsService(context.getResourceRegistrationForUpdate(), name, true);
serviceTarget.addService(ConnectorServices.DISTRIBUTED_WORKMANAGER_STATS_SERVICE.append(name), dwmStatsService).addDependency(ConnectorServices.WORKMANAGER_SERVICE.append(name), DistributedWorkManager.class, dwmStatsService.getDistributedWorkManagerInjector()).setInitialMode(ServiceController.Mode.PASSIVE).install();
PathElement peDistributedWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "distributed");
PathElement peLocaldWm = PathElement.pathElement(org.jboss.as.connector.subsystems.resourceadapters.Constants.STATISTICS_NAME, "local");
final Resource wmResource = new IronJacamarResource.IronJacamarRuntimeResource();
if (!resource.hasChild(peLocaldWm))
resource.registerChild(peLocaldWm, wmResource);
final Resource dwmResource = new IronJacamarResource.IronJacamarRuntimeResource();
if (!resource.hasChild(peDistributedWm))
resource.registerChild(peDistributedWm, dwmResource);
}
Aggregations