Search in sources :

Example 51 with OperationContext

use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronKeyStoreResourceDefinition.

/**
     * Defines a resource that represents an Elytron-compatible key store that can be exported by a JSSE-enabled domain
     * in the legacy security subsystem.
     *
     * To export the key store the resource uses a {@code BasicAddHandler} implementation that registers the elytron key-store
     * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
     * {@code SecurityDomainContext} to obtain a {@code JSSESecurityDomain}. If such domain is found, its configured key
     * store is obtained and returned.
     *
     * The {@code ValueSupplier} implementation throws an exception if the referenced legacy domain is not a JSSE-enabled
     * domain or if the domain doesn't contain a key store configuration.
     */
public static ResourceDefinition getElytronKeyStoreResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JSSE_CONFIG };
    final AbstractAddStepHandler addHandler = new BasicAddHandler<KeyStore>(attributes, KEY_STORE_RUNTIME_CAPABILITY) {

        @Override
        protected BasicService.ValueSupplier<KeyStore> getValueSupplier(ServiceBuilder<KeyStore> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String legacyJSSEConfig = asStringIfDefined(context, LEGACY_JSSE_CONFIG, model);
            final InjectedValue<SecurityDomainContext> securityDomainContextInjector = new InjectedValue<>();
            if (legacyJSSEConfig != null) {
                serviceBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(legacyJSSEConfig), SecurityDomainContext.class, securityDomainContextInjector);
            }
            return () -> {
                final SecurityDomainContext domainContext = securityDomainContextInjector.getValue();
                final JSSESecurityDomain jsseDomain = domainContext.getJSSE();
                if (jsseDomain == null) {
                    throw SecurityLogger.ROOT_LOGGER.unableToLocateJSSEConfig(legacyJSSEConfig);
                }
                final KeyStore keyStore = jsseDomain.getKeyStore();
                if (keyStore == null) {
                    throw SecurityLogger.ROOT_LOGGER.unableToLocateComponentInJSSEDomain("key store", legacyJSSEConfig);
                }
                return keyStore;
            };
        }
    };
    return new BasicResourceDefinition(Constants.ELYTRON_KEY_STORE, addHandler, attributes, KEY_STORE_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) JSSESecurityDomain(org.jboss.security.JSSESecurityDomain) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) KeyStore(java.security.KeyStore) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 52 with OperationContext

use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.

the class ElytronIntegrationResourceDefinitions method getElytronRealmResourceDefinition.

/**
     * Defines a resource that represents an Elytron-compatible realm that can be exported by the legacy security subsystem.
     * The constructed {@code SecurityRealm} wraps a legacy {@code SecurityDomainContext} and delegates authentication
     * decisions to that context.
     *
     * To export the realm the resource uses a {@code BasicAddHandler} implementation that registers the security-realm
     * capability and implements a {@code org.jboss.as.security.elytron.BasicService.ValueSupplier} that uses the injected
     * {@code SecurityDomainContext} to create and return an instance of {@code SecurityDomainContextRealm}.
     */
public static ResourceDefinition getElytronRealmResourceDefinition() {
    final AttributeDefinition[] attributes = new AttributeDefinition[] { LEGACY_JAAS_CONFIG };
    final AbstractAddStepHandler addHandler = new BasicAddHandler<SecurityRealm>(attributes, SECURITY_REALM_RUNTIME_CAPABILITY) {

        @Override
        protected BasicService.ValueSupplier<SecurityRealm> getValueSupplier(ServiceBuilder<SecurityRealm> serviceBuilder, OperationContext context, ModelNode model) throws OperationFailedException {
            final String legacyJAASConfig = asStringIfDefined(context, LEGACY_JAAS_CONFIG, model);
            final InjectedValue<SecurityDomainContext> securityDomainContextInjector = new InjectedValue<>();
            if (legacyJAASConfig != null) {
                serviceBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(legacyJAASConfig), SecurityDomainContext.class, securityDomainContextInjector);
            }
            return () -> {
                final SecurityDomainContext domainContext = securityDomainContextInjector.getValue();
                return new SecurityDomainContextRealm(domainContext);
            };
        }
    };
    return new BasicResourceDefinition(Constants.ELYTRON_REALM, addHandler, attributes, SECURITY_REALM_RUNTIME_CAPABILITY);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InjectedValue(org.jboss.msc.value.InjectedValue) SecurityRealm(org.wildfly.security.auth.server.SecurityRealm) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) ModelNode(org.jboss.dmr.ModelNode)

