Java Code Examples for org.jboss.dmr.ModelNode#require()

The following examples show how to use org.jboss.dmr.ModelNode#require() . 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: RespawnHttpTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean lookupServerInModel(String host, String server) throws Exception {
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(READ_RESOURCE_OPERATION);
    operation.get(OP_ADDR).set(getHostControllerServerAddress(host, server));

    try {
        final ModelNode result = getControllerClient().execute(operation);
        if (result.get(OUTCOME).asString().equals(SUCCESS)){
            final ModelNode model = result.require(RESULT);
            if (model.hasDefined(NAME) && model.get(NAME).asString().equals(server)) {
                return true;
            }
        }
    } catch (IOException e) {
        //
    }
    return false;
}
 
Example 2
Source File: ThreadsSubsystemParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleBlockingBoundedQueueThreadPool() throws Exception {
    List<ModelNode> updates = createSubSystem("<blocking-bounded-queue-thread-pool name=\"test-pool\">" +
            "<max-threads count=\"1\"/><queue-length count=\"1\"/></blocking-bounded-queue-thread-pool>");
    assertEquals(2, updates.size());
    for (ModelNode update : updates) {
        try {
            executeForResult(update);
        } catch (OperationFailedException e) {
            throw new RuntimeException(e.getFailureDescription().toString());
        }
    }

    ModelNode subsystem = model.require("subsystem").require("threads");
    ModelNode threadPool = subsystem.require("blocking-bounded-queue-thread-pool");
    assertEquals(1, threadPool.keys().size());
}
 
Example 3
Source File: ConnectorUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected static OptionMap getFullOptions(OperationContext context, ModelNode fullModel) throws OperationFailedException {
    OptionMap.Builder builder = OptionMap.builder();
    builder.set(Options.TCP_NODELAY, true);
    builder.set(Options.REUSE_ADDRESSES, true);

    builder.set(RemotingOptions.SASL_PROTOCOL, ConnectorCommon.SASL_PROTOCOL.resolveModelAttribute(context, fullModel).asString());
    ModelNode serverName = ConnectorCommon.SERVER_NAME.resolveModelAttribute(context, fullModel);
    if (serverName.isDefined()) {
        builder.set(RemotingOptions.SERVER_NAME, serverName.asString());
    }

    ModelNode properties = fullModel.get(PROPERTY);
    if (properties.isDefined() && properties.asInt() > 0) {
        addOptions(context, properties, builder);
    }
    if (fullModel.hasDefined(SECURITY)) {
        ModelNode security = fullModel.require(SECURITY);
        if (security.hasDefined(SASL)) {
            ModelNode sasl = security.require(SASL);
            addSasl(context, sasl, builder);
        }
    }
    return builder.getMap();
}
 
Example 4
Source File: ThreadsSubsystemParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSeveralQueuelessThreadPools1_0() throws Exception {
    List<ModelNode> updates = createSubSystem("<queueless-thread-pool name=\"test-poolA\">"
            + "   <max-threads count=\"1\" per-cpu=\"2\"/>" + "</queueless-thread-pool>"
            + "<queueless-thread-pool name=\"test-poolB\">" + "   <max-threads count=\"1\" per-cpu=\"2\"/>"
            + "</queueless-thread-pool>", Namespace.THREADS_1_0);
    assertEquals(3, updates.size());
    for (ModelNode update : updates) {
        try {
            executeForResult(update);
        } catch (OperationFailedException e) {
            throw new RuntimeException(e.getFailureDescription().toString());
        }
    }

    ModelNode subsystem = model.require("subsystem").require("threads");
    ModelNode threadFactory = subsystem.require("queueless-thread-pool");
    assertEquals(2, threadFactory.keys().size());
}
 
