Search in sources :

Example 71 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project keycloak by keycloak.

the class KeycloakSubsystemParser method writeSingleLogout.

void writeSingleLogout(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    writer.writeStartElement(Constants.XML.SINGLE_LOGOUT);
    for (SimpleAttributeDefinition attr : SingleLogoutDefinition.ATTRIBUTES) {
        attr.getAttributeMarshaller().marshallAsAttribute(attr, model, false, writer);
    }
    writer.writeEndElement();
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition)

Example 72 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project keycloak by keycloak.

the class KeycloakSubsystemParser method readKeyStore.

void readKeyStore(ModelNode addKey, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode addKeyStore = addKey.get(Constants.Model.KEY_STORE);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);
        SimpleAttributeDefinition attr = KeyStoreDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKeyStore, reader);
    }
    if (!addKeyStore.hasDefined(Constants.Model.FILE) && !addKeyStore.hasDefined(Constants.Model.RESOURCE)) {
        throw new XMLStreamException("KeyStore element must have 'file' or 'resource' attribute set", reader.getLocation());
    }
    if (!addKeyStore.hasDefined(Constants.Model.PASSWORD)) {
        throw ParseUtils.missingRequired(reader, Constants.XML.PASSWORD);
    }
    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 keystore type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }
        if (Constants.XML.PRIVATE_KEY.equals(tagName)) {
            readPrivateKey(reader, addKeyStore);
        } else if (Constants.XML.CERTIFICATE.equals(tagName)) {
            readCertificate(reader, addKeyStore);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 73 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project keycloak by keycloak.

the class KeycloakSubsystemParser method writeKeyStore.

void writeKeyStore(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    writer.writeStartElement(Constants.XML.KEY_STORE);
    for (SimpleAttributeDefinition attr : KeyStoreDefinition.ATTRIBUTES) {
        attr.getAttributeMarshaller().marshallAsAttribute(attr, model, false, writer);
    }
    writePrivateKey(writer, model);
    writeCertificate(writer, model);
    writer.writeEndElement();
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition)

Example 74 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project keycloak by keycloak.

the class KeycloakSubsystemParser method readIdentityProvider.

void readIdentityProvider(List<ModelNode> list, XMLExtendedStreamReader reader, PathAddress parentAddr) throws XMLStreamException {
    String entityId = readRequiredAttribute(reader, Constants.XML.ENTITY_ID);
    PathAddress addr = PathAddress.pathAddress(parentAddr, PathElement.pathElement(Constants.Model.IDENTITY_PROVIDER, entityId));
    ModelNode addIdentityProvider = Util.createAddOperation(addr);
    list.add(addIdentityProvider);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);
        if (Constants.XML.ENTITY_ID.equals(name) || // don't break if encountering this noop attr from client-adapter/core keycloak_saml_adapter_1_6.xsd
        "encryption".equals(name)) {
            continue;
        }
        SimpleAttributeDefinition attr = IdentityProviderDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addIdentityProvider, 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 identity provider type should occur only once.
            throw ParseUtils.unexpectedElement(reader);
        }
        if (Constants.XML.SINGLE_SIGN_ON.equals(tagName)) {
            readSingleSignOn(addIdentityProvider, reader);
        } else if (Constants.XML.SINGLE_LOGOUT.equals(tagName)) {
            readSingleLogout(addIdentityProvider, reader);
        } else if (Constants.XML.KEYS.equals(tagName)) {
            readKeys(list, reader, addr);
        } else if (Constants.XML.HTTP_CLIENT.equals(tagName)) {
            readHttpClient(addIdentityProvider, reader);
        } else if (Constants.XML.ALLOWED_CLOCK_SKEW.equals(tagName)) {
            readAllowedClockSkew(addIdentityProvider, reader);
        } else {
            throw ParseUtils.unexpectedElement(reader);
        }
        parsedElements.add(tagName);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 75 with SimpleAttributeDefinition

use of org.jboss.as.controller.SimpleAttributeDefinition in project keycloak by keycloak.

the class KeycloakSubsystemParser method readPrivateKey.

void readPrivateKey(XMLExtendedStreamReader reader, ModelNode addKeyStore) throws XMLStreamException {
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);
        SimpleAttributeDefinition attr = KeyStorePrivateKeyDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKeyStore, reader);
    }
    if (!addKeyStore.hasDefined(Constants.Model.PRIVATE_KEY_ALIAS)) {
        throw ParseUtils.missingRequired(reader, Constants.XML.PRIVATE_KEY_ALIAS);
    }
    if (!addKeyStore.hasDefined(Constants.Model.PRIVATE_KEY_PASSWORD)) {
        throw ParseUtils.missingRequired(reader, Constants.XML.PRIVATE_KEY_PASSWORD);
    }
    ParseUtils.requireNoContent(reader);
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition)

Aggregations

SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)89 ModelNode (org.jboss.dmr.ModelNode)47 PathAddress (org.jboss.as.controller.PathAddress)14 Property (org.jboss.dmr.Property)13 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)12 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)9 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)9 HashSet (java.util.HashSet)8 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)8 XMLStreamException (javax.xml.stream.XMLStreamException)7 OperationContext (org.jboss.as.controller.OperationContext)4 ArrayList (java.util.ArrayList)3 AbstractAttributeDefinitionBuilder (org.jboss.as.controller.AbstractAttributeDefinitionBuilder)3 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)3 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)3 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)3 SimpleMapAttributeDefinition (org.jboss.as.controller.SimpleMapAttributeDefinition)3 ParseUtils.unexpectedElement (org.jboss.as.controller.parsing.ParseUtils.unexpectedElement)3 ClearWorkManagerStatisticsHandler (org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)2 WorkManagerRuntimeAttributeReadHandler (org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler)2