Example 53 with OperationContext

use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.

the class RaRemove method execute.

public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    final ModelNode opAddr = operation.require(OP_ADDR);
    final String idName = PathAddress.pathAddress(opAddr).getLastElement().getValue();
    final boolean isModule;
    // Compensating is add
    final ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
    final String archiveOrModuleName;
    if (!model.hasDefined(ARCHIVE.getName()) && !model.hasDefined(MODULE.getName())) {
        throw ConnectorLogger.ROOT_LOGGER.archiveOrModuleRequired();
    }
    if (model.get(ARCHIVE.getName()).isDefined()) {
        isModule = false;
        archiveOrModuleName = model.get(ARCHIVE.getName()).asString();
    } else {
        isModule = true;
        archiveOrModuleName = model.get(MODULE.getName()).asString();
    }
    final ModelNode compensating = Util.getEmptyOperation(ADD, opAddr);
    if (model.hasDefined(RESOURCEADAPTERS_NAME)) {
        for (ModelNode raNode : model.get(RESOURCEADAPTERS_NAME).asList()) {
            ModelNode raCompensatingNode = raNode.clone();
            compensating.get(RESOURCEADAPTERS_NAME).add(raCompensatingNode);
        }
    }
    context.removeResource(PathAddress.EMPTY_ADDRESS);
    context.addStep(new OperationStepHandler() {

        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final boolean wasActive;
            wasActive = RaOperationUtil.removeIfActive(context, archiveOrModuleName, idName);
            if (wasActive) {
                if (!context.isResourceServiceRestartAllowed()) {
                    context.reloadRequired();
                    context.completeStep(new OperationContext.RollbackHandler() {

                        @Override
                        public void handleRollback(OperationContext context, ModelNode operation) {
                            context.revertReloadRequired();
                        }
                    });
                    return;
                }
            }
            ServiceName raServiceName = ServiceName.of(ConnectorServices.RA_SERVICE, idName);
            ServiceController<?> serviceController = context.getServiceRegistry(false).getService(raServiceName);
            final ModifiableResourceAdapter resourceAdapter;
            if (serviceController != null) {
                resourceAdapter = (ModifiableResourceAdapter) serviceController.getValue();
            } else {
                resourceAdapter = null;
            }
            final List<ServiceName> serviceNameList = context.getServiceRegistry(false).getServiceNames();
            for (ServiceName name : serviceNameList) {
                if (raServiceName.isParentOf(name)) {
                    context.removeService(name);
                }
            }
            if (model.get(MODULE.getName()).isDefined()) {
                //ServiceName deploymentServiceName = ConnectorServices.getDeploymentServiceName(model.get(MODULE.getName()).asString(),raId);
                //context.removeService(deploymentServiceName);
                ServiceName deployerServiceName = ConnectorServices.RESOURCE_ADAPTER_DEPLOYER_SERVICE_PREFIX.append(idName);
                context.removeService(deployerServiceName);
                ServiceName inactiveServiceName = ConnectorServices.INACTIVE_RESOURCE_ADAPTER_SERVICE.append(idName);
                context.removeService(inactiveServiceName);
            }
            context.removeService(raServiceName);
            context.completeStep(new OperationContext.RollbackHandler() {

                @Override
                public void handleRollback(OperationContext context, ModelNode operation) {
                    if (resourceAdapter != null) {
                        List<ServiceController<?>> newControllers = new LinkedList<ServiceController<?>>();
                        if (model.get(ARCHIVE.getName()).isDefined()) {
                            RaOperationUtil.installRaServices(context, idName, resourceAdapter, newControllers);
                        } else {
                            try {
                                RaOperationUtil.installRaServicesAndDeployFromModule(context, idName, resourceAdapter, archiveOrModuleName, newControllers);
                            } catch (OperationFailedException e) {
                            }
                        }
                        try {
                            if (wasActive) {
                                RaOperationUtil.activate(context, idName, archiveOrModuleName);
                            }
                        } catch (OperationFailedException e) {
                        }
                    }
                }
            });
        }
    }, OperationContext.Stage.RUNTIME);
    context.stepCompleted();
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedList(java.util.LinkedList) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) LinkedList(java.util.LinkedList) ModelNode(org.jboss.dmr.ModelNode)