Example 5
Source File: ThreadsSubsystemParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleScheduledThreadPool1_0() throws Exception {
    List<ModelNode> updates = createSubSystem("<scheduled-thread-pool name=\"test-pool\">"
            + "   <max-threads count=\"1\" per-cpu=\"2\"/>" + "</scheduled-thread-pool>", Namespace.THREADS_1_0);
    assertEquals(2, updates.size());
    for (ModelNode update : updates) {
        try {
            executeForResult(update);
        } catch (OperationFailedException e) {
            throw new RuntimeException(e.getFailureDescription().toString());
        }
    }

    ModelNode subsystem = model.require("subsystem").require("threads");
    ModelNode threadPool = subsystem.require("scheduled-thread-pool");
    assertEquals(1, threadPool.keys().size());
}
 
Example 6
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeLdapCacheIfDefined(XMLExtendedStreamWriter writer, ModelNode parent) throws XMLStreamException {
    if (parent.hasDefined(CACHE)) {
        ModelNode cacheHolder = parent.require(CACHE);
        final ModelNode cache;
        final String type;

        if (cacheHolder.hasDefined(BY_ACCESS_TIME)) {
            cache = cacheHolder.require(BY_ACCESS_TIME);
            type = BY_ACCESS_TIME;
        } else if (cacheHolder.hasDefined(BY_SEARCH_TIME)) {
            cache = cacheHolder.require(BY_SEARCH_TIME);
            type = BY_SEARCH_TIME;
        } else {
            return;
        }

        writer.writeStartElement(Element.CACHE.getLocalName());
        if (type.equals(BY_SEARCH_TIME) == false) {
            writer.writeAttribute(Attribute.TYPE.getLocalName(), type);
        }
        LdapCacheResourceDefinition.EVICTION_TIME.marshallAsAttribute(cache, writer);
        LdapCacheResourceDefinition.CACHE_FAILURES.marshallAsAttribute(cache, writer);
        LdapCacheResourceDefinition.MAX_CACHE_SIZE.marshallAsAttribute(cache, writer);
        writer.writeEndElement();
    }
}
 
Example 7
Source File: ThreadsSubsystemParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleUnboundedQueueThreadPool1_0() throws Exception {
    List<ModelNode> updates = createSubSystem("<unbounded-queue-thread-pool name=\"test-pool\">"
            + "   <max-threads count=\"1\" per-cpu=\"2\"/>" + "</unbounded-queue-thread-pool>", Namespace.THREADS_1_0);
    assertEquals(2, updates.size());
    for (ModelNode update : updates) {
        try {
            executeForResult(update);
        } catch (OperationFailedException e) {
            throw new RuntimeException(e.getFailureDescription().toString());
        }
    }

    ModelNode subsystem = model.require("subsystem").require("threads");
    ModelNode threadPool = subsystem.require("unbounded-queue-thread-pool");
    assertEquals(1, threadPool.keys().size());
}
 
Example 8
Source File: ThreadsSubsystemParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSeveralScheduledThreadPools() throws Exception {
    List<ModelNode> updates = createSubSystem("<scheduled-thread-pool name=\"test-poolA\"><max-threads count=\"1\"/></scheduled-thread-pool>"
            + "<scheduled-thread-pool name=\"test-poolB\"><max-threads count=\"1\"/></scheduled-thread-pool>");
    assertEquals(3, updates.size());
    for (ModelNode update : updates) {
        try {
            executeForResult(update);
        } catch (OperationFailedException e) {
            throw new RuntimeException(e.getFailureDescription().toString());
        }
    }

    ModelNode subsystem = model.require("subsystem").require("threads");
    ModelNode threadFactory = subsystem.require("scheduled-thread-pool");
    assertEquals(2, threadFactory.keys().size());
}
 
