@Override protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { Map<String, Object> vaultOptions = new HashMap<String, Object>(); ModelNode vaultClassNode = CODE.resolveModelAttribute(context, model); String vaultClass = vaultClassNode.getType() == ModelType.UNDEFINED ? null : vaultClassNode.asString(); if (operation.hasDefined(Constants.VAULT_OPTIONS)) { for (Map.Entry<String,String> vaultOption : OPTIONS.unwrap(context,model).entrySet()) { vaultOptions.put(vaultOption.getKey(), vaultOption.getValue()); } } // add security vault service if (vaultClass != null || !vaultOptions.isEmpty()) { final SecurityVaultService vaultService = new SecurityVaultService(vaultClass, vaultOptions); context.getServiceTarget() .addService(SecurityVaultService.SERVICE_NAME, vaultService) .setInitialMode(ServiceController.Mode.ACTIVE).install(); } } }
break; default: throw ParseUtils.unexpectedAttribute(reader, i); ParseUtils.requireNoContent(reader); break; final String[] array = requireAttributes(reader, org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), org.jboss.as.controller.parsing.Attribute.VALUE.getLocalName()); MailServerDefinition.PROPERTIES.parseAndAddParameterElement(array[0], array[1], operation, reader); ParseUtils.requireNoContent(reader); break; operation.get(OP_ADDR).set(address.toModelNode());
if (dataSourceNode.hasDefined(CONNECTION_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(CONNECTION_PROPERTIES.getName()).asPropertyList()) { if (dataSourceNode.hasDefined(XADATASOURCE_PROPERTIES.getName())) { for (Property prop : dataSourceNode.get(XADATASOURCE_PROPERTIES.getName()).asPropertyList()) { CONNECTION_LISTENER_PROPERTIES.isMarshallable(dataSourceNode); if (isXADataSource) { poolRequired = poolRequired CAPACITY_INCREMENTER_PROPERTIES.isMarshallable(dataSourceNode) || CAPACITY_DECREMENTER_CLASS.isMarshallable(dataSourceNode) || CAPACITY_DECREMENTER_PROPERTIES.isMarshallable(dataSourceNode); poolRequired = poolRequired || capacityRequired; if (poolRequired) { if (dataSourceNode.hasDefined(CONNECTION_LISTENER_PROPERTIES.getName())) { for (Property connectionProperty : dataSourceNode.get(CONNECTION_LISTENER_PROPERTIES.getName()) CAPACITY_INCREMENTER_PROPERTIES.marshallAsElement(dataSourceNode, writer); CAPACITY_DECREMENTER_PROPERTIES.marshallAsElement(dataSourceNode, writer); REAUTHPLUGIN_PROPERTIES.isMarshallable(dataSourceNode); if (securityRequired) { writer.writeStartElement(DataSource.Tag.SECURITY.getLocalName()); if (dataSourceNode.hasDefined(REAUTHPLUGIN_PROPERTIES.getName())) {
private void writeConDef(XMLExtendedStreamWriter streamWriter, ModelNode conDef, final String poolName, final boolean isXa) throws XMLStreamException { streamWriter.writeStartElement(Activation.Tag.CONNECTION_DEFINITION.getLocalName()); CLASS_NAME.marshallAsAttribute(conDef, streamWriter); JNDINAME.marshallAsAttribute(conDef, streamWriter); ENABLED.marshallAsAttribute(conDef, streamWriter); CAPACITY_INCREMENTER_PROPERTIES.isMarshallable(conDef) || CAPACITY_DECREMENTER_CLASS.isMarshallable(conDef) || CAPACITY_DECREMENTER_PROPERTIES.isMarshallable(conDef); poolRequired = poolRequired || capacityRequired; if (conDef.hasDefined(INTERLEAVING.getName()) && conDef.get(INTERLEAVING.getName()).asBoolean()) { CAPACITY_INCREMENTER_PROPERTIES.marshallAsElement(conDef, streamWriter); CAPACITY_DECREMENTER_PROPERTIES.marshallAsElement(conDef, streamWriter); || conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName()) || conDef.hasDefined(NO_RECOVERY.getName()) streamWriter.writeEndElement(); if (conDef.hasDefined(RECOVERLUGIN_CLASSNAME.getName()) || conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())) { if (conDef.hasDefined(RECOVERLUGIN_PROPERTIES.getName())) { for (Property property : conDef.get(RECOVERLUGIN_PROPERTIES.getName()).asPropertyList()) {
final ModelNode operation = new ModelNode(); operation.get(OP).set(ADD); boolean enabled = Defaults.ENABLED.booleanValue(); final int count = reader.getAttributeCount(); for (int i = 0; i < count; i++) { if (!isNoNamespaceAttribute(reader, i)) { throw unexpectedAttribute(reader, i); final String jndiName = rawAttributeText(reader, JNDI_NAME.getXmlName()); JNDI_NAME.parseAndSetParameter(jndiName, operation, reader); break; if (Constants.STATISTICS_ENABLED.getName().equals(reader.getAttributeLocalName(i))) { final String value = rawAttributeText(reader, Constants.STATISTICS_ENABLED.getXmlName()); if (value != null) { throw ParseUtils.unexpectedAttribute(reader, i); final ModelNode configAddress = dsAddress.clone(); configAddress.add(XADATASOURCE_PROPERTIES.getName(), name); configAddress.protect();
private void parseProperties(String childElementName, XMLExtendedStreamReader reader, ModelNode node, PropertiesAttributeDefinition attribute) throws XMLStreamException { while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); if (childElementName.equals(element.getLocalName())) { final String[] array = requireAttributes(reader, org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), org.jboss.as.controller.parsing.Attribute.VALUE.getLocalName()); attribute.parseAndAddParameterElement(array[0], array[1], node, reader); } else { throw unexpectedElement(reader); } requireNoContent(reader); } }
private void parsePolicy(final XMLExtendedStreamReader reader, final ModelNode operation) throws XMLStreamException { final int cnt = reader.getAttributeCount(); for (int i = 0; i < cnt; i++) { final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i)); switch (attribute) { case NAME: { String policy = rawAttributeText(reader, attribute.getLocalName()); ((SimpleAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY.getAttribute()).parseAndSetParameter(policy, operation, reader); break; } default: { throw unexpectedAttribute(reader, i); } } } while (reader.hasNext() && reader.nextTag() != END_ELEMENT) { final Element element = Element.forName(reader.getLocalName()); switch (element) { case OPTION: { requireSingleAttribute(reader, "name"); final String name = rawAttributeText(reader, "name"); String value = rawElementText(reader); final String trimmed = value == null ? null : value.trim(); ((PropertiesAttributeDefinition) JcaDistributedWorkManagerDefinition.DWmParameters.POLICY_OPTIONS.getAttribute()).parseAndAddParameterElement(name, trimmed, operation, reader); break; } } // Handle elements } }
private Map<String, String> unwrap(final ModelNode model) { if (!model.hasDefined(PARAMETERS.getName())) { return Collections.emptyMap(); } ModelNode modelProps = model.get(PARAMETERS.getName()); Map<String, String> props = new HashMap<String, String>(); for (Property p : modelProps.asPropertyList()) { props.put(p.getName(), p.getValue().asString()); } return props; } }
@Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { ModelNode codeNode = VaultResourceDefinition.CODE.resolveModelAttribute(context, model); ModelNode moduleNode = VaultResourceDefinition.MODULE.resolveModelAttribute(context, model); String vaultClass = codeNode.isDefined() ? codeNode.asString() : null; String module = moduleNode.isDefined() ? moduleNode.asString() : null; if (vaultReader != null) { final Map<String, Object> vaultOptions = new HashMap<String, Object>(); if (operation.hasDefined(VaultResourceDefinition.VAULT_OPTIONS.getName())) { for (Map.Entry<String, String> vaultOption : VaultResourceDefinition.VAULT_OPTIONS.unwrap(context, model).entrySet()) { vaultOptions.put(vaultOption.getKey(), vaultOption.getValue()); } } vaultReader.createVault(vaultClass, module, vaultOptions); // WFLY-1904 if any system properties were not resolved due to needing vault resolution, // resolve them now final SystemPropertyDeferredProcessor deferredResolver = context.getAttachment(SystemPropertyDeferredProcessor.ATTACHMENT_KEY); if (deferredResolver != null) { deferredResolver.processDeferredProperties(context); } } }
private void handleDatasourceAttribute(final String attributeName, final OperationContext context, final DataSource dataSource) { if (attributeName.equals(Constants.CONNECTION_URL.getName())) { setStringIfNotNull(context, dataSource.getConnectionUrl()); } else if (attributeName.equals(Constants.CONNECTION_PROPERTIES.getName())) { final Map<String, String> propertiesMap = dataSource.getConnectionProperties(); if (propertiesMap == null) { } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_INCREMENTER_PROPERTIES.getName())) { Pool pool = dataSource.getPool(); if (pool == null || pool.getCapacity() == null || pool.getCapacity().getIncrementer() == null) } else if (attributeName.equals(org.jboss.as.connector.subsystems.common.pool.Constants.CAPACITY_DECREMENTER_PROPERTIES.getName())) { Pool pool = dataSource.getPool(); if (pool == null || pool.getCapacity() == null || pool.getCapacity().getDecrementer() == null) } else if (attributeName.equals(Constants.REAUTHPLUGIN_PROPERTIES.getName())) { if (dataSource.getSecurity() == null) { return; } else if (attributeName.equals(Constants.EXCEPTION_SORTER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } else if (attributeName.equals(Constants.STALE_CONNECTION_CHECKER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return; } else if (attributeName.equals(Constants.VALID_CONNECTION_CHECKER_PROPERTIES.getName())) { if (dataSource.getValidation() == null) { return;
static void populateAddModel(final ModelNode operation, final ModelNode modelNode, final String connectionPropertiesProp, final SimpleAttributeDefinition[] attributes, PropertiesAttributeDefinition[] properties) throws OperationFailedException { if (operation.hasDefined(connectionPropertiesProp)) { for (Property property : operation.get(connectionPropertiesProp).asPropertyList()) { modelNode.get(connectionPropertiesProp, property.getName()).set(property.getValue().asString()); } } for (final SimpleAttributeDefinition attribute : attributes) { attribute.validateAndSet(operation, modelNode); } for (final PropertiesAttributeDefinition attribute : properties) { attribute.validateAndSet(operation, modelNode); } }
@Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { context.startSubsystemElement(Namespace.CURRENT.getUriString(), false); ModelNode model = context.getModelNode(); if (model.hasDefined(ModelConstants.CONFIGURATION)) { ModelNode configuration = model.get(ModelConstants.CONFIGURATION); for (String pid : new TreeSet<String>(configuration.keys())) { writer.writeStartElement(Element.CONFIGURATION.getLocalName()); writer.writeAttribute(Attribute.PID.getLocalName(), pid); ConfigurationResource.ENTRIES.marshallAsElement(configuration.get(pid), writer); writer.writeEndElement(); } } writer.writeEndElement(); }
String httpServerFactory = HTTP_SERVER_FACTORY.resolveModelAttribute(context, model).asString(); serviceBuilder.addDependency(context.getCapabilityServiceName( buildDynamicCapabilityName(HTTP_SERVER_MECHANISM_FACTORY_CAPABILITY, httpServerFactory), HttpServerAuthenticationMechanismFactory.class), HttpServerAuthenticationMechanismFactory.class, factoryInjector); if (model.hasDefined(ElytronDescriptionConstants.FILTERS)) { Predicate<String> filter = null; List<ModelNode> nodes = model.require(ElytronDescriptionConstants.FILTERS).asList(); for (ModelNode current : nodes) { Predicate<String> currentFilter = (String s) -> true; String patternFilter = PATTERN_FILTER.resolveModelAttribute(context, current).asStringOrNull(); if (patternFilter != null) { final Pattern pattern = Pattern.compile(patternFilter); currentFilter = ENABLING.resolveModelAttribute(context, current).asBoolean() ? currentFilter : currentFilter.negate(); filter = filter == null ? currentFilter : filter.or(currentFilter); final Map<String, String> propertiesMap = PROPERTIES.unwrap(context, model); return () -> { HttpServerAuthenticationMechanismFactory factory = factoryInjector.getValue();
switch (attribute) { case CLASS_NAME: { requireSingleAttribute(reader, attribute.getLocalName()); final String value = reader.getAttributeValue(0); extensionClassName.parseAndSetParameter(value, operation, reader); break; while (reader.hasNext()) { switch (reader.nextTag()) { case END_ELEMENT: { if (reader.getLocalName().equals(enclosingTag)) { } else { if (Extension.Tag.forName(reader.getLocalName()) == Extension.Tag.UNKNOWN) { throw ParseUtils.unexpectedEndElement(reader); switch (Extension.Tag.forName(reader.getLocalName())) { case CONFIG_PROPERTY: { requireSingleAttribute(reader, "name"); final String name = reader.getAttributeValue(0); String value = rawElementText(reader); final String trimmed = value == null ? null : value.trim(); extensionProperties.parseAndAddParameterElement(name, trimmed, operation, reader); break;
private static CustomServerConfig readCustomServerConfig(final String protocol, final OperationContext operationContext, final ModelNode model) throws OperationFailedException { final ModelNode socketModel = MailServerDefinition.OUTBOUND_SOCKET_BINDING_REF_OPTIONAL.resolveModelAttribute(operationContext, model); final String socket = socketModel.isDefined() ? socketModel.asString() : null; final Credentials credentials = readCredentials(operationContext, model); boolean ssl = MailServerDefinition.SSL.resolveModelAttribute(operationContext, model).asBoolean(); boolean tls = MailServerDefinition.TLS.resolveModelAttribute(operationContext, model).asBoolean(); Map<String, String> properties = MailServerDefinition.PROPERTIES.unwrap(operationContext, model); return new CustomServerConfig(protocol, socket, credentials, ssl, tls, properties); }
@Override protected void performBoottime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { ModelNode model = resource.getModel(); ModelNode defaultAuthenticationContext = DEFAULT_AUTHENTICATION_CONTEXT.resolveModelAttribute(context, model); AUTHENITCATION_CONTEXT_PROCESSOR.setDefaultAuthenticationContext(defaultAuthenticationContext.isDefined() ? defaultAuthenticationContext.asString() : null); Map<String,String> securityProperties = SECURITY_PROPERTIES.unwrap(context, model); final String defaultSSLContext = DEFAULT_SSL_CONTEXT.resolveModelAttribute(context, model).asStringOrNull(); ServiceTarget target = context.getServiceTarget(); installService(SecurityPropertyService.SERVICE_NAME, new SecurityPropertyService(securityProperties), target); .setInitialMode(Mode.ACTIVE); String initialProviders = INITIAL_PROVIDERS.resolveModelAttribute(context, model).asStringOrNull(); if (initialProviders != null) { builder.addDependency( context.getCapabilityServiceName(PROVIDERS_CAPABILITY, initialProviders, Provider[].class), Provider[].class, prs.getInitialProivders()); if (finalProviders != null) { builder.addDependency( context.getCapabilityServiceName(PROVIDERS_CAPABILITY, finalProviders, Provider[].class), Provider[].class, prs.getFinalProviders());
private void parseConfigurations(XMLExtendedStreamReader reader, PathAddress parent, List<ModelNode> operations) throws XMLStreamException { // Handle attributes String pid = ParseUtils.requireAttributes(reader, Attribute.PID.getLocalName())[0]; ModelNode operation = Util.createAddOperation(parent.append(ModelConstants.CONFIGURATION, pid)); operations.add(operation); // Handle elements while (reader.nextTag() != END_ELEMENT) { switch (Namespace.forUri(reader.getNamespaceURI())) { case VERSION_1_0: { final Element element = Element.forName(reader.getLocalName()); if (element == Element.PROPERTY) { final String[] array = requireAttributes(reader, org.jboss.as.controller.parsing.Attribute.NAME.getLocalName(), org.jboss.as.controller.parsing.Attribute.VALUE.getLocalName()); ConfigurationResource.ENTRIES.parseAndAddParameterElement(array[0], array[1], operation, reader); ParseUtils.requireNoContent(reader); break; } else { throw unexpectedElement(reader); } } default: throw unexpectedElement(reader); } } } }
if (node.hasDefined(CLIENT_ALIAS)) { value = JSSEResourceDefinition.CLIENT_ALIAS.resolveModelAttribute(context, node).asString(); jsseSecurityDomain.setClientAlias(value); if (node.hasDefined(SERVER_ALIAS)) { value = JSSEResourceDefinition.SERVER_ALIAS.resolveModelAttribute(context, node).asString(); jsseSecurityDomain.setServerAlias(value); if (node.hasDefined(CLIENT_AUTH)) { boolean clientAuth = JSSEResourceDefinition.CLIENT_AUTH.resolveModelAttribute(context, node).asBoolean(); jsseSecurityDomain.setClientAuth(clientAuth); if (node.hasDefined(ADDITIONAL_PROPERTIES)) { Properties properties = new Properties(); properties.putAll(JSSEResourceDefinition.ADDITIONAL_PROPERTIES.unwrap(context, node)); jsseSecurityDomain.setAdditionalProperties(properties);
@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); 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()); 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());
private void writeProviders(XMLExtendedStreamWriter writer, ModelNode spiElements) throws XMLStreamException { if (!spiElements.get(ProviderResourceDefinition.TAG_NAME).isDefined()) { return; } for (Property provider : spiElements.get(ProviderResourceDefinition.TAG_NAME).asPropertyList()) { writer.writeStartElement(ProviderResourceDefinition.TAG_NAME); writer.writeAttribute("name", provider.getName()); ModelNode providerElements = provider.getValue(); ENABLED.marshallAsAttribute(providerElements, writer); PROPERTIES.marshallAsElement(providerElements, writer); writer.writeEndElement(); } }