Java Code Examples for org.jboss.dmr.ModelType#EXPRESSION

The following examples show how to use org.jboss.dmr.ModelType#EXPRESSION . 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: AttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Finds a value in the given {@code operationObject} whose key matches this attribute's {@link #getName() name},
 * validates it using this attribute's {@link #getValidator() validator}, and, stores it under this attribute's name in the given {@code model}.
 *
 * @param operationObject model node of type {@link ModelType#OBJECT}, typically representing an operation request
 * @param model model node in which the value should be stored
 *
 * @throws OperationFailedException if the value is not valid
 */
public final void validateAndSet(ModelNode operationObject, final ModelNode model) throws OperationFailedException {
    if (operationObject.hasDefined(name) && deprecationData != null && deprecationData.isNotificationUseful()) {
        ControllerLogger.DEPRECATED_LOGGER.attributeDeprecated(getName(),
                PathAddress.pathAddress(operationObject.get(ModelDescriptionConstants.OP_ADDR)).toCLIStyleString());
    }
    // AS7-6224 -- convert expression strings to ModelType.EXPRESSION *before* correcting
    ModelNode newValue = convertParameterExpressions(operationObject.get(name));
    final ModelNode correctedValue = correctValue(newValue, model.get(name));
    if (!correctedValue.equals(operationObject.get(name))) {
        operationObject.get(name).set(correctedValue);
    }
    ModelNode node = validateOperation(operationObject, true);
    if (node.getType() == ModelType.EXPRESSION
            && (referenceRecorder != null || flags.contains(AttributeAccess.Flag.EXPRESSIONS_DEPRECATED))) {
        ControllerLogger.DEPRECATED_LOGGER.attributeExpressionDeprecated(getName(),
            PathAddress.pathAddress(operationObject.get(ModelDescriptionConstants.OP_ADDR)).toCLIStyleString());
    }
    model.get(name).set(node);
}
 
Example 2
Source File: SecurityRealmAddHandler.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private Supplier<CallbackHandlerFactory> addSecretService(OperationContext context, ModelNode secret, String realmName, ServiceTarget serviceTarget,
                              ServiceBuilder<?> realmBuilder) throws OperationFailedException {
    final ServiceName secretServiceName = SecretIdentityService.ServiceUtil.createServiceName(realmName);
    final ModelNode resolvedValueNode = SecretServerIdentityResourceDefinition.VALUE.resolveModelAttribute(context, secret);
    boolean base64 = secret.get(SecretServerIdentityResourceDefinition.VALUE.getName()).getType() != ModelType.EXPRESSION;
    final ServiceBuilder<?> builder = serviceTarget.addService(secretServiceName);
    final Consumer<CallbackHandlerFactory> chfConsumer = builder.provides(secretServiceName);
    ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = null;
    if (secret.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
        String keySuffix = SERVER_IDENTITY + KEY_DELIMITER + SECRET;
        credentialSourceSupplier = CredentialReference.getCredentialSourceSupplier(context, SecretServerIdentityResourceDefinition.CREDENTIAL_REFERENCE, secret, builder, keySuffix);
    }
    SecretIdentityService sis;
    if (secret.hasDefined(CredentialReference.CREDENTIAL_REFERENCE)) {
        sis = new SecretIdentityService(chfConsumer, credentialSourceSupplier, resolvedValueNode.asString(), false);
    } else {
        sis = new SecretIdentityService(chfConsumer, credentialSourceSupplier, resolvedValueNode.asString(), base64);
    }
    builder.setInstance(sis);
    builder.setInitialMode(ON_DEMAND);
    builder.install();

    return CallbackHandlerFactory.ServiceUtil.requires(realmBuilder, secretServiceName);
}
 
Example 3
Source File: AttributeTransformationRequirementChecker.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Check an attribute for expressions.
 *
 * @param node the attribute value
 * @return whether an expression was found or not
 */
private boolean checkForExpression(final ModelNode node) {
    if (!node.isDefined()) {
        return false;
    }

    final ModelNode resolved = node.clone();
    if (node.getType() == ModelType.EXPRESSION || node.getType() == ModelType.STRING) {
        return checkForExpression(resolved.asString());
    } else if (node.getType() == ModelType.OBJECT) {
        for (Property prop : resolved.asPropertyList()) {
            if(checkForExpression(prop.getValue())) {
                return true;
            }
        }
    } else if (node.getType() == ModelType.LIST) {
        for (ModelNode current : resolved.asList()) {
            if(checkForExpression(current)) {
                return true;
            }
        }
    } else if (node.getType() == ModelType.PROPERTY) {
        return checkForExpression(resolved.asProperty().getValue());
    }
    return false;
}
 
Example 4
Source File: RejectAttributeChecker.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Check an attribute for expressions.
 *
 * @param node the attribute value
 * @return whether an expression was found or not
 */
private boolean checkForExpression(final ModelNode node) {
    if (!node.isDefined()) {
        return false;
    }

    final ModelNode resolved = node.clone();
    if (node.getType() == ModelType.EXPRESSION || node.getType() == ModelType.STRING) {
        return checkForExpression(resolved.asString());
    } else if (node.getType() == ModelType.OBJECT) {
        for (Property prop : resolved.asPropertyList()) {
            if (checkForExpression(prop.getValue())) {
                return true;
            }
        }
    } else if (node.getType() == ModelType.LIST) {
        for (ModelNode current : resolved.asList()) {
            if (checkForExpression(current)) {
                return true;
            }
        }
    } else if (node.getType() == ModelType.PROPERTY) {
        return checkForExpression(resolved.asProperty().getValue());
    }
    return false;
}
 
Example 5
Source File: IntRangeValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);
    if (value.isDefined() && value.getType() != ModelType.EXPRESSION) {
        int val = value.asInt();
        if (val < min) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMinValue(val, parameterName, min));
        }
        else if (val > max) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMaxValue(val, parameterName, max));
        }
    }
}
 