Example 9
Source File: ThreadsSubsystemParsingTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleUnboundedQueueThreadPool() throws Exception {
    List<ModelNode> updates = createSubSystem("<unbounded-queue-thread-pool name=\"test-pool\"><max-threads count=\"1\"/></unbounded-queue-thread-pool>");
    assertEquals(2, updates.size());
    for (ModelNode update : updates) {
        try {
            executeForResult(update);
        } catch (OperationFailedException e) {
            throw new RuntimeException(e.getFailureDescription().toString());
        }
    }

    ModelNode subsystem = model.require("subsystem").require("threads");
    ModelNode threadPool = subsystem.require("unbounded-queue-thread-pool");
    assertEquals(1, threadPool.keys().size());
}
 
Example 10
Source File: ValidateModelTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ModelNode getDescription() throws Exception {
    ModelNode op = new ModelNode();
    op.get(OP).set(READ_RESOURCE_DESCRIPTION_OPERATION);
    op.get(OP_ADDR).setEmptyList();
    op.get(RECURSIVE).set(true);
    op.get(INHERITED).set(false);
    op.get(OPERATIONS).set(true);
    ModelNode result = managementClient.getControllerClient().execute(op);
    if (result.hasDefined(FAILURE_DESCRIPTION)) {
        throw new RuntimeException(result.get(FAILURE_DESCRIPTION).asString());
    }
    return result.require(RESULT);
}
 
Example 11
Source File: ReadFeatureDescriptionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reads alias to a storage resource.
 *
 * Expectations:
 *
 * - the target resource is read.
 */
@Test
public void testAliasToResource() throws OperationFailedException {
    ModelNode result = readFeatureDescription(PathAddress.pathAddress("alias", "alias-to-resource"));

    ModelNode feature = result.require(FEATURE);
    Assert.assertEquals("subsystem.testsubsystem.resource.main-resource", feature.require(NAME).asString());
    Map<String, ModelNode> params = extractParamsToMap(feature);
    assertFeatureIdParam(SUBSYSTEM, TEST_SUBSYSTEM, params);
    assertFeatureIdParam(RESOURCE, MAIN_RESOURCE, params);
}
 
Example 12
Source File: SubsystemTestDelegate.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Checks that the transformed model is the same as the model built up in the legacy subsystem controller via the transformed operations,
 * and that the transformed model is valid according to the resource definition in the legacy subsystem controller.
 *
 *
 *
 * @param kernelServices the main kernel services
 * @param modelVersion   the model version of the targeted legacy subsystem
 * @param legacyModelFixer use to touch up the model read from the legacy controller, use sparingly when the legacy model is just wrong. May be {@code null}
 * @param includeDefaults  whether the legacy controller model and the transformed model should include default values for undefined attributes
 * @return the whole model of the legacy controller
 */
ModelNode checkSubsystemModelTransformation(KernelServices kernelServices, ModelVersion modelVersion, ModelFixer legacyModelFixer, boolean includeDefaults) throws IOException, OperationFailedException {

    ModelNode legacyReadResource = Util.createOperation(ModelDescriptionConstants.READ_RESOURCE_OPERATION, PathAddress.EMPTY_ADDRESS);
    legacyReadResource.get(ModelDescriptionConstants.RECURSIVE).set(true);
    legacyReadResource.get(ModelDescriptionConstants.INCLUDE_ALIASES).set(false);
    legacyReadResource.get(ModelDescriptionConstants.INCLUDE_RUNTIME).set(false);
    legacyReadResource.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(includeDefaults);
    ModelNode legacyModel = ModelTestUtils.checkResultAndGetContents(kernelServices.executeOperation(modelVersion, kernelServices.transformOperation(modelVersion, legacyReadResource)));
    ModelNode legacySubsystem = legacyModel.require(SUBSYSTEM);
    legacySubsystem = legacySubsystem.require(mainSubsystemName);

    if (legacyModelFixer != null) {
        legacySubsystem = legacyModelFixer.fixModel(legacySubsystem);
    }

    //1) Check that the transformed model is the same as the whole model read from the legacy controller.
    //The transformed model is done via the resource transformers
    //The model in the legacy controller is built up via transformed operations
    ModelNode transformed = kernelServices.readTransformedModel(modelVersion, includeDefaults).get(SUBSYSTEM, mainSubsystemName);

    ModelTestUtils.compare(legacySubsystem, transformed, true);

    //2) Check that the transformed model is valid according to the resource definition in the legacy subsystem controller
    ResourceDefinition rd = TransformationUtils.getResourceDefinition(kernelServices, modelVersion, mainSubsystemName);
    Assert.assertNotNull("Could not load legacy dmr for subsystem '" + mainSubsystemName + "' version: '" + modelVersion + "' please add it", rd);
    ManagementResourceRegistration rr = ManagementResourceRegistration.Factory.forProcessType(getProcessType()).createRegistration(rd);
    ModelTestUtils.checkModelAgainstDefinition(transformed, rr);
    return legacyModel;
}
 
