Java Code Examples for org.jboss.as.controller.registry.Resource#getModel()

The following examples show how to use org.jboss.as.controller.registry.Resource#getModel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JVMOptionAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    final Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    final ModelNode model = resource.getModel();

    final ModelNode option = JVM_OPTION.validateOperation(operation);
    ModelNode jvmOptions = model.get(JvmAttributes.JVM_OPTIONS);
    if (jvmOptions.isDefined()) {
        for (ModelNode optionNode : jvmOptions.asList()) {
            if (optionNode.equals(option)) {
                throw HostControllerLogger.ROOT_LOGGER.jvmOptionAlreadyExists(option.asString());
            }
        }
    }
    model.get(JvmAttributes.JVM_OPTIONS).add(option);
}
 
Example 2
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testRejectExpressions() throws Exception {
    //Set up the model
    resourceModel.get("reject").set(new ValueExpression("${expr}"));

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().addRejectCheck(RejectAttributeChecker.SIMPLE_EXPRESSIONS, "reject").end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    //The rejection does not trigger for resource transformation
    Assert.assertTrue(model.hasDefined("reject"));

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("reject").set(new ValueExpression("${expr}"));
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertTrue(transformedAdd.rejectOperation(success()));

    ModelNode write = Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "reject", new ModelNode().set(new ValueExpression("${expr}")));
    OperationTransformer.TransformedOperation transformedWrite = transformOperation(write);
    Assert.assertTrue(transformedWrite.rejectOperation(success()));
}
 
Example 3
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testConvertVsAdd() throws Exception {
    resourceModel.get("convert").set("test");
    resourceModel.get("undefined");

    AttributeNameValueConverter converter = new AttributeNameValueConverter();
    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder()
        .setValueConverter(converter, "convert", "undefined", "new", "dontAdd")
        .end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    Assert.assertEquals(3, model.keys().size());
    Assert.assertEquals("convert", model.get("convert").asString());
    Assert.assertEquals("undefined", model.get("undefined").asString());
    Assert.assertEquals("new", model.get("new").asString());
}
 
Example 4
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleReject() throws Exception {
    //Set up the model
    resourceModel.get("reject").set(true);

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().addRejectCheck(new RejectAttributeChecker.SimpleRejectAttributeChecker(ModelNode.TRUE), "reject").end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    //The rejection does not trigger for resource transformation
    Assert.assertTrue(model.hasDefined("reject"));

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("reject").set(true);
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertTrue(transformedAdd.rejectOperation(success()));

    ModelNode write = Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "reject", ModelNode.TRUE);
    OperationTransformer.TransformedOperation transformedWrite = transformOperation(write);
    Assert.assertTrue(transformedWrite.rejectOperation(success()));
}
 
Example 5
Source File: ReadResourceDescriptionAccessControlTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private ModelNode readModelDescriptionWithAccessControlParameter(ReadResourceDescriptionHandler.AccessControl accessControl) throws Exception {
    ChildResourceDefinition oneChild = new ChildResourceDefinition(ONE);
    oneChild.addAttribute(ATTR_NONE);
    oneChild.addOperation(OP_CONFIG_RW_NONE, false, false);
    ManagementResourceRegistration oneReg = rootRegistration.registerSubModel(oneChild);
    Resource resourceOneA = Resource.Factory.create();
    ModelNode modelOneA = resourceOneA.getModel();
    modelOneA.get(ATTR_NONE).set("uno");
    rootResource.registerChild(ONE_A, resourceOneA);

    ChildResourceDefinition twoChild = new ChildResourceDefinition(TWO);
    twoChild.addAttribute(ATTR_NONE);
    twoChild.addOperation(OP_CONFIG_RW_NONE, false, false);
    oneReg.registerSubModel(twoChild);
    Resource resourceTwoA = Resource.Factory.create();
    ModelNode modelTwoA = resourceOneA.getModel();
    modelTwoA.get(ATTR_NONE).set("dos");
    resourceOneA.registerChild(TWO_A, resourceTwoA);

    ModelNode op = createReadResourceDescriptionOperation(PathAddress.EMPTY_ADDRESS, StandardRole.ADMINISTRATOR, true);
    op.get(ACCESS_CONTROL).set(accessControl.toString());
    ModelNode desc = executeForResult(op);
    return getChildDescription(desc, ONE);
}
 
