Java Code Examples for org.jboss.as.controller.parsing.ParseUtils#unexpectedElement()

The following examples show how to use org.jboss.as.controller.parsing.ParseUtils#unexpectedElement() . 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: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void readRoleIdentifiers(ModelNode addServiceProvider, XMLExtendedStreamReader reader) throws XMLStreamException {
    ParseUtils.requireNoAttributes(reader);

    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();

        if (!Constants.XML.ATTRIBUTE.equals(tagName)) {
            throw ParseUtils.unexpectedElement(reader);
        }

        ParseUtils.requireSingleAttribute(reader, Constants.XML.NAME);
        String name = ParseUtils.readStringAttributeElement(reader, Constants.XML.NAME);

        ServiceProviderDefinition.ROLE_ATTRIBUTES.parseAndAddParameterElement(name, addServiceProvider, reader);
    }
}
 
Example 2
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void readSecureDeployment(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    String name = readRequiredAttribute(reader, Constants.XML.NAME);

    PathAddress addr = PathAddress.pathAddress(
            PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, KeycloakSamlExtension.SUBSYSTEM_NAME),
            PathElement.pathElement(Constants.Model.SECURE_DEPLOYMENT, name));
    ModelNode addSecureDeployment = Util.createAddOperation(addr);
    list.add(addSecureDeployment);

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the secure deployment type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }
        if (tagName.equals(Constants.XML.SERVICE_PROVIDER)) {
            readServiceProvider(reader, list, addr);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 3
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException {
    // Require no attributes
    ParseUtils.requireNoAttributes(reader);
    ModelNode addKeycloakSub = Util.createAddOperation(PathAddress.pathAddress(KeycloakSamlExtension.PATH_SUBSYSTEM));
    list.add(addKeycloakSub);

    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        if (reader.getLocalName().equals(Constants.XML.SECURE_DEPLOYMENT)) {
            readSecureDeployment(reader, list);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
    }
}
 
Example 4
Source File: PersistentResourceXMLDescription.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void parseGroup(XMLExtendedStreamReader reader, ModelNode op, boolean wildcard) throws XMLStreamException {
    Map<String, AttributeDefinition> groupAttrs = attributesByGroup.get(reader.getLocalName());
    for (AttributeDefinition attrGroup : groupAttrs.values()) {
        if (op.hasDefined(attrGroup.getName())) {
            throw ParseUtils.unexpectedElement(reader);
        }
    }
    parseAttributes(reader, op, groupAttrs, wildcard);
    // Check if there are also element attributes inside a group
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        AttributeDefinition ad = groupAttrs.get(reader.getLocalName());
        if (ad != null) {
            ad.getParser().parseElement(ad, reader, op);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
    }
}
 
Example 5
Source File: PersistentResourceXMLDescription.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Parse xml from provided <code>reader</code> and add resulting operations to passed list
 * @param reader xml reader to parse from
 * @param parentAddress address of the parent, used as base for all child elements
 * @param list list of operations where result will be put to.
 * @throws XMLStreamException if any error occurs while parsing
 */
public void parse(final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list) throws XMLStreamException {
    if (decoratorElement != null) {
        parseDecorator(reader, parentAddress, list);
        return;
    }
    if (xmlWrapperElement != null) {
        if (reader.getLocalName().equals(xmlWrapperElement)) {
            if (reader.hasNext() && reader.nextTag() == END_ELEMENT) { return; }
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parseInternal(reader, parentAddress, list);
        while (reader.nextTag() != END_ELEMENT && !reader.getLocalName().equals(xmlWrapperElement)) {
            parseInternal(reader, parentAddress, list);
        }
    } else {
        parseInternal(reader, parentAddress, list);
    }
}
 
Example 6
Source File: AttributeParsers.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void parseElement(AttributeDefinition attribute, XMLExtendedStreamReader reader, ModelNode operation) throws XMLStreamException {
    ObjectTypeAttributeDefinition objectType = getObjectType(attribute);

    ModelNode listValue = operation.get(attribute.getName());
    if (!listValue.isDefined()){
        listValue.setEmptyList();
    }
    String xmlName = objectType.getXmlName();
    if (xmlName.equals(reader.getLocalName())) {
        ModelNode op = listValue.add();
        parseEmbeddedElement(objectType, reader, op);
    } else {
        throw ParseUtils.unexpectedElement(reader, Collections.singleton(xmlName));
    }
    if (!reader.isEndElement()) {
        ParseUtils.requireNoContent(reader);
    }
}
 
Example 7
Source File: JMXExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    ParseUtils.requireNoAttributes(reader);
    list.add(createAddOperation());

    boolean gotConnector = false;

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final String element = reader.getLocalName();
        switch (element) {
            case CommonAttributes.JMX_CONNECTOR: {
                if (gotConnector) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.JMX_CONNECTOR);
                }
                parseConnector(reader);
                gotConnector = true;
                break;
            }
            default: {
                throw ParseUtils.unexpectedElement(reader);
            }
        }
    }
}
 