Example 13
Source File: ReadFeatureDescriptionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Reads a subsystem recursively.
 *
 * The resource contains:
 *
 * - two storage resources,
 * - runtime resource and non-feature storage resource.
 *
 * Expectations:
 *
 * - only the two storage resources will be listed as children,
 * - children's children will be listed.
 *
 * (The usual stuff is tested by other tests.)
 */
@Test
public void testStorageResourceRecursive() throws OperationFailedException {
    ModelNode result = readFeatureDescription(PathAddress.pathAddress(SUBSYSTEM, TEST_SUBSYSTEM), true);

    ModelNode feature = result.require(FEATURE);
    Assert.assertEquals(SUBSYSTEM + "." + TEST_SUBSYSTEM, feature.require(NAME).asString());

    // subsystem params
    Map<String, ModelNode> params = extractParamsToMap(feature);
    assertFeatureIdParam(SUBSYSTEM, TEST_SUBSYSTEM, params);
    assertParamWithDefault(EXTENSION, TEST_EXTENSION, params);

    // subsystem children
    ModelNode resource1 = feature.require(CHILDREN).require("subsystem.testsubsystem.test.special-names-resource");
    Assert.assertEquals("subsystem.testsubsystem.test.special-names-resource", resource1.get(NAME).asString());
    params = extractParamsToMap(resource1);
    assertFeatureIdParam(SUBSYSTEM, TEST_SUBSYSTEM, params);
    assertFeatureIdParam(TEST, SPECIAL_NAMES_RESOURCE, params);
    Assert.assertTrue(params.containsKey("host-feature"));
    Assert.assertTrue(params.containsKey("test-feature"));
    Assert.assertTrue(params.containsKey("profile-feature"));

    ModelNode resource2 = feature.require(CHILDREN).require("subsystem.testsubsystem.resource.main-resource");
    Assert.assertEquals("subsystem.testsubsystem.resource.main-resource", resource2.get(NAME).asString());
    params = extractParamsToMap(resource2);
    assertFeatureIdParam(SUBSYSTEM, TEST_SUBSYSTEM, params);
    assertFeatureIdParam(RESOURCE, MAIN_RESOURCE, params);
    Assert.assertTrue(params.containsKey("optional-attr"));
    Assert.assertTrue(params.containsKey("mandatory-attr"));

    // check that nested resource children are also listed
    Assert.assertTrue(resource2.require(CHILDREN).get("subsystem.testsubsystem.resource.main-resource.list-attr").isDefined());
    Assert.assertTrue(resource2.require(CHILDREN).get("subsystem.testsubsystem.resource.main-resource.object-attr").isDefined());
}
 
Example 14
Source File: HostXml_10.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseServer(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> list,
                         final Set<String> serverNames) throws XMLStreamException {

    // Handle attributes
    final ModelNode addUpdate = parseServerAttributes(reader, parentAddress, serverNames);
    final ModelNode address = addUpdate.require(OP_ADDR);
    list.add(addUpdate);

    // Handle elements
    parseServerContent(reader, addUpdate, address, list);
}
 
