static String asStringIfDefined(OperationContext context, SimpleAttributeDefinition attributeDefinition, ModelNode model) throws OperationFailedException { ModelNode value = attributeDefinition.resolveModelAttribute(context, model); if (value.isDefined()) { return value.asString(); } return null; } }
public WebSocketInfo getConfig(final OperationContext context, final ModelNode model) throws OperationFailedException { if (!model.isDefined()) { return null; } boolean dispatchToWorker = DISPATCH_TO_WORKER.resolveModelAttribute(context, model).asBoolean(); String bufferPool = BUFFER_POOL.resolveModelAttribute(context, model).asString(); String worker = WORKER.resolveModelAttribute(context, model).asString(); boolean perMessageDeflate = PER_MESSAGE_DEFLATE.resolveModelAttribute(context, model).asBoolean(); int deflaterLevel = DEFLATER_LEVEL.resolveModelAttribute(context, model).asInt(); return new WebSocketInfo(worker, bufferPool, dispatchToWorker, perMessageDeflate, deflaterLevel); }
public static Boolean getBooleanIfSetOrGetDefault(final OperationContext context, final ModelNode dataSourceNode, final SimpleAttributeDefinition key) throws OperationFailedException { ModelNode resolvedNode = key.resolveModelAttribute(context, dataSourceNode); return resolvedNode.isDefined() ? resolvedNode.asBoolean() : null; }
@Override protected void performBoottime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final Boolean enableByDefault = EJB3IIOPResourceDefinition.ENABLE_BY_DEFAULT.resolveModelAttribute(context, model).asBoolean(); final Boolean useQualifiedName = EJB3IIOPResourceDefinition.USE_QUALIFIED_NAME.resolveModelAttribute(context, model).asBoolean(); final IIOPSettingsService settingsService = new IIOPSettingsService(enableByDefault, useQualifiedName); context.addStep(new AbstractDeploymentChainStep() { protected void execute(DeploymentProcessorTarget processorTarget) { ROOT_LOGGER.debug("Adding EJB IIOP support"); processorTarget.addDeploymentProcessor(EJB3Extension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EJB_IIOP, new EjbIIOPDeploymentUnitProcessor(settingsService)); } }, OperationContext.Stage.RUNTIME); context.getServiceTarget().addService(IIOPSettingsService.SERVICE_NAME, settingsService).install(); }
@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(); } } }
private Object createSimpleBinding(OperationContext context, ModelNode model) throws OperationFailedException { final String value = NamingBindingResourceDefinition.VALUE.resolveModelAttribute(context, model).asString(); final String type; if (model.hasDefined(TYPE)) { type = NamingBindingResourceDefinition.TYPE.resolveModelAttribute(context, model).asString(); } else { type = null; } return coerceToType(value, type); }
private static ServerConfig readServerConfig(final OperationContext operationContext, final ModelNode model) throws OperationFailedException { final String socket = MailServerDefinition.OUTBOUND_SOCKET_BINDING_REF.resolveModelAttribute(operationContext, model).asString(); final Credentials credentials = readCredentials(operationContext, model); boolean ssl = MailServerDefinition.SSL.resolveModelAttribute(operationContext, model).asBoolean(); boolean tls = MailServerDefinition.TLS.resolveModelAttribute(operationContext, model).asBoolean(); return new ServerConfig(socket, credentials, ssl, tls, null); }
private static String extractCode(OperationContext context, ModelNode node, Map<String, String> substitutions) throws OperationFailedException { String code = LoginModuleResourceDefinition.CODE.resolveModelAttribute(context, node).asString(); if (substitutions.containsKey(code)) { code = substitutions.get(code); } return code; }
private void applyModelToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode model) throws OperationFailedException { final String poolName = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue(); final ServiceName serviceName = StrictMaxPoolConfigService.EJB_POOL_CONFIG_BASE_SERVICE_NAME.append(poolName); final ServiceRegistry registry = context.getServiceRegistry(true); ServiceController<?> sc = registry.getService(serviceName); if (sc != null) { StrictMaxPoolConfigService smpc = (StrictMaxPoolConfigService) sc.getService(); if (smpc != null) { if (StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.getName().equals(attributeName)) { int maxPoolSize = StrictMaxPoolResourceDefinition.MAX_POOL_SIZE.resolveModelAttribute(context, model).asInt(-1); smpc.setMaxPoolSize(maxPoolSize); } else if (StrictMaxPoolResourceDefinition.DERIVE_SIZE.getName().equals(attributeName)) { StrictMaxPoolConfigService.Derive derive = StrictMaxPoolResourceDefinition.parseDeriveSize(context, model); smpc.setDerive(derive); } else if (StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.getName().equals(attributeName)) { long timeout = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT.resolveModelAttribute(context, model).asLong(); smpc.setTimeout(timeout); } else if (StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.getName().equals(attributeName)) { String timeoutUnit = StrictMaxPoolResourceDefinition.INSTANCE_ACQUISITION_TIMEOUT_UNIT.resolveModelAttribute(context, model).asString(); smpc.setTimeoutUnit(TimeUnit.valueOf(timeoutUnit)); } } } }
@Override void applySetting(final IIOPSettingsService service, OperationContext context, final ModelNode model) throws OperationFailedException { final boolean value = ENABLE_BY_DEFAULT.resolveModelAttribute(context, model).asBoolean(); service.setUseQualifiedName(value); } });
@Override protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { super.populateModel(context, operation, resource); ModelNode model = resource.getModel(); boolean enableJacc = false; if (model.hasDefined(ENABLE_JACC.getName())) { enableJacc = ENABLE_JACC.resolveModelAttribute(context, model).asBoolean(); } knownApplicationSecurityDomains.add(new ApplicationSecurityDomainConfig(context.getCurrentAddressValue(), enableJacc)); }
public static Long getLongIfSetOrGetDefault(final OperationContext context, final ModelNode dataSourceNode, final SimpleAttributeDefinition key) throws OperationFailedException { ModelNode resolvedNode = key.resolveModelAttribute(context, dataSourceNode); return resolvedNode.isDefined() ? resolvedNode.asLong() : null; }
protected void performBoottime(final OperationContext context, ModelNode operation, final ModelNode model) throws OperationFailedException { final String defaultDataStore = TimerServiceResourceDefinition.DEFAULT_DATA_STORE.resolveModelAttribute(context, model).asString(); final String threadPoolName = TimerServiceResourceDefinition.THREAD_POOL_NAME.resolveModelAttribute(context, model).asString(); final ServiceName threadPoolServiceName = EJB3SubsystemModel.BASE_THREAD_POOL_SERVICE_NAME.append(threadPoolName); context.addStep(new AbstractDeploymentChainStep() { protected void execute(DeploymentProcessorTarget processorTarget) { ROOT_LOGGER.debug("Configuring timers"); //we only add the timer service DUP's when the timer service in enabled in XML processorTarget.addDeploymentProcessor(EJB3Extension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_TIMEOUT_ANNOTATION, new TimerServiceAnnotationProcessor()); processorTarget.addDeploymentProcessor(EJB3Extension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_AROUNDTIMEOUT_ANNOTATION, new AroundTimeoutAnnotationParsingProcessor()); processorTarget.addDeploymentProcessor(EJB3Extension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EJB_TIMER_METADATA_MERGE, new TimerMethodMergingProcessor()); processorTarget.addDeploymentProcessor(EJB3Extension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_EJB_TIMER_SERVICE, new TimerServiceDeploymentProcessor(threadPoolServiceName, defaultDataStore)); } }, OperationContext.Stage.RUNTIME); context.getServiceTarget().addService(TimerServiceDeploymentProcessor.TIMER_SERVICE_NAME, new TimerValueService()) .install(); }
public static List<GlobalModule> createModuleList(final OperationContext context, final ModelNode globalMods) throws OperationFailedException { final List<GlobalModule> ret = new ArrayList<>(); if (globalMods.isDefined()) { for (final ModelNode module : globalMods.asList()) { String name = NAME_AD.resolveModelAttribute(context, module).asString(); String slot = SLOT_AD.resolveModelAttribute(context, module).asString(); boolean annotations = ANNOTATIONS_AD.resolveModelAttribute(context, module).asBoolean(); boolean services = SERVICES_AD.resolveModelAttribute(context, module).asBoolean(); boolean metaInf = META_INF_AD.resolveModelAttribute(context, module).asBoolean(); ret.add(new GlobalModule(ModuleIdentifier.create(name, slot), annotations, services, metaInf)); } } return ret; }
public static String getResolvedStringIfSetOrGetDefault(final OperationContext context, final ModelNode dataSourceNode, final SimpleAttributeDefinition key) throws OperationFailedException { ModelNode resolvedNode = key.resolveModelAttribute(context, dataSourceNode); String resolvedString = resolvedNode.isDefined() ? resolvedNode.asString() : null; if (resolvedString != null && resolvedString.trim().length() == 0) { resolvedString = null; } return resolvedString; }
@Override protected Object[] getParameters(OperationContext context, ModelNode operation) { Object[] parameters = null; try { if (operation.hasDefined(USERNAME.getName()) || operation.hasDefined(PASSWORD.getName())) { parameters = new Object[2]; parameters[0] = USERNAME.resolveModelAttribute(context, operation).asString(); parameters[1] = PASSWORD.resolveModelAttribute(context, operation).asString(); } } catch (OperationFailedException ofe) { //just return null } return parameters; }
@Override @SuppressWarnings("unchecked") protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { String datasourceName = context.getCurrentAddressValue(); ModelNode factoryModel = AbstractDataSourceDefinition.CONNECTION_FACTORY_ATTRIBUTE.resolveModelAttribute(context, model); AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = AbstractDataSourceOperations.connectionFactoryConfiguration(context, factoryModel); ModelNode poolModel = AbstractDataSourceDefinition.CONNECTION_POOL_ATTRIBUTE.resolveModelAttribute(context, model); AgroalConnectionPoolConfigurationSupplier connectionPoolConfiguration = AbstractDataSourceOperations.connectionPoolConfiguration(context, poolModel); connectionPoolConfiguration.connectionFactoryConfiguration(connectionFactoryConfiguration); AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier(); dataSourceConfiguration.connectionPoolConfiguration(connectionPoolConfiguration); dataSourceConfiguration.metricsEnabled(AbstractDataSourceDefinition.STATISTICS_ENABLED_ATTRIBUTE.resolveModelAttribute(context, model).asBoolean()); String jndiName = AbstractDataSourceDefinition.JNDI_NAME_ATTRIBUTE.resolveModelAttribute(context, model).asString(); boolean jta = DataSourceDefinition.JTA_ATTRIBUTE.resolveModelAttribute(context, model).asBoolean(); boolean connectable = DataSourceDefinition.CONNECTABLE_ATTRIBUTE.resolveModelAttribute(context, model).asBoolean(); String driverName = AbstractDataSourceDefinition.DRIVER_ATTRIBUTE.resolveModelAttribute(context, factoryModel).asString(); DataSourceService dataSourceService = new DataSourceService(datasourceName, jndiName, jta, connectable, false, dataSourceConfiguration); CapabilityServiceBuilder<AgroalDataSource> serviceBuilder = context.getCapabilityServiceTarget().addCapability(AbstractDataSourceDefinition.DATA_SOURCE_CAPABILITY.fromBaseCapability(datasourceName), dataSourceService); serviceBuilder.addCapabilityRequirement(DriverDefinition.AGROAL_DRIVER_CAPABILITY.getDynamicName(driverName), Class.class, dataSourceService.getDriverInjector()); if (jta) { // TODO add a Stage.MODEL requirement serviceBuilder.addCapabilityRequirement("org.wildfly.transactions.transaction-synchronization-registry", TransactionSynchronizationRegistry.class, dataSourceService.getTransactionSynchronizationRegistryInjector()); } AbstractDataSourceOperations.setupElytronSecurity(context, factoryModel, dataSourceService, serviceBuilder); serviceBuilder.install(); } }
/** * Extracts the raw JNDI_NAME value from the given model node, and depending on the value and * the value of any USE_JAVA_CONTEXT child node, converts the raw name into a compliant jndi name. * * @param modelNode the model node; either an operation or the model behind a mail session resource * @return the compliant jndi name */ static String getJndiName(final ModelNode modelNode, OperationContext context) throws OperationFailedException { final String rawJndiName = MailSessionDefinition.JNDI_NAME.resolveModelAttribute(context, modelNode).asString(); return getJndiName(rawJndiName); }
@Override void applySetting(final IIOPSettingsService service, OperationContext context, final ModelNode model) throws OperationFailedException { final boolean value = USE_QUALIFIED_NAME.resolveModelAttribute(context, model).asBoolean(); service.setUseQualifiedName(value); } });
@Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { // 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) if (model.hasDefined(RECOVERY_AUTHENTICATION_CONTEXT.getName()) && !RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean()) { throw SUBSYSTEM_DATASOURCES_LOGGER.attributeRequiresTrueAttribute(RECOVERY_AUTHENTICATION_CONTEXT.getName(), RECOVERY_ELYTRON_ENABLED.getName()); } else if (RECOVERY_ELYTRON_ENABLED.resolveModelAttribute(context, model).asBoolean() && model.hasDefined(RECOVERY_SECURITY_DOMAIN.getName())) { throw SUBSYSTEM_DATASOURCES_LOGGER .attributeRequiresFalseOrUndefinedAttribute(RECOVERY_SECURITY_DOMAIN.getName(), RECOVERY_ELYTRON_ENABLED.getName()); } super.performRuntime(context, operation, model); }