org.jboss.as.controller.SimpleAttributeDefinition Java Examples

The following examples show how to use org.jboss.as.controller.SimpleAttributeDefinition. 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: BpmPlatformParser.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void writeJobAcquisitionsContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context, ModelNode parentNode) throws XMLStreamException {
  writer.writeStartElement(Element.JOB_AQUISITIONS.getLocalName());

  ModelNode jobAcquisitionConfigurations = parentNode.get(Element.JOB_AQUISITIONS.getLocalName());
  if (jobAcquisitionConfigurations.isDefined()) {
    for (Property property : jobAcquisitionConfigurations.asPropertyList()) {
      // write each child element to xml
      writer.writeStartElement(Element.JOB_AQUISITION.getLocalName());

      for (AttributeDefinition jobAcquisitionAttribute : SubsystemAttributeDefinitons.JOB_ACQUISITION_ATTRIBUTES) {
        if (jobAcquisitionAttribute.equals(SubsystemAttributeDefinitons.NAME)) {
          ((SimpleAttributeDefinition) jobAcquisitionAttribute).marshallAsAttribute(property.getValue(), writer);
        } else {
          jobAcquisitionAttribute.marshallAsElement(property.getValue(), writer);
        }
      }

      writer.writeEndElement();
    }
  }
  // end job-acquisitions
  writer.writeEndElement();
}
 
Example #2
Source File: LdapCacheResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static ResourceDefinition create(final PathElement pathElement, final CacheFor cacheFor) {
    SimpleAttributeDefinition[] configurationAttributes = new SimpleAttributeDefinition[] { EVICTION_TIME, CACHE_FAILURES, MAX_CACHE_SIZE };
    SimpleAttributeDefinition[] runtimeAttributes = new SimpleAttributeDefinition[] { CACHE_SIZE };
    final SimpleOperationDefinition[] runtimeOperations;
    final OperationStepHandler runtimeHandler;
    switch (cacheFor) {
        case AuthUser:
            runtimeOperations = new SimpleOperationDefinition[] { FLUSH_CACHE_NAME_ONLY, CONTAINS_NAME_ONLY };
            runtimeHandler = NAME_ONLY_HANDLER;
            break;
        default:
            runtimeOperations = new SimpleOperationDefinition[] { FLUSH_CACHE_FULL, CONTAINS_FULL };
            runtimeHandler = FULL_HANDLER;
    }

    return new LdapCacheResourceDefinition(pathElement, configurationAttributes, runtimeAttributes, runtimeOperations,
            runtimeHandler);
}
 
Example #3
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
void writeSps(final XMLExtendedStreamWriter writer, final ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    for (Property sp : model.get(Constants.Model.SERVICE_PROVIDER).asPropertyList()) {
        writer.writeStartElement(Constants.XML.SERVICE_PROVIDER);
        writer.writeAttribute(Constants.XML.ENTITY_ID, sp.getName());
        ModelNode spAttributes = sp.getValue();
        for (SimpleAttributeDefinition attr : ServiceProviderDefinition.ATTRIBUTES) {
            attr.getAttributeMarshaller().marshallAsAttribute(attr, spAttributes, false, writer);
        }
        writeKeys(writer, spAttributes.get(Constants.Model.KEY));
        writePrincipalNameMapping(writer, spAttributes);
        writeRoleIdentifiers(writer, spAttributes);
        writeRoleMappingsProvider(writer, spAttributes);
        writeIdentityProvider(writer, spAttributes.get(Constants.Model.IDENTITY_PROVIDER));

        writer.writeEndElement();
    }
}
 
Example #4
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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, Constants.XML.CERTIFICATE_ALIAS);
    }

    ParseUtils.requireNoContent(reader);
}
 
Example #5
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: JmxFacadeRbacEnabledTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
void addOperation(String name, boolean readOnly, boolean runtimeOnly, SimpleAttributeDefinition[] parameters, AccessConstraintDefinition...constraints) {
    SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(name, new NonResolvingResourceDescriptionResolver());
    if (constraints != null) {
        builder.setAccessConstraints(constraints);
    }
    if (readOnly) {
        builder.setReadOnly();
    }
    if (runtimeOnly) {
        builder.setRuntimeOnly();
    }
    if (parameters != null) {
        for (SimpleAttributeDefinition param : parameters) {
            builder.addParameter(param);
        }
    }
    operations.add(builder.build());
}
 