Example 15
Source File: HostXml_6.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseServer(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> list,
                         final Set<String> serverNames) throws XMLStreamException {

    // Handle attributes
    final ModelNode addUpdate = parseServerAttributes(reader, parentAddress, serverNames);
    final ModelNode address = addUpdate.require(OP_ADDR);
    list.add(addUpdate);

    // Handle elements
    parseServerContent(reader, addUpdate, address, list);
}
 
Example 16
Source File: CachedDcDomainTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param hostname the hostname to query
 * @param requiredState the {@link ControlledProcessState.State} expected, or null for any state}
 * @return true if the host is present in the queried hosts's model (in the requiredState, if present), false otherwise.
 */
private boolean isHostPresentInModel(final String hostname, final ControlledProcessState.State requiredState) throws IOException {
    final ModelNode operation = new ModelNode();
    operation.get(OP).set(READ_ATTRIBUTE_OPERATION);
    operation.get(OP_ADDR).add(HOST, hostname);
    operation.get(NAME).set(HOST_STATE);

    ModelNode result;

    try (DomainClient client = getDomainClient(domainConfig.getMasterConfiguration())) {
        result = client.execute(operation);
        if (result.get(ModelDescriptionConstants.OUTCOME).asString().equals(ModelDescriptionConstants.SUCCESS)) {
            final ModelNode model = result.require(RESULT);
            if (requiredState == null) {
                return true;
            }
            return model.asString().equalsIgnoreCase(requiredState.toString());
        } else if (result.get(ModelDescriptionConstants.OUTCOME).asString().equals(FAILED)) {
            // make sure we get WFLYCTL0030: No resource definition is registered for address so we don't mistakenly hide other problems.
            if (result.require(FAILURE_DESCRIPTION).asString().contains("WFLYCTL0030")) {
                return false;
            }
            // otherwise we got a failure, but the host is present (perhaps still shutting down?), so return true
            return true;
        }
        // otherwise, something bad happened
        throw new RuntimeException(result != null ? result.toJSONString(false) : "Unknown error in determining host state.");
    }
}
 
Example 17
Source File: JdbcRealmDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static KeyMapper resolveKeyMappers(OperationContext context, ModelNode authenticationQueryNode) throws OperationFailedException {
    KeyMapper keyMapper = null;

    for (String name : authenticationQueryNode.keys()) {
        ModelNode propertyNode = authenticationQueryNode.require(name);

        if (!propertyNode.isDefined()) {
            continue;
        }

        PasswordMapperObjectDefinition mapperResource = PrincipalQueryAttributes.SUPPORTED_PASSWORD_MAPPERS.get(name);

        if (mapperResource == null) {
            continue;
        }

        if (keyMapper != null) {
            throw ROOT_LOGGER.jdbcRealmOnlySingleKeyMapperAllowed();
        }

        try {
            keyMapper = mapperResource.toPasswordKeyMapper(context, propertyNode);
        } catch (InvalidKeyException e) {
            throw new OperationFailedException("Invalid key type.", e);
        }
    }

    return keyMapper;
}
 