Example 6
Source File: ReadMasterDomainModelUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static void processServerGroup(final RequiredConfigurationHolder holder, final String group, final Resource domain, ExtensionRegistry extensionRegistry) {

        final PathElement groupElement = PathElement.pathElement(SERVER_GROUP, group);
        if (!domain.hasChild(groupElement)) {
            return;
        }
        final Resource serverGroup = domain.getChild(groupElement);
        final ModelNode model = serverGroup.getModel();

        if (model.hasDefined(SOCKET_BINDING_GROUP)) {
            final String socketBindingGroup = model.get(SOCKET_BINDING_GROUP).asString();
            processSocketBindingGroup(domain, socketBindingGroup, holder);
        }

        final String profile = model.get(PROFILE).asString();
        processProfile(domain, profile, holder, extensionRegistry);

    }
 
Example 7
Source File: DeploymentScannerAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void recordCapabilitiesAndRequirements(final OperationContext context, Resource resource, AttributeDefinition... attributes) throws OperationFailedException {
    Set<RuntimeCapability> capabilitySet = context.getResourceRegistration().getCapabilities();

    for (RuntimeCapability capability : capabilitySet) {
        if (capability.isDynamicallyNamed()) {
            context.registerCapability(capability.fromBaseCapability(context.getCurrentAddress()));
        } else {
            context.registerCapability(capability);
        }
    }

    ModelNode model = resource.getModel();
    for (AttributeDefinition ad : attributes) {
        if (model.hasDefined(ad.getName()) || ad.hasCapabilityRequirements()) {
            ad.addCapabilityRequirements(context, resource, model.get(ad.getName()));
        }
    }
}
 
Example 8
Source File: DeploymentDeployHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    ModelNode model = resource.getModel();
    model.get(ENABLED.getName()).set(true);

    final ModelNode opAddr = operation.get(OP_ADDR);
    PathAddress address = PathAddress.pathAddress(opAddr);
    final String name = address.getLastElement().getValue();
    final String runtimeName = RUNTIME_NAME.resolveModelAttribute(context, model).asString();
    final DeploymentHandlerUtil.ContentItem[] contents = getContents(CONTENT_RESOURCE_ALL.resolveModelAttribute(context, model));
    DeploymentHandlerUtil.deploy(context, operation, runtimeName, name, vaultReader, contents);
    DeploymentUtils.enableAttribute(model);
}
 
Example 9
Source File: RemotingSubsystemAdd.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {

    // WFCORE-4510 -- the effective endpoint configuration is from the root subsystem resource,
    // not from the placeholder configuration=endpoint child resource.
    ModelNode endpointModel = resource.getModel();
    String workerName = WORKER.resolveModelAttribute(context, endpointModel).asString();

    final OptionMap map = EndpointConfigFactory.populate(context, endpointModel);

    // create endpoint
    final String nodeName = WildFlySecurityManager.getPropertyPrivileged(RemotingExtension.NODE_NAME_PROPERTY, null);

    // In case of a managed server the subsystem endpoint might already be installed {@see DomainServerCommunicationServices}
    if (context.getProcessType() == ProcessType.DOMAIN_SERVER) {
        final ServiceController<?> controller = context.getServiceRegistry(false).getService(RemotingServices.SUBSYSTEM_ENDPOINT);
        if (controller != null) {
            // if installed, just skip the rest
            return;
        }
    }

    final CapabilityServiceBuilder<?> builder = context.getCapabilityServiceTarget().addCapability(REMOTING_ENDPOINT_CAPABILITY);
    final Consumer<Endpoint> endpointConsumer = builder.provides(REMOTING_ENDPOINT_CAPABILITY);
    final Supplier<XnioWorker> workerSupplier = builder.requiresCapability(IO_WORKER_CAPABILITY_NAME, XnioWorker.class, workerName);
    builder.setInstance(new EndpointService(endpointConsumer, workerSupplier, nodeName, EndpointService.EndpointType.SUBSYSTEM, map));
    builder.install();
}
 
Example 10
Source File: IgnoredNonAffectedServerGroupsUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processSocketBindingGroups(final Resource domainResource, final String name, final Set<String> socketBindingGroups) {
    if (!socketBindingGroups.contains(name)) {
        socketBindingGroups.add(name);
        final PathElement pathElement = PathElement.pathElement(SOCKET_BINDING_GROUP, name);
        if (domainResource.hasChild(pathElement)) {
            final Resource resource = domainResource.getChild(pathElement);
            final ModelNode model = resource.getModel();
            if (model.hasDefined(INCLUDES)) {
                for (final ModelNode include : model.get(INCLUDES).asList()) {
                    processSocketBindingGroups(domainResource, include.asString(), socketBindingGroups);
                }
            }
        }
    }
}
 