Example 6
Source File: AttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Based on the given attribute value, add capability requirements. If this definition
 * is for an attribute whose value is or contains a reference to the name of some capability,
 * this method should record the addition of a requirement for the capability.
 * <p>
 * This is a no-op in this base class. Subclasses that support attribute types that can represent
 * capability references should override this method.
 *  @param context the operation context
 * @param resource
 * @param attributeValue the value of the attribute described by this object
 */
public void addCapabilityRequirements(OperationContext context, Resource resource, ModelNode attributeValue) {
    @SuppressWarnings("deprecation")
    CapabilityReferenceRecorder refRecorder = getReferenceRecorder();
    if (refRecorder != null) {
        // We can't process expressions
        if (attributeValue.getType() != ModelType.EXPRESSION) {
            ModelNode value = attributeValue.isDefined() ? attributeValue : (defaultValue != null) ? defaultValue : new ModelNode();
            refRecorder.addCapabilityRequirements(context, resource, name, value.isDefined() ? value.asString() : null);
        }
    }
}
 
Example 7
Source File: StringBytesLengthValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);
    if (value.isDefined() && value.getType() != ModelType.EXPRESSION) {
        String str = value.asString();
        if (str.getBytes().length < min) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMinBytesLength(str, parameterName, min));
        }
        else if (str.getBytes().length > max) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMaxBytesLength(str, parameterName, max));
        }
    }
}
 
Example 8
Source File: LongRangeValidator.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException {
    super.validateParameter(parameterName, value);
    if (value.isDefined() && value.getType() != ModelType.EXPRESSION) {
        long val = value.asLong();
        if (val < min) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMinValue(val, parameterName, min));
        }
        else if (val > max) {
            throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.invalidMaxValue(val, parameterName, max));
        }
    }
}
 
