Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFLY-15452] - allow specifying AJP_ALLOWED_REQUEST_ATTRIBUTES_PATTERN #14789

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ AjpListenerService createService(final Consumer<ListenerService> serviceConsumer
}
OptionMap.Builder listenerBuilder = OptionMap.builder().addAll(listenerOptions);
AjpListenerResourceDefinition.MAX_AJP_PACKET_SIZE.resolveOption(context, model,listenerBuilder);
AjpListenerResourceDefinition.ALLOWED_REQUEST_ATTRIBUTES_PATTERN.resolveOption(context, model,listenerBuilder);
return new AjpListenerService(serviceConsumer, context.getCurrentAddress(), scheme, listenerBuilder.getMap(), socketOptions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.wildfly.extension.undertow;


import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -21,6 +22,7 @@
import org.jboss.as.controller.client.helpers.MeasurementUnit;
import org.jboss.as.controller.operations.validation.IntRangeValidator;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.version.Stability;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.extension.io.OptionAttributeDefinition;
Expand All @@ -45,7 +47,15 @@ public class AjpListenerResourceDefinition extends ListenerResourceDefinition {
.setValidator(new IntRangeValidator(1))
.build();

static final List<AttributeDefinition> ATTRIBUTES = List.of(SCHEME, REDIRECT_SOCKET, MAX_AJP_PACKET_SIZE);
protected static final OptionAttributeDefinition ALLOWED_REQUEST_ATTRIBUTES_PATTERN = OptionAttributeDefinition
.builder(Constants.ALLOWED_REQUEST_ATTRIBUTES_PATTERN, UndertowOptions.AJP_ALLOWED_REQUEST_ATTRIBUTES_PATTERN)
.setRequired(false)
.setAllowExpression(true)
.setDefaultValue(null)
.setStability(Stability.PREVIEW)
.build();

static final List<AttributeDefinition> ATTRIBUTES = List.of(SCHEME, REDIRECT_SOCKET, MAX_AJP_PACKET_SIZE, ALLOWED_REQUEST_ATTRIBUTES_PATTERN);

AjpListenerResourceDefinition() {
super(new SimpleResourceDefinition.Parameters(PATH_ELEMENT, UndertowExtension.getResolver(Constants.LISTENER)), new AjpListenerAdd(), Map.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public interface Constants {
String CERTIFICATE_FORWARDING = "certificate-forwarding";
String OPTIONS = "options";
String IGNORE_FLUSH = "ignore-flush";
String ALLOWED_REQUEST_ATTRIBUTES_PATTERN = "allowed-request-attributes-pattern";

String WEBSOCKETS = "websockets";
//mod_cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
package org.wildfly.extension.undertow;

import java.util.EnumSet;
import java.util.List;

import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ExtensionContext;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentResourceXMLDescriptionReader;
import org.jboss.as.controller.PersistentResourceXMLDescriptionWriter;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.parsing.ExtensionParsingContext;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;


/**
Expand All @@ -38,14 +33,9 @@ public static StandardResourceDescriptionResolver getResolver(final String... ke
return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, UndertowExtension.class.getClassLoader(), true, false);
}

private final PersistentResourceXMLDescription currentDescription = UndertowSubsystemSchema.CURRENT.getXMLDescription();

@Override
public void initializeParsers(ExtensionParsingContext context) {
for (UndertowSubsystemSchema schema : EnumSet.allOf(UndertowSubsystemSchema.class)) {
XMLElementReader<List<ModelNode>> reader = (schema == UndertowSubsystemSchema.CURRENT) ? new PersistentResourceXMLDescriptionReader(this.currentDescription) : schema;
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, schema.getNamespace().getUri(), reader);
}
context.setSubsystemXmlMappings(SUBSYSTEM_NAME, EnumSet.allOf(UndertowSubsystemSchema.class));
}

@Override
Expand All @@ -58,6 +48,6 @@ public void initialize(ExtensionContext context) {
deployments.registerSubModel(new DeploymentServletDefinition());
deployments.registerSubModel(new DeploymentWebSocketDefinition());

subsystem.registerXMLElementWriter(new PersistentResourceXMLDescriptionWriter(this.currentDescription));
subsystem.registerXMLElementWriter(new PersistentResourceXMLDescriptionWriter(UndertowSubsystemSchema.CURRENT.get(context.getStability())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.jboss.as.controller.transform.ExtensionTransformerRegistration;
import org.jboss.as.controller.transform.SubsystemTransformerRegistration;
import org.jboss.as.controller.transform.description.AttributeConverter;
import org.jboss.as.controller.transform.description.AttributeTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
Expand All @@ -39,7 +40,7 @@ public void registerTransformers(SubsystemTransformerRegistration registration)
ResourceTransformationDescriptionBuilder subsystem = TransformationDescriptionBuilder.Factory.createSubsystemInstance();

ResourceTransformationDescriptionBuilder server = subsystem.addChildResource(ServerDefinition.PATH_ELEMENT);
for (PathElement listenerPath : Set.of(HttpListenerResourceDefinition.PATH_ELEMENT, HttpsListenerResourceDefinition.PATH_ELEMENT, AjpListenerResourceDefinition.PATH_ELEMENT)) {
for (PathElement listenerPath : Set.of(HttpListenerResourceDefinition.PATH_ELEMENT, HttpsListenerResourceDefinition.PATH_ELEMENT)) {
if (UndertowSubsystemModel.VERSION_13_0_0.requiresTransformation(version)) {
server.addChildResource(listenerPath).getAttributeBuilder()
.setValueConverter(AttributeConverter.DEFAULT_VALUE, ListenerResourceDefinition.WRITE_TIMEOUT, ListenerResourceDefinition.READ_TIMEOUT)
Expand All @@ -57,6 +58,20 @@ public void registerTransformers(SubsystemTransformerRegistration registration)
servletContainer.rejectChildResource(AffinityCookieDefinition.PATH_ELEMENT);
}

final ResourceTransformationDescriptionBuilder ajpListener = server.addChildResource(AjpListenerResourceDefinition.PATH_ELEMENT);
if (UndertowSubsystemModel.VERSION_14_0_0.requiresTransformation(version)) {
final AttributeTransformationDescriptionBuilder ajpListenerAttributeTransformationDescriptionBuilder = ajpListener.getAttributeBuilder();
ajpListenerAttributeTransformationDescriptionBuilder.setDiscard(DiscardAttributeChecker.UNDEFINED, AjpListenerResourceDefinition.ALLOWED_REQUEST_ATTRIBUTES_PATTERN)
.addRejectCheck(RejectAttributeChecker.DEFINED, AjpListenerResourceDefinition.ALLOWED_REQUEST_ATTRIBUTES_PATTERN)
.end();

if (UndertowSubsystemModel.VERSION_13_0_0.requiresTransformation(version)) {
ajpListenerAttributeTransformationDescriptionBuilder
.setValueConverter(AttributeConverter.DEFAULT_VALUE, ListenerResourceDefinition.WRITE_TIMEOUT, ListenerResourceDefinition.READ_TIMEOUT)
.end();
}
}

TransformationDescription.Tools.register(subsystem.build(), registration, version);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public enum UndertowSubsystemModel implements SubsystemModel {

VERSION_11_0_0(11), // WildFly 23-26.x, EAP 7.4.x
VERSION_12_0_0(12), // WildFly 27
VERSION_13_0_0(13), // WildFly 28-present
VERSION_13_0_0(13), // WildFly 28
VERSION_14_0_0(14), // WildFly 31-present
;
static final UndertowSubsystemModel CURRENT = VERSION_13_0_0;
static final UndertowSubsystemModel CURRENT = VERSION_14_0_0;

private final ModelVersion version;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

package org.wildfly.extension.undertow;

import java.util.EnumSet;
import java.util.Map;

import org.jboss.as.controller.Feature;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentSubsystemSchema;
import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.as.version.Stability;
import org.jboss.staxmapper.IntVersion;

/**
Expand All @@ -34,10 +39,11 @@ public enum UndertowSubsystemSchema implements PersistentSubsystemSchema<Underto
VERSION_11_0(11), // WildFly 20-22 N.B. There were no parser changes between 10.0 and 11.0 !!
VERSION_12_0(12), // WildFly 23-26.1, EAP 7.4
VERSION_13_0(13), // WildFly 27 N.B. There were no schema changes between 12.0 and 13.0!
VERSION_14_0(14), // WildFly 28-present
VERSION_14_0(14), // WildFly 28
VERSION_14_0_PREVIEW(14, 0, Stability.PREVIEW) // WildFly 32-present
;
static final UndertowSubsystemSchema CURRENT = VERSION_14_0;

static final Map<Stability, UndertowSubsystemSchema> CURRENT = Feature.map(EnumSet.of(VERSION_14_0, VERSION_14_0_PREVIEW));
private final VersionedNamespace<IntVersion, UndertowSubsystemSchema> namespace;

UndertowSubsystemSchema(int major) {
Expand All @@ -49,7 +55,15 @@ public enum UndertowSubsystemSchema implements PersistentSubsystemSchema<Underto
}

UndertowSubsystemSchema(IntVersion version) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(UndertowExtension.SUBSYSTEM_NAME, version);
this(version, Stability.DEFAULT);
}

UndertowSubsystemSchema(final int major, final int minor, final Stability stability) {
this(new IntVersion(major, minor), stability);
}

UndertowSubsystemSchema(final IntVersion version, final Stability stability) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(UndertowExtension.SUBSYSTEM_NAME, stability, version);
}

@Override
Expand All @@ -61,4 +75,4 @@ public VersionedNamespace<IntVersion, UndertowSubsystemSchema> getNamespace() {
public PersistentResourceXMLDescription getXMLDescription() {
return UndertowPersistentResourceXMLDescriptionFactory.INSTANCE.apply(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ undertow.listener.http2-max-header-list-size=The maximum size of request headers
undertow.listener.http2-initial-window-size=The flow control window size that controls how quickly the client can send data to the server
undertow.listener.http2-header-table-size=The size of the header table used for HPACK compression, in bytes. This amount of memory will be allocated per connection for compression. Larger values use more memory but may give better compression.
undertow.listener.require-host-http11=Require that all HTTP/1.1 requests have a 'Host' header, as per the RFC. IF the request does not include this header it will be rejected with a 403.
undertow.listener.allowed-request-attributes-pattern=Pattern(regex) which specifies allowed custom AJP request attributes.
undertow.host=An Undertow host
undertow.host.add=Adds a new host
undertow.host.remove=Removes a host
Expand Down