Search in sources :

Example 81 with SimpleAttributeDefinition

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

the class KeycloakSubsystemParser method writeIdentityProvider.

void writeIdentityProvider(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    for (Property idp : model.asPropertyList()) {
        writer.writeStartElement(Constants.XML.IDENTITY_PROVIDER);
        writer.writeAttribute(Constants.XML.ENTITY_ID, idp.getName());
        ModelNode idpAttributes = idp.getValue();
        for (SimpleAttributeDefinition attr : IdentityProviderDefinition.ATTRIBUTES) {
            attr.getAttributeMarshaller().marshallAsAttribute(attr, idpAttributes, false, writer);
        }
        writeSingleSignOn(writer, idpAttributes.get(Constants.Model.SINGLE_SIGN_ON));
        writeSingleLogout(writer, idpAttributes.get(Constants.Model.SINGLE_LOGOUT));
        writeKeys(writer, idpAttributes.get(Constants.Model.KEY));
        writeHttpClient(writer, idpAttributes.get(Constants.Model.HTTP_CLIENT));
        writeAllowedClockSkew(writer, idpAttributes.get(Constants.Model.ALLOWED_CLOCK_SKEW));
        writer.writeEndElement();
    }
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 82 with SimpleAttributeDefinition

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

the class KeycloakSubsystemParser method readSecureResource.

private void readSecureResource(String tagName, AbstractAdapterConfigurationDefinition resource, XMLExtendedStreamReader reader, List<ModelNode> resourcesToAdd) throws XMLStreamException {
    String name = readNameAttribute(reader);
    ModelNode addSecureDeployment = new ModelNode();
    addSecureDeployment.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
    PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, KeycloakExtension.SUBSYSTEM_NAME), PathElement.pathElement(tagName, name));
    addSecureDeployment.get(ModelDescriptionConstants.OP_ADDR).set(addr.toModelNode());
    List<ModelNode> credentialsToAdd = new ArrayList<ModelNode>();
    List<ModelNode> redirectRulesToAdd = new ArrayList<ModelNode>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String localName = reader.getLocalName();
        if (localName.equals(CredentialDefinition.TAG_NAME)) {
            readCredential(reader, addr, credentialsToAdd);
            continue;
        }
        if (localName.equals(RedirecRewritetRuleDefinition.TAG_NAME)) {
            readRewriteRule(reader, addr, redirectRulesToAdd);
            continue;
        }
        SimpleAttributeDefinition def = resource.lookup(localName);
        if (def == null)
            throw new XMLStreamException("Unknown secure-deployment tag " + localName);
        def.parseAndSetParameter(reader.getElementText(), addSecureDeployment, reader);
    }
    // Must add credentials after the deployment is added.
    resourcesToAdd.add(addSecureDeployment);
    resourcesToAdd.addAll(credentialsToAdd);
    resourcesToAdd.addAll(redirectRulesToAdd);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 83 with SimpleAttributeDefinition

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

the class KeycloakSubsystemParser method readRealm.

private void readRealm(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
    String realmName = readNameAttribute(reader);
    ModelNode addRealm = new ModelNode();
    addRealm.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
    PathAddress addr = PathAddress.pathAddress(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, KeycloakExtension.SUBSYSTEM_NAME), PathElement.pathElement(RealmDefinition.TAG_NAME, realmName));
    addRealm.get(ModelDescriptionConstants.OP_ADDR).set(addr.toModelNode());
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        SimpleAttributeDefinition def = RealmDefinition.lookup(tagName);
        if (def == null)
            throw new XMLStreamException("Unknown realm tag " + tagName);
        def.parseAndSetParameter(reader.getElementText(), addRealm, reader);
    }
    list.add(addRealm);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) PathAddress(org.jboss.as.controller.PathAddress) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 84 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, asSet(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 85 with SimpleAttributeDefinition

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

the class KeycloakSubsystemParser method readCertificate.

void readCertificate(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 = KeyStoreCertificateDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, addKeyStore, reader);
    }
    if (!addKeyStore.hasDefined(Constants.Model.CERTIFICATE_ALIAS)) {
        throw ParseUtils.missingRequired(reader, asSet(Constants.XML.CERTIFICATE_ALIAS));
    }
    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