Example 54 with OperationContext

use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.

the class GetInstalledDriverOperationHandler method execute.

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    validator.validate(operation);
    final String name = operation.require(DRIVER_NAME.getName()).asString();
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE);
                DriverRegistry driverRegistry = DriverRegistry.class.cast(sc.getValue());
                ModelNode result = new ModelNode();
                InstalledDriver driver = driverRegistry.getInstalledDriver(name);
                ModelNode driverNode = new ModelNode();
                driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName());
                if (driver.isFromDeployment()) {
                    driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName());
                    driverNode.get(DRIVER_MODULE_NAME.getName());
                    driverNode.get(MODULE_SLOT.getName());
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName());
                } else {
                    driverNode.get(DEPLOYMENT_NAME.getName());
                    driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName());
                    driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : "");
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName());
                }
                driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName());
                driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion());
                driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion());
                driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant());
                result.add(driverNode);
                context.getResult().set(result);
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 55 with OperationContext

use of org.jboss.as.controller.OperationContext in project wildfly by wildfly.

the class EnlistmentTraceAttributeWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<ConnectionManager>> handbackHolder) throws OperationFailedException {
    final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDINAME.getName()).asString();
    final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
    Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean();
    try {
        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
        if (repository.getConnectors() != null) {
            List<ConnectionManager> handback = new LinkedList<>();
            repository.getConnectors().stream().forEach(connector -> connector.getConnectionManagers().stream().filter(cm -> jndiName.equalsIgnoreCase(cm.getUniqueId())).forEach(cm -> {
                cm.setEnlistmentTrace(boolValue);
                handback.add(cm);
            }));
            handbackHolder.setHandback(handback);
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage()));
    }
    return false;
}
Also used : AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) ServiceController(org.jboss.msc.service.ServiceController) List(java.util.List) OperationContext(org.jboss.as.controller.OperationContext) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) PathAddress(org.jboss.as.controller.PathAddress) ConnectionManager(org.jboss.jca.core.api.management.ConnectionManager) ConnectorLogger(org.jboss.as.connector.logging.ConnectorLogger) ConnectorServices(org.jboss.as.connector.util.ConnectorServices) ModelNode(org.jboss.dmr.ModelNode) LinkedList(java.util.LinkedList) ConnectionManager(org.jboss.jca.core.api.management.ConnectionManager) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedList(java.util.LinkedList) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)67 ModelNode (org.jboss.dmr.ModelNode)67 OperationFailedException (org.jboss.as.controller.OperationFailedException)51 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)40 PathAddress (org.jboss.as.controller.PathAddress)34 ServiceController (org.jboss.msc.service.ServiceController)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)17 Resource (org.jboss.as.controller.registry.Resource)16 ServiceName (org.jboss.msc.service.ServiceName)13 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)11 ServiceTarget (org.jboss.msc.service.ServiceTarget)11 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)9 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 EnumSet (java.util.EnumSet)7 Map (java.util.Map)7 PathElement (org.jboss.as.controller.PathElement)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 ArrayList (java.util.ArrayList)6