Example #8
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #9
Source File: BpmPlatformParser1_1.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void writeJobExecutorContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
  ModelNode node = context.getModelNode();
  ModelNode jobExecutorNode = node.get(Element.JOB_EXECUTOR.getLocalName());

  if (jobExecutorNode.isDefined()) {

    writer.writeStartElement(Element.JOB_EXECUTOR.getLocalName());

    for (Property property : jobExecutorNode.asPropertyList()) {
      ModelNode propertyValue = property.getValue();

      for (AttributeDefinition jobExecutorAttribute : SubsystemAttributeDefinitons.JOB_EXECUTOR_ATTRIBUTES) {
        if (jobExecutorAttribute.equals(SubsystemAttributeDefinitons.NAME)) {
          ((SimpleAttributeDefinition) jobExecutorAttribute).marshallAsAttribute(propertyValue, writer);
        } else {
          jobExecutorAttribute.marshallAsElement(propertyValue, writer);
        }
      }

      writeJobAcquisitionsContent(writer, context, propertyValue);
    }

    // end job-executor
    writer.writeEndElement();
  }
}
 
Example #10
Source File: ModelControllerResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void init() {
    complexValueType = new ModelNode();
    complexValueType.get("int-value", DESCRIPTION).set("An int value");
    complexValueType.get("int-value", EXPRESSIONS_ALLOWED).set(allowExpressions);
    complexValueType.get("int-value", TYPE).set(ModelType.INT);
    complexValueType.get("bigdecimal-value", DESCRIPTION).set("A bigdecimal value");
    complexValueType.get("bigdecimal-value", TYPE).set(ModelType.BIG_DECIMAL);
    complexValueType.get("bigdecimal-value", EXPRESSIONS_ALLOWED).set(allowExpressions);

    SimpleAttributeDefinition intValue = createAttribute("int-value", ModelType.INT, allowExpressions);
    SimpleAttributeDefinition bigDecimal = createAttribute("bigdecimal-value", ModelType.BIG_DECIMAL, allowExpressions);

    complex = new ObjectTypeAttributeDefinition.Builder("complex", intValue, bigDecimal).build();
    AttributeDefinition param1 = new ObjectTypeAttributeDefinition.Builder("param1", intValue, bigDecimal).build();
    COMPLEX_OP_DEF = new SimpleOperationDefinitionBuilder("complex", new NonResolvingResourceDescriptionResolver())
            .addParameter(param1)
            .setReplyType(ModelType.OBJECT)
            .setReplyParameters(complex)
            .build();

}
 
Example #11
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readSingleLogout(ModelNode addIdentityProvider, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode slo = addIdentityProvider.get(Constants.Model.SINGLE_LOGOUT);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = SingleLogoutDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, slo, reader);
    }
    ParseUtils.requireNoContent(reader);
}
 
Example #12
Source File: ExposeModelResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
static SimpleAttributeDefinition getDomainNameAttribute(String childName) {
    if (CommonAttributes.RESOLVED.equals(childName)){
        return ExposeModelResourceResolved.DOMAIN_NAME;
    } else if (CommonAttributes.EXPRESSION.equals(childName)) {
        return ExposeModelResourceExpression.DOMAIN_NAME;
    }

    throw JmxLogger.ROOT_LOGGER.unknownChild(childName);
}
 
Example #13
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #14
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void writeSingleSignOn(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    writer.writeStartElement(Constants.XML.SINGLE_SIGN_ON);
    for (SimpleAttributeDefinition attr : SingleSignOnDefinition.ATTRIBUTES) {
        attr.getAttributeMarshaller().marshallAsAttribute(attr, model, false, writer);
    }
    writer.writeEndElement();
}
 
Example #15
Source File: PathResourceDefinition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    resourceRegistration.registerReadOnlyAttribute(NAME, ReadResourceNameOperationStepHandler.INSTANCE);
    resourceRegistration.registerReadWriteAttribute(RELATIVE_TO_LOCAL, null, new PathWriteAttributeHandler(pathManager, RELATIVE_TO_LOCAL));
    SimpleAttributeDefinition pathAttr = specified ? PATH_SPECIFIED : PATH_NAMED;
    resourceRegistration.registerReadWriteAttribute(pathAttr, null, new PathWriteAttributeHandler(pathManager, pathAttr));
    resourceRegistration.registerReadOnlyAttribute(READ_ONLY, null);
}
 