Example 9
Source File: ExpressionResolverImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Examine the given model node, resolving any expressions found within, including within child nodes.
 *
 * @param node the node
 * @return a node with all expressions resolved
 * @throws OperationFailedException if an expression cannot be resolved
 */
private ModelNode resolveExpressionsRecursively(final ModelNode node) throws OperationFailedException {
    if (!node.isDefined()) {
        return node;
    }

    ModelType type = node.getType();
    ModelNode resolved;
    if (type == ModelType.EXPRESSION) {
        resolved = resolveExpressionStringRecursively(node.asExpression().getExpressionString(), lenient, true);
    } else if (type == ModelType.OBJECT) {
        resolved = node.clone();
        for (Property prop : resolved.asPropertyList()) {
            resolved.get(prop.getName()).set(resolveExpressionsRecursively(prop.getValue()));
        }
    } else if (type == ModelType.LIST) {
        resolved = node.clone();
        ModelNode list = new ModelNode();
        list.setEmptyList();
        for (ModelNode current : resolved.asList()) {
            list.add(resolveExpressionsRecursively(current));
        }
        resolved = list;
    } else if (type == ModelType.PROPERTY) {
        resolved = node.clone();
        resolved.set(resolved.asProperty().getName(), resolveExpressionsRecursively(resolved.asProperty().getValue()));
    } else {
        resolved = node;
    }

    return resolved;
}
 
Example 10
Source File: HostXml_6.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 11
Source File: AttributeDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private ModelNode convertToExpectedType(final ModelNode node) {
    ModelType nodeType = node.getType();
    if (nodeType == type || nodeType == ModelType.UNDEFINED || nodeType == ModelType.EXPRESSION || Util.isExpression(node.asString())) {
        return node;
    }
    switch (type) {
        case BIG_DECIMAL:
            return new ModelNode(node.asBigDecimal());
        case BIG_INTEGER:
            return new ModelNode(node.asBigInteger());
        case BOOLEAN:
            return new ModelNode(node.asBoolean());
        case BYTES:
            return new ModelNode(node.asBytes());
        case DOUBLE:
            return new ModelNode(node.asDouble());
        case INT:
            return new ModelNode(node.asInt());
        case LIST:
            return new ModelNode().set(node.asList());
        case LONG:
            return new ModelNode(node.asLong());
        case PROPERTY:
            return new ModelNode().set(node.asProperty());
        case TYPE:
            return new ModelNode(node.asType());
        case STRING:
            return new ModelNode(node.asString());
        case OBJECT:
            // Check for LIST of PROPERTY. If that is found convert.
            // But only convert if that specifically is found in order
            // to avoid odd unintended conversions (e.g. LIST of STRING, which DMR can convert to OBJECT)
            if (nodeType == ModelType.LIST) {
                if (node.asInt() == 0) {
                    return new ModelNode().setEmptyObject();
                }
                ModelNode first = node.get(0);
                if (first.getType() != ModelType.PROPERTY) {
                    return node;
                }
                // Now we know at least the first element is property, so
                // we assume the rest are as well.
                List<Property> propertyList;
                try {
                    propertyList = node.asPropertyList();
                } catch (IllegalArgumentException iae) {
                    // ignore. The validator allowed this node or we wouldn't be here,
                    // so just fall through and return the unconverted node
                    // Note this isn't expected to be a real world case
                    return node;
                }
                ModelNode result = new ModelNode().setEmptyObject();
                for (Property prop : propertyList) {
                    result.get(prop.getName()).set(prop.getValue());
                }
                return result;
            }
            return node;
        default:
            return node;
    }
}
 