Example 8
Source File: JMXExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseAuditLogHandlers(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    ParseUtils.requireNoAttributes(reader);

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final String element = reader.getLocalName();
        switch (element) {
            case HANDLER:
                parseAuditLogHandler(reader, list);
                break;
            default: {
                throw ParseUtils.unexpectedElement(reader);
            }
        }
    }
}
 
Example 9
Source File: JMXExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void parseAuditLogElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {

            ModelNode op = createOperation(ADD, JmxAuditLoggerResourceDefinition.PATH_ELEMENT.getKey(), JmxAuditLoggerResourceDefinition.PATH_ELEMENT.getValue());

            final int count = reader.getAttributeCount();
            for (int i = 0; i < count; i++) {
                final String value = reader.getAttributeValue(i);
                final String attribute = reader.getAttributeLocalName(i);
                switch (attribute) {
                    case CommonAttributes.LOG_BOOT: {
                        JmxAuditLoggerResourceDefinition.LOG_BOOT.parseAndSetParameter(value, op, reader);
                        break;
                    }
                    case CommonAttributes.LOG_READ_ONLY: {
                        JmxAuditLoggerResourceDefinition.LOG_READ_ONLY.parseAndSetParameter(value, op, reader);
                        break;
                    }
                    case CommonAttributes.ENABLED: {
                        JmxAuditLoggerResourceDefinition.ENABLED.parseAndSetParameter(value, op, reader);
                        break;
                    }
                    default: {
                        throw ParseUtils.unexpectedAttribute(reader, i);
                    }
                }
            }
            list.add(op);

            while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
                final String element = reader.getLocalName();
                switch (element) {
                    case CommonAttributes.HANDLERS:
                        parseAuditLogHandlers(reader, list);
                        break;
                    default: {
                        throw ParseUtils.unexpectedElement(reader);
                    }
                }
            }
        }
 
Example 10
Source File: JMXExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    boolean showResolvedModel = false;
    boolean showExpressionModel = false;
    boolean connectorAdd = false;

    ParseUtils.requireNoAttributes(reader);

    list.add(createAddOperation());

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final String element = reader.getLocalName();
        switch (element) {
            case CommonAttributes.EXPOSE_RESOLVED_MODEL:
                if (showResolvedModel) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.EXPOSE_RESOLVED_MODEL);
                }
                showResolvedModel = true;
                list.add(parseShowModelElement(reader, CommonAttributes.RESOLVED));
                break;
            case CommonAttributes.EXPOSE_EXPRESSION_MODEL:
                if (showExpressionModel) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.EXPOSE_EXPRESSION_MODEL);
                }
                showExpressionModel = true;
                list.add(parseShowModelElement(reader, CommonAttributes.EXPRESSION));
                break;
            case REMOTING_CONNECTOR:
                if (connectorAdd) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.REMOTING_CONNECTOR);
                }
                connectorAdd = true;
                list.add(parseRemoteConnector(reader));
                break;
            default: {
                throw ParseUtils.unexpectedElement(reader);
            }
        }
    }
}
 
Example 11
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readKey(List<ModelNode> list, XMLExtendedStreamReader reader, PathAddress parentAddr) throws XMLStreamException {
    PathAddress addr = PathAddress.pathAddress(parentAddr,
            PathElement.pathElement(Constants.Model.KEY, "key-" + list.size()));
    ModelNode addKey = Util.createAddOperation(addr);
    list.add(addKey);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = KeyDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKey, reader);
    }

    Set<String> parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the key type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }

        if (Constants.XML.KEY_STORE.equals(tagName)) {
            readKeyStore(addKey, reader);
        } else if (Constants.XML.PRIVATE_KEY_PEM.equals(tagName)
                || Constants.XML.PUBLIC_KEY_PEM.equals(tagName)
                || Constants.XML.CERTIFICATE_PEM.equals(tagName)) {

            readNoAttrElementContent(KeyDefinition.lookupElement(tagName), addKey, reader);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 12
Source File: JMXExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    boolean showModel = false;

    ParseUtils.requireNoAttributes(reader);

    ModelNode connectorAdd = null;
    list.add(createAddOperation());
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final String element = reader.getLocalName();
        switch (element) {
            case CommonAttributes.SHOW_MODEL:
                if (showModel) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.SHOW_MODEL);
                }
                if (parseShowModelElement(reader)) {
                    //Add the show-model=>resolved part with the default domain name
                    ModelNode op = createOperation(ADD, CommonAttributes.EXPOSE_MODEL, CommonAttributes.RESOLVED);
                    //Use false here to keep total backwards compatibility
                    op.get(CommonAttributes.PROPER_PROPERTY_FORMAT).set(false);
                    list.add(op);
                }
                showModel = true;
                break;
            case CommonAttributes.REMOTING_CONNECTOR: {
                if (connectorAdd != null) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.REMOTING_CONNECTOR);
                }
                list.add(parseRemoteConnector(reader));
                break;
            }
            default: {
                throw ParseUtils.unexpectedElement(reader);
            }
        }
    }
}
 