Example 18
Source File: ManagementXml_5.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void writeLdapAuthorization(XMLExtendedStreamWriter writer, ModelNode ldapNode) throws XMLStreamException {
    writer.writeStartElement(Element.LDAP.getLocalName());
    LdapAuthorizationResourceDefinition.CONNECTION.marshallAsAttribute(ldapNode, writer);
    if (ldapNode.hasDefined(USERNAME_TO_DN)) {
        ModelNode usenameToDn = ldapNode.require(USERNAME_TO_DN);
        if (usenameToDn.hasDefined(USERNAME_IS_DN) || usenameToDn.hasDefined(USERNAME_FILTER)
                || usenameToDn.hasDefined(ADVANCED_FILTER)) {
            writer.writeStartElement(Element.USERNAME_TO_DN.getLocalName());
            if (usenameToDn.hasDefined(USERNAME_IS_DN)) {
                ModelNode usernameIsDn = usenameToDn.require(USERNAME_IS_DN);
                UserIsDnResourceDefintion.FORCE.marshallAsAttribute(usernameIsDn, writer);
                writeLdapCacheIfDefined(writer, usernameIsDn);
                writer.writeEmptyElement(Element.USERNAME_IS_DN.getLocalName());
            } else if (usenameToDn.hasDefined(USERNAME_FILTER)) {
                ModelNode usernameFilter = usenameToDn.require(USERNAME_FILTER);
                UserSearchResourceDefintion.FORCE.marshallAsAttribute(usernameFilter, writer);
                writeLdapCacheIfDefined(writer, usernameFilter);
                writer.writeStartElement(Element.USERNAME_FILTER.getLocalName());
                UserSearchResourceDefintion.BASE_DN.marshallAsAttribute(usernameFilter, writer);
                UserSearchResourceDefintion.RECURSIVE.marshallAsAttribute(usernameFilter, writer);
                UserSearchResourceDefintion.USER_DN_ATTRIBUTE.marshallAsAttribute(usernameFilter, writer);
                UserSearchResourceDefintion.ATTRIBUTE.marshallAsAttribute(usernameFilter, writer);
                writer.writeEndElement();
            } else {
                ModelNode advancedFilter = usenameToDn.require(ADVANCED_FILTER);
                AdvancedUserSearchResourceDefintion.FORCE.marshallAsAttribute(advancedFilter, writer);
                writeLdapCacheIfDefined(writer, advancedFilter);
                writer.writeStartElement(Element.ADVANCED_FILTER.getLocalName());
                AdvancedUserSearchResourceDefintion.BASE_DN.marshallAsAttribute(advancedFilter, writer);
                AdvancedUserSearchResourceDefintion.RECURSIVE.marshallAsAttribute(advancedFilter, writer);
                AdvancedUserSearchResourceDefintion.USER_DN_ATTRIBUTE.marshallAsAttribute(advancedFilter, writer);
                AdvancedUserSearchResourceDefintion.FILTER.marshallAsAttribute(advancedFilter, writer);
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
    }

    if (ldapNode.hasDefined(GROUP_SEARCH)) {
        ModelNode groupSearch = ldapNode.require(GROUP_SEARCH);

        if (groupSearch.hasDefined(GROUP_TO_PRINCIPAL) || groupSearch.hasDefined(PRINCIPAL_TO_GROUP)) {
            writer.writeStartElement(Element.GROUP_SEARCH.getLocalName());
            if (groupSearch.hasDefined(GROUP_TO_PRINCIPAL)) {
                ModelNode groupToPrincipal = groupSearch.require(GROUP_TO_PRINCIPAL);
                GroupToPrincipalResourceDefinition.GROUP_NAME.marshallAsAttribute(groupToPrincipal, writer);
                GroupToPrincipalResourceDefinition.ITERATIVE.marshallAsAttribute(groupToPrincipal, writer);
                GroupToPrincipalResourceDefinition.GROUP_DN_ATTRIBUTE.marshallAsAttribute(groupToPrincipal, writer);
                GroupToPrincipalResourceDefinition.GROUP_NAME_ATTRIBUTE.marshallAsAttribute(groupToPrincipal, writer);
                writeLdapCacheIfDefined(writer, groupToPrincipal);
                writer.writeStartElement(Element.GROUP_TO_PRINCIPAL.getLocalName());
                GroupToPrincipalResourceDefinition.SEARCH_BY.marshallAsAttribute(groupToPrincipal, writer);
                GroupToPrincipalResourceDefinition.BASE_DN.marshallAsAttribute(groupToPrincipal, writer);
                GroupToPrincipalResourceDefinition.RECURSIVE.marshallAsAttribute(groupToPrincipal, writer);
                GroupToPrincipalResourceDefinition.PREFER_ORIGINAL_CONNECTION.marshallAsAttribute(groupToPrincipal, writer);
                writer.writeStartElement(Element.MEMBERSHIP_FILTER.getLocalName());
                GroupToPrincipalResourceDefinition.PRINCIPAL_ATTRIBUTE.marshallAsAttribute(groupToPrincipal, writer);
                writer.writeEndElement();
                writer.writeEndElement();
            } else {
                ModelNode principalToGroup = groupSearch.require(PRINCIPAL_TO_GROUP);
                PrincipalToGroupResourceDefinition.GROUP_NAME.marshallAsAttribute(principalToGroup, writer);
                PrincipalToGroupResourceDefinition.ITERATIVE.marshallAsAttribute(principalToGroup, writer);
                PrincipalToGroupResourceDefinition.GROUP_DN_ATTRIBUTE.marshallAsAttribute(principalToGroup, writer);
                PrincipalToGroupResourceDefinition.GROUP_NAME_ATTRIBUTE.marshallAsAttribute(principalToGroup, writer);
                writeLdapCacheIfDefined(writer, principalToGroup);
                writer.writeStartElement(Element.PRINCIPAL_TO_GROUP.getLocalName());
                PrincipalToGroupResourceDefinition.GROUP_ATTRIBUTE.marshallAsAttribute(principalToGroup, writer);
                PrincipalToGroupResourceDefinition.PREFER_ORIGINAL_CONNECTION.marshallAsAttribute(principalToGroup, writer);
                PrincipalToGroupResourceDefinition.SKIP_MISSING_GROUPS.marshallAsAttribute(principalToGroup, writer);
                PrincipalToGroupResourceDefinition.PARSE_ROLES_FROM_DN.marshallAsAttribute(principalToGroup, writer);
                writer.writeEndElement();
            }
            writer.writeEndElement();
        }
    }

    writer.writeEndElement();
}
 
Example 19
Source File: ReadChildrenNamesHandler.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 {

    final PathAddress address = context.getCurrentAddress();
    final String childType = CHILD_TYPE.resolveModelAttribute(context, operation).asString();
    final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS, false);
    ImmutableManagementResourceRegistration registry = context.getResourceRegistration();
    Map<String, Set<String>> childAddresses = GlobalOperationHandlers.getChildAddresses(context, address, registry, resource, childType);
    Set<String> childNames = childAddresses.get(childType);
    if (childNames == null) {
        throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.unknownChildType(childType));
    }
    final boolean singletons = INCLUDE_SINGLETONS.resolveModelAttribute(context, operation).asBoolean(false);
    if (singletons && isSingletonResource(registry, childType)) {
        Set<PathElement> childTypes = registry.getChildAddresses(PathAddress.EMPTY_ADDRESS);
        for (PathElement child : childTypes) {
            if (childType.equals(child.getKey())) {
                childNames.add(child.getValue());
            }
        }
    }
    // Sort the result
    childNames = new TreeSet<String>(childNames);
    ModelNode result = context.getResult();
    result.setEmptyList();
    PathAddress childAddress = address.append(PathElement.pathElement(childType));
    ModelNode op = Util.createEmptyOperation(READ_RESOURCE_OPERATION, childAddress);
    op.get(OPERATION_HEADERS).set(operation.get(OPERATION_HEADERS));
    ModelNode opAddr = op.get(OP_ADDR);
    ModelNode childProperty = opAddr.require(address.size());
    Set<Action.ActionEffect> actionEffects = EnumSet.of(Action.ActionEffect.ADDRESS);
    FilteredData fd = null;
    for (String childName : childNames) {
        childProperty.set(childType, new ModelNode(childName));
        if (context.authorize(op, actionEffects).getDecision() == AuthorizationResult.Decision.PERMIT) {
            result.add(childName);
        } else {
            if (fd == null) {
                fd = new FilteredData(address);
            }
            fd.addAccessRestrictedResource(childAddress);
        }
    }

    if (fd != null) {
        context.getResponseHeaders().get(ACCESS_CONTROL).set(fd.toModelNode());
    }
}
 
Example 20
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);
}