Example 11
Source File: IgnoredNonAffectedServerGroupsUtil.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void processProfiles(final Resource domain, final String profile, final Set<String> profiles) {
    if (!profiles.contains(profile)) {
        profiles.add(profile);
        final PathElement pathElement = PathElement.pathElement(PROFILE, profile);
        if (domain.hasChild(pathElement)) {
            final Resource resource = domain.getChild(pathElement);
            final ModelNode model = resource.getModel();
            if (model.hasDefined(INCLUDES)) {
                for (final ModelNode include : model.get(INCLUDES).asList()) {
                    processProfiles(domain, include.asString(), profiles);
                }
            }
        }
    }
}
 
Example 12
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testConvertValue() throws Exception {
    resourceModel.get("value1").set("one");
    resourceModel.get("value2").set("two");

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
    builder.getAttributeBuilder().setValueConverter(new DefaultAttributeConverter() {
        @Override
        public void convertAttribute(PathAddress address, String name, ModelNode attributeValue, TransformationContext context) {
            if (name.equals("value2") && attributeValue.asString().equals("two")) {
                attributeValue.set(1);
            }
        }
    }, "value1", "value2").end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    Assert.assertEquals(2, model.keys().size());
    Assert.assertEquals("one", model.get("value1").asString());
    Assert.assertEquals(ModelType.INT, model.get("value2").getType());
    Assert.assertEquals(1, model.get("value2").asInt());

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("value1").set("one");
    add.get("value2").set("two");
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    Assert.assertEquals("one", transformedAdd.getTransformedOperation().get("value1").asString());
    Assert.assertEquals(ModelType.INT, transformedAdd.getTransformedOperation().get("value2").getType());
    Assert.assertEquals(1, transformedAdd.getTransformedOperation().get("value2").asInt());

    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "value1", new ModelNode("value")),
            "value1", new ModelNode("value"));
    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "value2", new ModelNode("two")),
            "value2", new ModelNode(1));
}
 
Example 13
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testDiscardNotHappeningWithExpressions() throws Exception {
    //Set up the model
    resourceModel.get("discard").set(new ValueExpression("${xxx}"));

    final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createInstance(PATH);
        builder.getAttributeBuilder().setDiscard(new DefaultDiscardAttributeChecker(false, false) {
            @Override
            public boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
                return true;
            }
        }, "discard").end();
    TransformationDescription.Tools.register(builder.build(), transformersSubRegistration);

    final Resource resource = transformResource();
    Assert.assertNotNull(resource);
    final Resource toto = resource.getChild(PATH);
    Assert.assertNotNull(toto);
    final ModelNode model = toto.getModel();
    Assert.assertEquals(new ModelNode().set(new ValueExpression("${xxx}")), model.get("discard"));

    ModelNode add = Util.createAddOperation(PathAddress.pathAddress(PATH));
    add.get("discard").set(new ValueExpression("${xxx}"));
    OperationTransformer.TransformedOperation transformedAdd = transformOperation(add);
    Assert.assertFalse(transformedAdd.rejectOperation(success()));
    Assert.assertEquals(add, transformedAdd.getTransformedOperation());

    checkWriteOp(Util.getWriteAttributeOperation(PathAddress.pathAddress(PATH), "discard", new ModelNode().set(new ValueExpression("${xxx}"))),
            "discard", new ModelNode().set(new ValueExpression("${xxx}")));
}
 
Example 14
Source File: ReadResourceDescriptionAccessControlTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void registerAttributeVaultSensitivityFixedResource() {
    ChildResourceDefinition oneChild = new ChildResourceDefinition(ONE_A);
    oneChild.addAttribute(ATTR_NONE);
    oneChild.addAttribute(ATTR_VAULT);
    rootRegistration.registerSubModel(oneChild);
    Resource resourceA = Resource.Factory.create();
    ModelNode modelA = resourceA.getModel();
    modelA.get(ATTR_NONE).set("hello");
    modelA.get(ATTR_VAULT).set("${VAULT::AA::bb::cc}");
    rootResource.registerChild(ONE_A, resourceA);
}
 