Example 13
Source File: RemotingSubsystem11Parser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void parseRemoteOutboundConnection(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> operations) throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.OUTBOUND_SOCKET_BINDING_REF);
    final int count = reader.getAttributeCount();
    String name = null;
    String outboundSocketBindingRef = null;
    ModelNode username = null;
    String securityRealm = null;
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME: {
                name = value;
                break;
            }
            case OUTBOUND_SOCKET_BINDING_REF: {
                outboundSocketBindingRef = value;
                break;
            }
            case USERNAME: {
                username = RemoteOutboundConnectionResourceDefinition.USERNAME.parse(value, reader);
                break;
            }
            case SECURITY_REALM: {
                securityRealm = value;
                break;
            }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    final PathAddress address = PathAddress.pathAddress(PathAddress.pathAddress(parentAddress), PathElement.pathElement(CommonAttributes.REMOTE_OUTBOUND_CONNECTION, name));

    // create add operation add it to the list of operations
    ModelNode connectionAddOperation = getConnectionAddOperation(name, outboundSocketBindingRef, username, securityRealm, address);
    operations.add(connectionAddOperation);
    // parse the nested elements
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (visited.contains(element)) {
            throw ParseUtils.unexpectedElement(reader);
        }
        visited.add(element);
        switch (element) {
            case PROPERTIES: {
                parseProperties(reader, address.toModelNode(), operations);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }

}
 
Example 14
Source File: RemotingSubsystem11Parser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void parseLocalOutboundConnection(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> operations) throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.OUTBOUND_SOCKET_BINDING_REF);
    final int count = reader.getAttributeCount();
    String name = null;
    String outboundSocketBindingRef = null;
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME: {
                name = value;
                break;
            }
            case OUTBOUND_SOCKET_BINDING_REF: {
                outboundSocketBindingRef = value;
                break;
            }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }

    final PathAddress address = PathAddress.pathAddress(PathAddress.pathAddress(parentAddress), PathElement.pathElement(CommonAttributes.LOCAL_OUTBOUND_CONNECTION, name));
    // add it to the list of operations
    operations.add(getConnectionAddOperation(name, outboundSocketBindingRef, address));
    // create add operation parse the nested elements

    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (visited.contains(element)) {
            throw ParseUtils.unexpectedElement(reader);
        }
        visited.add(element);
        switch (element) {
            case PROPERTIES: {
                parseProperties(reader, address.toModelNode(), operations);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
}
 
Example 15
Source File: RemotingSubsystem11Parser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
void parseOutboundConnection(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> operations) throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.URI);
    final int count = reader.getAttributeCount();
    String name = null;
    String uri = null;
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME: {
                name = value;
                break;
            }
            case URI: {
                uri = value;
                break;
            }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }

    final PathAddress address = PathAddress.pathAddress(PathAddress.pathAddress(parentAddress), PathElement.pathElement(CommonAttributes.OUTBOUND_CONNECTION, name));
    // create add operation add it to the list of operations
    operations.add(GenericOutboundConnectionAdd.getAddOperation(name, uri, address));
    // parse the nested elements
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (visited.contains(element)) {
            throw ParseUtils.unexpectedElement(reader);
        }
        visited.add(element);
        switch (element) {
            case PROPERTIES: {
                parseProperties(reader, address.toModelNode(), operations);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }


}
 