Example 12
Source File: HostXml_11.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 13
Source File: HostXml_Legacy.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseRemoteDomainControllerAttributes_1_3(final XMLExtendedStreamReader reader, final ModelNode address,
        final List<ModelNode> list) throws XMLStreamException {
    // Handle attributes
    String host = null;
    ModelNode port = null;
    String securityRealm = null;
    String username = null;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    host = value;
                    break;
                }
                case PORT: {
                    port = parsePossibleExpression(value);
                    if(port.getType() != ModelType.EXPRESSION) {
                        try {
                            int portNo = Integer.parseInt(value);
                            if (portNo < 1) {
                                throw ControllerLogger.ROOT_LOGGER.invalidPort(attribute.getLocalName(), value, reader.getLocation());
                            }
                        }catch(NumberFormatException e) {
                            throw ControllerLogger.ROOT_LOGGER.invalidPort(attribute.getLocalName(), value, reader.getLocation());
                        }
                    }
                    break;
                }
                case SECURITY_REALM: {
                    securityRealm = value;
                    break;
                }
                case USERNAME: {
                    username = value;
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }
    if (host == null) {
        throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.HOST.getLocalName()));
    }
    if (port == null) {
        throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.PORT.getLocalName()));
    }

    final ModelNode update = new ModelNode();
    update.get(OP_ADDR).set(address);
    update.get(OP).set(RemoteDomainControllerAddHandler.OPERATION_NAME);
    update.get(HOST).set(parsePossibleExpression(host));
    update.get(PORT).set(port);
    if (securityRealm != null) {
        update.get(SECURITY_REALM).set(securityRealm);
    }
    if (username != null) {
        update.get(USERNAME).set(username);
    }
    list.add(update);
}
 
Example 14
Source File: HostXml_Legacy.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * The only difference between version 1.5 and 1.6 of the schema were to make is possible to define discovery options, this
 * resulted in the host and port attributes becoming optional -this method also indicates if discovery options are required
 * where the host and port were not supplied.
 *
 * @param allowDiscoveryOptions i.e. are host and port potentially optional?
 * @return true if discovery options are required, i.e. no host and port set and the admin policy requires a config.
 */
private boolean parseRemoteDomainControllerAttributes_1_5(final XMLExtendedStreamReader reader, final ModelNode address,
                                                          final List<ModelNode> list, boolean allowDiscoveryOptions) throws XMLStreamException {

    final ModelNode update = new ModelNode();
    update.get(OP_ADDR).set(address);
    update.get(OP).set(RemoteDomainControllerAddHandler.OPERATION_NAME);

    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, update, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, update, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, update, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, update, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, update, reader);
                    ModelNode nodeValue = update.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!update.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        if (allowDiscoveryOptions) {
            requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
        } else {
            throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.HOST.getLocalName()));
        }
    }
    if (!update.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        if (allowDiscoveryOptions) {
            requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
        } else {
            throw ParseUtils.missingRequired(reader, Collections.singleton(Attribute.PORT.getLocalName()));
        }
    }

    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 15
Source File: HostXml_8.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 16
Source File: HostXml_4.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                          final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 17
Source File: HostXml_10.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 18
Source File: HostXml_13.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}
 