Example 15
Source File: AttributesTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Before
public void setUp() {
    // Cleanup
    resourceRoot = Resource.Factory.create();
    registry = TransformerRegistry.Factory.create();
    resourceRegistration = ManagementResourceRegistration.Factory.forProcessType(ProcessType.EMBEDDED_SERVER).createRegistration(ROOT);
    // test
    final Resource toto = Resource.Factory.create();
    resourceRoot.registerChild(PATH, toto);
    resourceModel = toto.getModel();

    // Register the description
    transformersSubRegistration = registry.getServerRegistration(ModelVersion.create(1));

}
 
Example 16
Source File: BasicResourceTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void transformResource(final ResourceTransformationContext context, final PathAddress address, final Resource resource) throws OperationFailedException {
    // Remote the test-resource attribute
    final ModelNode model = resource.getModel();
    final ModelNode testResource = model.remove("test-resource");
    // Add the current resource
    context.addTransformedResource(PathAddress.EMPTY_ADDRESS, resource);
    // Use the test-resource attribute to create a child
    final Resource child = Resource.Factory.create();
    child.getModel().get("attribute").set(testResource);
    context.addTransformedResource(PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement("resource", "test")), child);
    context.processChildren(resource);
}
 
Example 17
Source File: DeploymentReplaceHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    for (AttributeDefinition def : DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.values()) {
        def.validateOperation(operation);
    }
    String name = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(NAME).resolveModelAttribute(context, operation).asString();
    String toReplace = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(TO_REPLACE).resolveModelAttribute(context, operation).asString();

    if (name.equals(toReplace)) {
        throw ServerLogger.ROOT_LOGGER.cannotReplaceDeployment(OPERATION_NAME, NAME, TO_REPLACE,
                DeploymentRedeployHandler.OPERATION_NAME, DeploymentFullReplaceHandler.OPERATION_NAME);
    }

    final PathElement deployPath = PathElement.pathElement(DEPLOYMENT, name);
    final PathElement replacePath = PathElement.pathElement(DEPLOYMENT, toReplace);

    final Resource root = context.readResource(PathAddress.EMPTY_ADDRESS, false);
    if (! root.hasChild(replacePath)) {
        throw ServerLogger.ROOT_LOGGER.noSuchDeployment(toReplace);
    }

    final ModelNode replaceNode = context.readResourceForUpdate(PathAddress.pathAddress(replacePath)).getModel();
    final String replacedName = DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, replaceNode).asString();

    ModelNode deployNode;
    String runtimeName;
    if (!root.hasChild(deployPath)) {
        if (!operation.hasDefined(CONTENT)) {
            throw ServerLogger.ROOT_LOGGER.noSuchDeployment(name);
        }
        // else -- the HostController handles a server group replace-deployment like an add, so we do too

        final ModelNode content = operation.require(CONTENT);
        // TODO: JBAS-9020: for the moment overlays are not supported, so there is a single content item
        final ModelNode contentItemNode = content.require(0);
        if (contentItemNode.hasDefined(HASH)) {
            byte[] hash = contentItemNode.require(HASH).asBytes();
            addFromHash(ModelContentReference.fromDeploymentName(name, hash));
        } else {
        }
        runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : replacedName;

        // Create the resource
        final Resource deployResource = context.createResource(PathAddress.pathAddress(deployPath));
        deployNode = deployResource.getModel();
        deployNode.get(RUNTIME_NAME).set(runtimeName);

        //TODO Assumes this can only be set by client
        deployNode.get(ModelDescriptionConstants.PERSISTENT).set(true);

        deployNode.get(CONTENT).set(content);

    } else {
        deployNode = context.readResourceForUpdate(PathAddress.pathAddress(deployPath)).getModel();
        if (ENABLED.resolveModelAttribute(context, deployNode).asBoolean()) {
            throw ServerLogger.ROOT_LOGGER.deploymentAlreadyStarted(toReplace);
        }
        runtimeName = operation.hasDefined(RUNTIME_NAME) ? DeploymentAttributes.REPLACE_DEPLOYMENT_ATTRIBUTES.get(RUNTIME_NAME).resolveModelAttribute(context, operation).asString() : deployNode.require(RUNTIME_NAME).asString();
        deployNode.get(RUNTIME_NAME).set(runtimeName);
    }

    deployNode.get(ENABLED.getName()).set(true);
    replaceNode.get(ENABLED.getName()).set(false);

    final DeploymentHandlerUtil.ContentItem[] contents = getContents(deployNode.require(CONTENT));
    DeploymentHandlerUtil.replace(context, replaceNode, runtimeName, name, replacedName, vaultReader, contents);
}
 