Example 16
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 4 votes vote down vote up
void readServiceProvider(XMLExtendedStreamReader reader, List<ModelNode> list, PathAddress parentAddr) throws XMLStreamException {
    String entityId = readRequiredAttribute(reader, Constants.XML.ENTITY_ID);

    PathAddress addr = PathAddress.pathAddress(parentAddr,
            PathElement.pathElement(Constants.Model.SERVICE_PROVIDER, entityId));
    ModelNode addServiceProvider = Util.createAddOperation(addr);
    list.add(addServiceProvider);

    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        if (Constants.XML.ENTITY_ID.equals(name)) {
            continue;
        }

        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = ServiceProviderDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addServiceProvider, reader);
    }

    Set parsedElements = new HashSet<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (parsedElements.contains(tagName)) {
            // all sub-elements of the service provider type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }

        if (Constants.XML.KEYS.equals(tagName)) {
            readKeys(list, reader, addr);
        } else if (Constants.XML.PRINCIPAL_NAME_MAPPING.equals(tagName)) {
            readPrincipalNameMapping(addServiceProvider, reader);
        } else if (Constants.XML.ROLE_IDENTIFIERS.equals(tagName)) {
            readRoleIdentifiers(addServiceProvider, reader);
        } else if (Constants.XML.ROLE_MAPPINGS_PROVIDER.equals(tagName)) {
            readRoleMappingsProvider(addServiceProvider, reader);
        } else if (Constants.XML.IDENTITY_PROVIDER.equals(tagName)) {
            readIdentityProvider(list, reader, addr);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
 
Example 17
Source File: RemotingSubsystem10Parser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
ModelNode parsePolicyElement(XMLExtendedStreamReader reader, final ModelNode address, final List<ModelNode> list) throws XMLStreamException {
    final ModelNode policy = new ModelNode();
    policy.get(OP).set(ADD);
    policy.get(OP_ADDR).set(address).add(SaslPolicyResource.SASL_POLICY_CONFIG_PATH.getKey(), SaslPolicyResource.SASL_POLICY_CONFIG_PATH.getValue());
    list.add(policy);

    if (reader.getAttributeCount() > 0) {
        throw ParseUtils.unexpectedAttribute(reader, 0);
    }
    // Handle nested elements.
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (visited.contains(element)) {
            throw ParseUtils.unexpectedElement(reader);
        }
        visited.add(element);
        switch (element) {
            case FORWARD_SECRECY: {
                SaslPolicyResource.FORWARD_SECRECY.parseAndSetParameter(readStringAttributeElement(reader, "value"), policy, reader);
                break;
            }
            case NO_ACTIVE: {
                SaslPolicyResource.NO_ACTIVE.parseAndSetParameter(readStringAttributeElement(reader, "value"), policy, reader);
                break;
            }
            case NO_ANONYMOUS: {
                SaslPolicyResource.NO_ANONYMOUS.parseAndSetParameter(readStringAttributeElement(reader, "value"), policy, reader);
                break;
            }
            case NO_DICTIONARY: {
                SaslPolicyResource.NO_DICTIONARY.parseAndSetParameter(readStringAttributeElement(reader, "value"), policy, reader);
                break;
            }
            case NO_PLAIN_TEXT: {
                SaslPolicyResource.NO_PLAIN_TEXT.parseAndSetParameter(readStringAttributeElement(reader, "value"), policy, reader);
                break;
            }
            case PASS_CREDENTIALS: {
                SaslPolicyResource.PASS_CREDENTIALS.parseAndSetParameter(readStringAttributeElement(reader, "value"), policy, reader);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }
    return policy;
}
 
Example 18
Source File: RemotingSubsystem40Parser.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
void parseRemoteOutboundConnection(final XMLExtendedStreamReader reader, final ModelNode parentAddress, final List<ModelNode> operations) throws XMLStreamException {
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.OUTBOUND_SOCKET_BINDING_REF);
    final int count = reader.getAttributeCount();
    String name = null;
    final ModelNode addOperation = Util.createAddOperation();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch (attribute) {
            case NAME: {
                name = value;
                break;
            }
            case OUTBOUND_SOCKET_BINDING_REF: {
                RemoteOutboundConnectionResourceDefinition.OUTBOUND_SOCKET_BINDING_REF.parseAndSetParameter(value, addOperation, reader);
                break;
            }
            case USERNAME: {
                RemoteOutboundConnectionResourceDefinition.USERNAME.parseAndSetParameter(value, addOperation, reader);
                break;
            }
            case SECURITY_REALM: {
                RemoteOutboundConnectionResourceDefinition.SECURITY_REALM.parseAndSetParameter(value, addOperation, reader);
                break;
            }
            case PROTOCOL: {
                RemoteOutboundConnectionResourceDefinition.PROTOCOL.parseAndSetParameter(value, addOperation, reader);
                break;
            }
            case AUTHENTICATION_CONTEXT: {
                RemoteOutboundConnectionResourceDefinition.AUTHENTICATION_CONTEXT.parseAndSetParameter(value, addOperation, reader);
                break;
            }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    final PathAddress address = PathAddress.pathAddress(PathAddress.pathAddress(parentAddress), PathElement.pathElement(CommonAttributes.REMOTE_OUTBOUND_CONNECTION, name));
    addOperation.get(OP_ADDR).set(address.toModelNode());
    // create add operation add it to the list of operations
    operations.add(addOperation);
    // parse the nested elements
    final EnumSet<Element> visited = EnumSet.noneOf(Element.class);
    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final Element element = Element.forName(reader.getLocalName());
        if (visited.contains(element)) {
            throw ParseUtils.unexpectedElement(reader);
        }
        visited.add(element);
        switch (element) {
            case PROPERTIES: {
                parseProperties(reader, address.toModelNode(), operations);
                break;
            }
            default: {
                throw unexpectedElement(reader);
            }
        }
    }

}
 
Example 19
Source File: JMXExtension.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    boolean showResolvedModel = false;
    boolean showExpressionModel = false;
    boolean connectorAdd = false;
    boolean auditLog = false;
    boolean sensitivity = false;

    ParseUtils.requireNoAttributes(reader);

    ModelNode add = createAddOperation();
    list.add(add);

    while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
        final String element = reader.getLocalName();
        switch (element) {
            case CommonAttributes.EXPOSE_RESOLVED_MODEL:
                if (showResolvedModel) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.EXPOSE_RESOLVED_MODEL);
                }
                showResolvedModel = true;
                list.add(parseShowModelElement(reader, CommonAttributes.RESOLVED));
                break;
            case CommonAttributes.EXPOSE_EXPRESSION_MODEL:
                if (showExpressionModel) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.EXPOSE_EXPRESSION_MODEL);
                }
                showExpressionModel = true;
                list.add(parseShowModelElement(reader, CommonAttributes.EXPRESSION));
                break;
            case REMOTING_CONNECTOR:
                if (connectorAdd) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.REMOTING_CONNECTOR);
                }
                connectorAdd = true;
                list.add(parseRemoteConnector(reader));
                break;
            case CommonAttributes.AUDIT_LOG:
                if (auditLog) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.AUDIT_LOG);
                }
                auditLog = true;
                parseAuditLogElement(reader, list);
                break;
            case CommonAttributes.SENSITIVITY:
                if (sensitivity) {
                    throw ParseUtils.duplicateNamedElement(reader, CommonAttributes.SENSITIVITY);
                }
                sensitivity = true;
                parseSensitivity(add, reader);
                break;
            default: {
                throw ParseUtils.unexpectedElement(reader);
            }
        }
    }
}
 