Example 19
Source File: SocketBindingsXml.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
String parseSocketBinding(final XMLExtendedStreamReader reader, final Set<String> interfaces,
        final ModelNode address, final List<ModelNode> updates) throws XMLStreamException {

    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME);
    String name = null;

    final ModelNode binding = new ModelNode();
    binding.get(OP_ADDR); // undefined until we parse name
    binding.get(OP).set(ADD);

    // Handle attributes
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            required.remove(attribute);
            switch (attribute) {
                case NAME: {
                    name = value;
                    binding.get(OP_ADDR).set(address).add(SOCKET_BINDING, name);
                    break;
                }
                case INTERFACE: {
                    AbstractSocketBindingResourceDefinition.INTERFACE.parseAndSetParameter(value, binding, reader);
                    if (binding.get(AbstractSocketBindingResourceDefinition.INTERFACE.getName()).getType() != ModelType.EXPRESSION
                            && !interfaces.contains(value)) {
                        throw ControllerLogger.ROOT_LOGGER.unknownInterface(value, attribute.getLocalName(),
                                Element.INTERFACES.getLocalName(), reader.getLocation());
                    }
                    binding.get(INTERFACE).set(value);
                    break;
                }
                case PORT: {
                    AbstractSocketBindingResourceDefinition.PORT.parseAndSetParameter(value, binding, reader);
                    break;
                }
                case FIXED_PORT: {
                    AbstractSocketBindingResourceDefinition.FIXED_PORT.parseAndSetParameter(value, binding, reader);
                    break;
                }
                case MULTICAST_ADDRESS: {
                    AbstractSocketBindingResourceDefinition.MULTICAST_ADDRESS.parseAndSetParameter(value, binding, reader);
                    break;
                }
                case MULTICAST_PORT: {
                    AbstractSocketBindingResourceDefinition.MULTICAST_PORT.parseAndSetParameter(value, binding, reader);
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }

    // Handle elements
    while (reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        switch (element) {
            case CLIENT_MAPPING:
                binding.get(CLIENT_MAPPINGS).add(parseClientMapping(reader));
                break;
            default:
                throw unexpectedElement(reader);
        }
    }

    updates.add(binding);
    return name;
}
 
Example 20
Source File: HostXml_12.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private boolean parseRemoteDomainControllerAttributes(final XMLExtendedStreamReader reader, final ModelNode address,
                                                      final List<ModelNode> list) throws XMLStreamException {

    final ModelNode remoteDc = new ModelNode();
    final ModelNode updateDc = remoteDc.get(REMOTE).setEmptyObject() ;
    // Handle attributes
    AdminOnlyDomainConfigPolicy adminOnlyPolicy = AdminOnlyDomainConfigPolicy.DEFAULT;
    boolean requireDiscoveryOptions = false;
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        final String value = reader.getAttributeValue(i);
        if (!isNoNamespaceAttribute(reader, i)) {
            throw unexpectedAttribute(reader, i);
        } else {
            final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
            switch (attribute) {
                case HOST: {
                    DomainControllerWriteAttributeHandler.HOST.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PORT: {
                    DomainControllerWriteAttributeHandler.PORT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case PROTOCOL: {
                    DomainControllerWriteAttributeHandler.PROTOCOL.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case AUTHENTICATION_CONTEXT: {
                    DomainControllerWriteAttributeHandler.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case SECURITY_REALM: {
                    DomainControllerWriteAttributeHandler.SECURITY_REALM.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case USERNAME: {
                    DomainControllerWriteAttributeHandler.USERNAME.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case IGNORE_UNUSED_CONFIG: {
                    DomainControllerWriteAttributeHandler.IGNORE_UNUSED_CONFIG.parseAndSetParameter(value, updateDc, reader);
                    break;
                }
                case ADMIN_ONLY_POLICY: {
                    DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.parseAndSetParameter(value, updateDc, reader);
                    ModelNode nodeValue = updateDc.get(DomainControllerWriteAttributeHandler.ADMIN_ONLY_POLICY.getName());
                    if (nodeValue.getType() != ModelType.EXPRESSION) {
                        adminOnlyPolicy = AdminOnlyDomainConfigPolicy.getPolicy(nodeValue.asString());
                    }
                    break;
                }
                default:
                    throw unexpectedAttribute(reader, i);
            }
        }
    }

    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.HOST.getName())) {
        requireDiscoveryOptions = isRequireDiscoveryOptions(adminOnlyPolicy);
    }
    if (!updateDc.hasDefined(DomainControllerWriteAttributeHandler.PORT.getName())) {
        requireDiscoveryOptions = requireDiscoveryOptions || isRequireDiscoveryOptions(adminOnlyPolicy);
    }

    final ModelNode update = Util.getWriteAttributeOperation(address, DOMAIN_CONTROLLER, remoteDc);
    list.add(update);
    return requireDiscoveryOptions;
}