Example #16
Source File: ExposeModelResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
    domainName.validateAndSet(operation, model);
    if (otherAttributes.length > 0) {
        for (SimpleAttributeDefinition attr : otherAttributes) {
            attr.validateAndSet(operation, model);
        }
    }
}
 
Example #17
Source File: ExposeModelResource.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
ExposeModelResource(PathElement pathElement, ManagedAuditLogger auditLoggerInfo, JmxAuthorizer authorizer, Supplier<SecurityIdentity> securityIdentitySupplier,
        RuntimeHostControllerInfoAccessor hostInfoAccessor, SimpleAttributeDefinition domainName, SimpleAttributeDefinition...otherAttributes) {
    super(pathElement,
            JMXExtension.getResourceDescriptionResolver(CommonAttributes.EXPOSE_MODEL + "." + pathElement.getValue()),
            new ShowModelAdd(auditLoggerInfo, authorizer, securityIdentitySupplier, domainName, hostInfoAccessor, otherAttributes),
            new ShowModelRemove(auditLoggerInfo, authorizer, securityIdentitySupplier, hostInfoAccessor));
    this.auditLoggerInfo = auditLoggerInfo;
    this.authorizer = authorizer;
    this.securityIdentitySupplier = securityIdentitySupplier;
    this.domainName = domainName;
    this.hostInfoAccessor = hostInfoAccessor;
}
 
Example #18
Source File: BpmPlatformParser.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void writeProcessEnginesContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {
  
  writer.writeStartElement(Element.PROCESS_ENGINES.getLocalName());

  ModelNode node = context.getModelNode();
  
  ModelNode processEngineConfigurations = node.get(Element.PROCESS_ENGINES.getLocalName());
  if (processEngineConfigurations.isDefined()) {
    for (Property property : processEngineConfigurations.asPropertyList()) {
      // write each child element to xml
      writer.writeStartElement(Element.PROCESS_ENGINE.getLocalName());
      
      ModelNode propertyValue = property.getValue();
      for (AttributeDefinition processEngineAttribute : SubsystemAttributeDefinitons.PROCESS_ENGINE_ATTRIBUTES) {
        if (processEngineAttribute.equals(SubsystemAttributeDefinitons.NAME) || processEngineAttribute.equals(SubsystemAttributeDefinitons.DEFAULT)) {
          ((SimpleAttributeDefinition) processEngineAttribute).marshallAsAttribute(propertyValue, writer);
        } else {
          processEngineAttribute.marshallAsElement(propertyValue, writer);
        }
      }


      writer.writeEndElement();
    }
  }
  // end process-engines
  writer.writeEndElement();
}
 
Example #19
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void writeSingleSignOn(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
    if (!model.isDefined()) {
        return;
    }
    writer.writeStartElement(Constants.XML.SINGLE_SIGN_ON);
    for (SimpleAttributeDefinition attr : SingleSignOnDefinition.ATTRIBUTES) {
        attr.getAttributeMarshaller().marshallAsAttribute(attr, model, false, writer);
    }
    writer.writeEndElement();
}
 
Example #20
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void writeHttpClient(XMLExtendedStreamWriter writer, ModelNode httpClientModel) throws XMLStreamException {
    if (!httpClientModel.isDefined()) {
        return;
    }
    writer.writeStartElement(Constants.XML.HTTP_CLIENT);
    for (SimpleAttributeDefinition attr : HttpClientDefinition.ATTRIBUTES) {
        attr.marshallAsAttribute(httpClientModel, false, writer);
    }
    writer.writeEndElement();
}
 
