use of org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition in project wildfly by wildfly.
the class ActivationSecurityUtil method isLegacySecurityRequired.
public static boolean isLegacySecurityRequired(Activation raxml) {
boolean required = false;
org.jboss.jca.common.api.metadata.resourceadapter.WorkManagerSecurity wmsecurity = raxml.getWorkManager() != null ? raxml.getWorkManager().getSecurity() : null;
if (wmsecurity != null && !isElytronEnabled(wmsecurity)) {
String domain = wmsecurity.getDomain();
required = domain != null && domain.trim().length() > 0;
}
if (!required) {
List<ConnectionDefinition> connDefs = raxml.getConnectionDefinitions();
if (connDefs != null) {
for (ConnectionDefinition cd : connDefs) {
Security cdsecurity = cd.getSecurity();
if (cdsecurity != null && !isElytronEnabled(cdsecurity)) {
String domain = cdsecurity.resolveSecurityDomain();
if (domain != null && domain.trim().length() > 0) {
required = true;
break;
}
}
}
}
}
return required;
}
use of org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition in project wildfly by wildfly.
the class RaOperationUtil method buildResourceAdaptersObject.
public static ModifiableResourceAdapter buildResourceAdaptersObject(final String id, final OperationContext context, ModelNode operation, String archiveOrModule) throws OperationFailedException {
Map<String, String> configProperties = new HashMap<>(0);
List<ConnectionDefinition> connectionDefinitions = new ArrayList<>(0);
List<AdminObject> adminObjects = new ArrayList<>(0);
String transactionSupportResolved = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, TRANSACTION_SUPPORT);
TransactionSupportEnum transactionSupport = operation.hasDefined(TRANSACTION_SUPPORT.getName()) ? TransactionSupportEnum.valueOf(ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, TRANSACTION_SUPPORT)) : null;
String bootstrapContext = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, BOOTSTRAP_CONTEXT);
List<String> beanValidationGroups = BEANVALIDATION_GROUPS.unwrap(context, operation);
boolean wmSecurity = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, WM_SECURITY);
WorkManager workManager = null;
if (wmSecurity) {
final boolean mappingRequired = ModelNodeUtil.getBooleanIfSetOrGetDefault(context, operation, WM_SECURITY_MAPPING_REQUIRED);
String domain;
final String elytronDomain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_ELYTRON_SECURITY_DOMAIN);
if (elytronDomain != null) {
domain = elytronDomain;
} else {
domain = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_SECURITY_DOMAIN);
}
final String defaultPrincipal = ModelNodeUtil.getResolvedStringIfSetOrGetDefault(context, operation, WM_SECURITY_DEFAULT_PRINCIPAL);
final List<String> defaultGroups = WM_SECURITY_DEFAULT_GROUPS.unwrap(context, operation);
final Map<String, String> groups = ModelNodeUtil.extractMap(operation, WM_SECURITY_MAPPING_GROUPS, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO);
final Map<String, String> users = ModelNodeUtil.extractMap(operation, WM_SECURITY_MAPPING_USERS, WM_SECURITY_MAPPING_FROM, WM_SECURITY_MAPPING_TO);
workManager = new WorkManagerImpl(new WorkManagerSecurityImpl(mappingRequired, domain, elytronDomain != null, defaultPrincipal, defaultGroups, users, groups));
}
ModifiableResourceAdapter ra;
ra = new ModifiableResourceAdapter(id, archiveOrModule, transactionSupport, connectionDefinitions, adminObjects, configProperties, beanValidationGroups, bootstrapContext, workManager);
return ra;
}
use of org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition in project wildfly by wildfly.
the class RaOperationUtil method installRaServices.
public static ServiceName installRaServices(OperationContext context, String name, ModifiableResourceAdapter resourceAdapter, final List<ServiceController<?>> newControllers) {
final ServiceTarget serviceTarget = context.getServiceTarget();
final ServiceController<?> resourceAdaptersService = context.getServiceRegistry(false).getService(ConnectorServices.RESOURCEADAPTERS_SERVICE);
if (resourceAdaptersService == null) {
newControllers.add(serviceTarget.addService(ConnectorServices.RESOURCEADAPTERS_SERVICE, new ResourceAdaptersService()).setInitialMode(ServiceController.Mode.ACTIVE).install());
}
ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, name);
final ServiceController<?> service = context.getServiceRegistry(true).getService(raServiceName);
if (service == null) {
ResourceAdapterService raService = new ResourceAdapterService(resourceAdapter, name);
ServiceBuilder builder = serviceTarget.addService(raServiceName, raService).setInitialMode(ServiceController.Mode.ACTIVE).addDependency(ConnectorServices.RESOURCEADAPTERS_SERVICE, ResourceAdaptersService.ModifiableResourceAdaptors.class, raService.getResourceAdaptersInjector()).addDependency(ConnectorServices.RESOURCEADAPTERS_SUBSYSTEM_SERVICE, CopyOnWriteArrayListMultiMap.class, raService.getResourceAdaptersMapInjector());
// add dependency on security domain service if applicable for recovery config
for (ConnectionDefinition cd : resourceAdapter.getConnectionDefinitions()) {
Security security = cd.getSecurity();
if (security != null) {
final boolean elytronEnabled = (security instanceof SecurityMetadata && ((SecurityMetadata) security).isElytronEnabled());
if (security.getSecurityDomain() != null) {
if (!elytronEnabled) {
builder.requires(SECURITY_DOMAIN_SERVICE.append(security.getSecurityDomain()));
} else {
builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, security.getSecurityDomain(), AuthenticationContext.class));
}
}
if (security.getSecurityDomainAndApplication() != null) {
if (!elytronEnabled) {
builder.requires(SECURITY_DOMAIN_SERVICE.append(security.getSecurityDomainAndApplication()));
} else {
builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, security.getSecurityDomainAndApplication(), AuthenticationContext.class));
}
}
if (cd.getRecovery() != null && cd.getRecovery().getCredential() != null && cd.getRecovery().getCredential().getSecurityDomain() != null) {
if (!elytronEnabled) {
builder.requires(SECURITY_DOMAIN_SERVICE.append(cd.getRecovery().getCredential().getSecurityDomain()));
} else {
builder.requires(context.getCapabilityServiceName(AUTHENTICATION_CONTEXT_CAPABILITY, cd.getRecovery().getCredential().getSecurityDomain(), AuthenticationContext.class));
}
}
}
}
if (resourceAdapter.getWorkManager() != null) {
final WorkManagerSecurity workManagerSecurity = resourceAdapter.getWorkManager().getSecurity();
if (workManagerSecurity != null) {
final boolean elytronEnabled = (workManagerSecurity instanceof org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity) && ((org.jboss.as.connector.metadata.api.resourceadapter.WorkManagerSecurity) workManagerSecurity).isElytronEnabled();
final String securityDomainName = workManagerSecurity.getDomain();
if (securityDomainName != null) {
if (!elytronEnabled) {
builder.requires(SECURITY_DOMAIN_SERVICE.append(securityDomainName));
} else {
builder.requires(context.getCapabilityServiceName(ELYTRON_SECURITY_DOMAIN_CAPABILITY, securityDomainName, SecurityDomain.class));
}
}
}
}
newControllers.add(builder.install());
}
return raServiceName;
}
use of org.jboss.jca.common.api.metadata.resourceadapter.ConnectionDefinition 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.jca.common.api.metadata.resourceadapter.ConnectionDefinition in project wildfly by wildfly.
the class ExternalPooledConnectionFactoryService method createService.
private void createService(ServiceTarget serviceTarget, ServiceContainer container) throws Exception {
InputStream is = null;
InputStream isIj = null;
// Properties for the resource adapter
List<ConfigProperty> properties = new ArrayList<ConfigProperty>();
try {
StringBuilder connectorClassname = new StringBuilder();
StringBuilder connectorParams = new StringBuilder();
TransportConfigOperationHandlers.processConnectorBindings(Arrays.asList(connectors), socketBindings, outboundSocketBindings);
for (TransportConfiguration tc : connectors) {
if (tc == null) {
throw MessagingLogger.ROOT_LOGGER.connectorNotDefined("null");
}
if (connectorClassname.length() > 0) {
connectorClassname.append(",");
connectorParams.append(",");
}
connectorClassname.append(tc.getFactoryClassName());
Map<String, Object> params = tc.getParams();
boolean multiple = false;
for (Map.Entry<String, Object> entry : params.entrySet()) {
if (multiple) {
connectorParams.append(";");
}
connectorParams.append(entry.getKey()).append("=").append(entry.getValue());
multiple = true;
}
}
if (connectorClassname.length() > 0) {
properties.add(simpleProperty15(CONNECTOR_CLASSNAME, STRING_TYPE, connectorClassname.toString()));
}
if (connectorParams.length() > 0) {
properties.add(simpleProperty15(CONNECTION_PARAMETERS, STRING_TYPE, connectorParams.toString()));
}
if (discoveryGroupConfiguration != null) {
final String dgName = discoveryGroupConfiguration.getName();
final String key = "discovery" + dgName;
final DiscoveryGroupConfiguration config;
if (commandDispatcherFactories.containsKey(key)) {
BroadcastCommandDispatcherFactory commandDispatcherFactory = commandDispatcherFactories.get(key).get();
String clusterName = clusterNames.get(key);
config = JGroupsDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, discoveryGroupConfiguration, commandDispatcherFactory, clusterName);
} else {
final SocketBinding binding = groupBindings.get(key).get();
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(dgName);
}
config = SocketDiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, discoveryGroupConfiguration, binding);
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
}
BroadcastEndpointFactory bgCfg = config.getBroadcastEndpointFactory();
if (bgCfg instanceof UDPBroadcastEndpointFactory) {
UDPBroadcastEndpointFactory udpCfg = (UDPBroadcastEndpointFactory) bgCfg;
properties.add(simpleProperty15(GROUP_ADDRESS, STRING_TYPE, udpCfg.getGroupAddress()));
properties.add(simpleProperty15(GROUP_PORT, INTEGER_TYPE, "" + udpCfg.getGroupPort()));
properties.add(simpleProperty15(DISCOVERY_LOCAL_BIND_ADDRESS, STRING_TYPE, "" + udpCfg.getLocalBindAddress()));
} else if (bgCfg instanceof CommandDispatcherBroadcastEndpointFactory) {
String external = "/" + name + ":discovery" + dgName;
properties.add(simpleProperty15(JGROUPS_CHANNEL_NAME, STRING_TYPE, jgroupsClusterName));
properties.add(simpleProperty15(JGROUPS_CHANNEL_REF_NAME, STRING_TYPE, external));
}
properties.add(simpleProperty15(DISCOVERY_INITIAL_WAIT_TIMEOUT, LONG_TYPE, "" + config.getDiscoveryInitialWaitTimeout()));
properties.add(simpleProperty15(REFRESH_TIMEOUT, LONG_TYPE, "" + config.getRefreshTimeout()));
}
boolean hasReconnect = false;
final List<ConfigProperty> inboundProperties = new ArrayList<>();
final List<ConfigProperty> outboundProperties = new ArrayList<>();
final String reconnectName = ConnectionFactoryAttributes.Pooled.RECONNECT_ATTEMPTS_PROP_NAME;
for (PooledConnectionFactoryConfigProperties adapterParam : adapterParams) {
hasReconnect |= reconnectName.equals(adapterParam.getName());
ConfigProperty p = simpleProperty15(adapterParam.getName(), adapterParam.getType(), adapterParam.getValue());
if (adapterParam.getName().equals(REBALANCE_CONNECTIONS_PROP_NAME)) {
boolean rebalanceConnections = Boolean.parseBoolean(adapterParam.getValue());
if (rebalanceConnections) {
inboundProperties.add(p);
}
} else {
if (null == adapterParam.getConfigType()) {
properties.add(p);
} else {
switch(adapterParam.getConfigType()) {
case INBOUND:
inboundProperties.add(p);
break;
case OUTBOUND:
outboundProperties.add(p);
break;
default:
properties.add(p);
break;
}
}
}
}
// The default -1, which will hang forever until a server appears
if (!hasReconnect) {
properties.add(simpleProperty15(reconnectName, Integer.class.getName(), DEFAULT_MAX_RECONNECTS));
}
configureCredential(properties);
WildFlyRecoveryRegistry.container = container;
OutboundResourceAdapter outbound = createOutbound(outboundProperties);
InboundResourceAdapter inbound = createInbound(inboundProperties);
ResourceAdapter ra = createResourceAdapter15(properties, outbound, inbound);
Connector cmd = createConnector15(ra);
TransactionSupportEnum transactionSupport = getTransactionSupport(txSupport);
ConnectionDefinition common = createConnDef(transactionSupport, bindInfo.getBindName(), minPoolSize, maxPoolSize, managedConnectionPoolClassName, enlistmentTrace);
Activation activation = createActivation(common, transactionSupport);
ResourceAdapterActivatorService activator = new ResourceAdapterActivatorService(cmd, activation, ExternalPooledConnectionFactoryService.class.getClassLoader(), name);
activator.setBindInfo(bindInfo);
activator.setCreateBinderService(createBinderService);
activator.addJndiAliases(jndiAliases);
final ServiceBuilder sb = Services.addServerExecutorDependency(serviceTarget.addService(getResourceAdapterActivatorsServiceName(name), activator), activator.getExecutorServiceInjector()).addDependency(ConnectorServices.IRONJACAMAR_MDR, AS7MetadataRepository.class, activator.getMdrInjector()).addDependency(ConnectorServices.RA_REPOSITORY_SERVICE, ResourceAdapterRepository.class, activator.getRaRepositoryInjector()).addDependency(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE, ManagementRepository.class, activator.getManagementRepositoryInjector()).addDependency(ConnectorServices.RESOURCE_ADAPTER_REGISTRY_SERVICE, ResourceAdapterDeploymentRegistry.class, activator.getRegistryInjector()).addDependency(ConnectorServices.TRANSACTION_INTEGRATION_SERVICE, TransactionIntegration.class, activator.getTxIntegrationInjector()).addDependency(ConnectorServices.CONNECTOR_CONFIG_SERVICE, JcaSubsystemConfiguration.class, activator.getConfigInjector()).addDependency(ConnectorServices.CCM_SERVICE, CachedConnectionManager.class, activator.getCcmInjector());
sb.requires(NamingService.SERVICE_NAME);
sb.requires(capabilityServiceSupport.getCapabilityServiceName(MessagingServices.LOCAL_TRANSACTION_PROVIDER_CAPABILITY));
sb.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append("default"));
sb.setInitialMode(ServiceController.Mode.PASSIVE).install();
// Mock the deployment service to allow it to start
serviceTarget.addService(ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(name), Service.NULL).install();
} finally {
if (is != null) {
is.close();
}
if (isIj != null) {
isIj.close();
}
}
}
Aggregations