Example 18
Source File: BadReadHandlerAttributeTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected Resource createResource(OperationContext context) {
    Resource resource = super.createResource(context);
    BadReadHandlerAttributeTestCase.createdResource = resource.getModel();
    return resource;
}
 
Example 19
Source File: KeyStoreDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();
    String providers = PROVIDERS.resolveModelAttribute(context, model).asStringOrNull();
    String providerName = PROVIDER_NAME.resolveModelAttribute(context, model).asStringOrNull();
    String type = TYPE.resolveModelAttribute(context, model).asStringOrNull();
    String path = PATH.resolveModelAttribute(context, model).asStringOrNull();
    String relativeTo = null;
    boolean required;
    String aliasFilter = ALIAS_FILTER.resolveModelAttribute(context, model).asStringOrNull();

    final KeyStoreService keyStoreService;
    if (path != null) {
        relativeTo = RELATIVE_TO.resolveModelAttribute(context, model).asStringOrNull();
        required = REQUIRED.resolveModelAttribute(context, model).asBoolean();
        keyStoreService = KeyStoreService.createFileBasedKeyStoreService(providerName, type, relativeTo, path, required, aliasFilter);
    } else {
        if (type == null) {
            throw ROOT_LOGGER.filelessKeyStoreMissingType();
        }
        keyStoreService = KeyStoreService.createFileLessKeyStoreService(providerName, type, aliasFilter);
    }

    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = KEY_STORE_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName(KeyStore.class);
    ServiceBuilder<KeyStore> serviceBuilder = serviceTarget.addService(serviceName, keyStoreService).setInitialMode(Mode.ACTIVE);

    serviceBuilder.addDependency(PathManagerService.SERVICE_NAME, PathManager.class, keyStoreService.getPathManagerInjector());
    if (relativeTo != null) {
        serviceBuilder.requires(pathName(relativeTo));
    }

    if (providers != null) {
        String providersCapabilityName = RuntimeCapability.buildDynamicCapabilityName(PROVIDERS_CAPABILITY, providers);
        ServiceName providerLoaderServiceName = context.getCapabilityServiceName(providersCapabilityName, Provider[].class);
        serviceBuilder.addDependency(providerLoaderServiceName, Provider[].class, keyStoreService.getProvidersInjector());
    }

    keyStoreService.getCredentialSourceSupplierInjector()
            .inject(CredentialReference.getCredentialSourceSupplier(context, KeyStoreDefinition.CREDENTIAL_REFERENCE, model, serviceBuilder));

    commonDependencies(serviceBuilder).install();
}
 
Example 20
Source File: FilteringKeyStoreDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    ModelNode model = resource.getModel();

    String sourceKeyStoreName = KEY_STORE.resolveModelAttribute(context, model).asStringOrNull();
    String aliasFilter = ALIAS_FILTER.resolveModelAttribute(context, model).asStringOrNull();

    String sourceKeyStoreCapability = RuntimeCapability.buildDynamicCapabilityName(KEY_STORE_CAPABILITY, sourceKeyStoreName);
    ServiceName sourceKeyStoreServiceName = context.getCapabilityServiceName(sourceKeyStoreCapability, KeyStore.class);


    final InjectedValue<KeyStore> keyStore = new InjectedValue<>();

    FilteringKeyStoreService filteringKeyStoreService = new FilteringKeyStoreService(keyStore, aliasFilter);

    ServiceTarget serviceTarget = context.getServiceTarget();
    RuntimeCapability<Void> runtimeCapability = KEY_STORE_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
    ServiceName serviceName = runtimeCapability.getCapabilityServiceName(KeyStore.class);
    ServiceBuilder<KeyStore> serviceBuilder = serviceTarget.addService(serviceName, filteringKeyStoreService).setInitialMode(ServiceController.Mode.ACTIVE);

    FILTERING_KEY_STORE_UTIL.addInjection(serviceBuilder, keyStore, sourceKeyStoreServiceName);

    commonDependencies(serviceBuilder).install();
}