Example #21
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #22
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void readDeployment(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(SecureDeploymentDefinition.TAG_NAME, name));
    addSecureDeployment.get(ModelDescriptionConstants.OP_ADDR).set(addr.toModelNode());
    List<ModelNode> credentialsToAdd = new ArrayList<>();
    while (reader.hasNext() && nextTag(reader) != END_ELEMENT) {
        String tagName = reader.getLocalName();
        if (tagName.equals(CredentialDefinition.TAG_NAME)) {
            readCredential(reader, addr, credentialsToAdd);
            continue;
        }

        SimpleAttributeDefinition def = SecureDeploymentDefinition.lookup(tagName);
        if (def == null) throw new XMLStreamException("Unknown secure-deployment tag " + tagName);
        def.parseAndSetParameter(reader.getElementText(), addSecureDeployment, reader);
    }


    /**
     * TODO need to check realm-ref first.
    if (!SharedAttributeDefinitons.validateTruststoreSetIfRequired(addSecureDeployment)) {
        //TODO: externalize the message
        throw new XMLStreamException("truststore and truststore-password must be set if ssl-required is not none and disable-trust-manager is false.");
    }
     */

    // Must add credentials after the deployment is added.
    resourcesToAdd.add(addSecureDeployment);
    resourcesToAdd.addAll(credentialsToAdd);
}
 
Example #23
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 #24
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readSingleLogout(ModelNode addIdentityProvider, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode slo = addIdentityProvider.get(Constants.Model.SINGLE_LOGOUT);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = SingleLogoutDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, slo, reader);
    }
    ParseUtils.requireNoContent(reader);
}
 
Example #25
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readSingleSignOn(ModelNode addIdentityProvider, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode sso = addIdentityProvider.get(Constants.Model.SINGLE_SIGN_ON);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = SingleSignOnDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, sso, reader);
    }
    ParseUtils.requireNoContent(reader);
}
 
Example #26
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #27
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 #28
Source File: KeycloakSubsystemParser.java    From keycloak with Apache License 2.0 5 votes vote down vote up
void readSingleSignOn(ModelNode addIdentityProvider, XMLExtendedStreamReader reader) throws XMLStreamException {
    ModelNode sso = addIdentityProvider.get(Constants.Model.SINGLE_SIGN_ON);
    for (int i = 0; i < reader.getAttributeCount(); i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);

        SimpleAttributeDefinition attr = SingleSignOnDefinition.lookup(name);
        if (attr == null) {
            throw ParseUtils.unexpectedAttribute(reader, i);
        }
        attr.parseAndSetParameter(value, sso, reader);
    }
    ParseUtils.requireNoContent(reader);
}
 
Example #29
Source File: AbstractAdapterConfigurationDefinition.java    From keycloak with Apache License 2.0 5 votes vote down vote up
protected AbstractAdapterConfigurationDefinition(String name, List<SimpleAttributeDefinition> attributes, AbstractAdapterConfigurationAddHandler addHandler, AbstractAdapterConfigurationRemoveHandler removeHandler, AbstractAdapterConfigurationWriteAttributeHandler attrWriteHandler) {
    super(PathElement.pathElement(name),
            KeycloakExtension.getResourceDescriptionResolver(name),
            addHandler,
            removeHandler);
    this.attributes = attributes;
    this.attrWriteHandler = attrWriteHandler;
}
 
Example #30
Source File: BpmPlatformParser1_1.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void writeProcessEnginesContent(final XMLExtendedStreamWriter writer, final SubsystemMarshallingContext context) throws XMLStreamException {

      writer.writeStartElement(Element.PROCESS_ENGINES.getLocalName());

      ModelNode node = context.getModelNode();

      ModelNode processEngineConfigurations = node.get(Element.PROCESS_ENGINES.getLocalName());
      if (processEngineConfigurations.isDefined()) {
        for (Property property : processEngineConfigurations.asPropertyList()) {
          // write each child element to xml
          writer.writeStartElement(Element.PROCESS_ENGINE.getLocalName());

          ModelNode propertyValue = property.getValue();
          for (AttributeDefinition processEngineAttribute : SubsystemAttributeDefinitons.PROCESS_ENGINE_ATTRIBUTES) {
            if (processEngineAttribute.equals(SubsystemAttributeDefinitons.NAME) || processEngineAttribute.equals(SubsystemAttributeDefinitons.DEFAULT)) {
              ((SimpleAttributeDefinition) processEngineAttribute).marshallAsAttribute(propertyValue, writer);
            } else {
              processEngineAttribute.marshallAsElement(propertyValue, writer);
            }
          }

          writer.writeEndElement();
        }
      }
      // end process-engines
      writer.writeEndElement();
    }