Example 20
Source File: InterfacesXml.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void parseInterfaceCriteria(final XMLExtendedStreamReader reader, final Namespace expectedNs,
        final ModelNode interfaceModel) throws XMLStreamException {
    // all subsequent elements are criteria elements
    if (reader.nextTag() == END_ELEMENT) {
        return;
    }
    requireNamespace(reader, expectedNs);
    Element element = Element.forName(reader.getLocalName());
    switch (element) {
        case ANY_IPV4_ADDRESS:
        case ANY_IPV6_ADDRESS: {
            if (expectedNs.getMajorVersion() >= 3) {
                throw ParseUtils.unexpectedElement(reader);
            } else {
                throw ParseUtils.unsupportedElement(reader, Element.ANY_ADDRESS.getLocalName());
            }
        }
        case ANY_ADDRESS: {
            interfaceModel.get(Element.ANY_ADDRESS.getLocalName()).set(true);
            requireNoContent(reader); // consume this element
            requireNoContent(reader); // consume rest of criteria (no further content allowed)
            return;
        }
    }
    do {
        requireNamespace(reader, expectedNs);
        element = Element.forName(reader.getLocalName());
        switch (element) {
            case ANY:
                parseCompoundInterfaceCriterion(reader, expectedNs, interfaceModel.get(ANY).setEmptyObject());
                break;
            case NOT:
                parseCompoundInterfaceCriterion(reader, expectedNs, interfaceModel.get(NOT).setEmptyObject());
                break;
            default: {
                // parseSimpleInterfaceCriterion(reader, criteria.add().set(element.getLocalName(), new
                // ModelNode()).get(element.getLocalName()));
                parseSimpleInterfaceCriterion(reader, interfaceModel, false);
                break;
            }
        }
    } while (reader.nextTag() != END_ELEMENT);
}