Skip to content

Commit

Permalink
[WFLY-14210] Bump the jaxrs subsystems model version. Reject attribut…
Browse files Browse the repository at this point in the history
…es against the 1.0.0 and 2.0.0 model versions. Model version 2.0.0 was incorrectly used in WildFly 19, 20 and 21. An added system property was added to allow the transformers to be bypassed.

https://issues.redhat.com/browse/WFLY-14210
  • Loading branch information
jamezp committed Dec 14, 2020
1 parent c902cf1 commit 6875cc3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import javax.servlet.Servlet;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.ObjectTypeAttributeDefinition;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
Expand Down Expand Up @@ -90,7 +91,7 @@ private static class ShowJaxrsResourcesHandler implements OperationStepHandler {
.setReadOnly()
.setRuntimeOnly()
.setReplyType(ModelType.LIST)
.setDeprecated(JaxrsExtension.MODEL_VERSION_2_0_0)
.setDeprecated(ModelVersion.create(2, 0, 0))
.setReplyParameters(JAXRS_RESOURCE).build();


Expand Down
7 changes: 1 addition & 6 deletions jaxrs/src/main/java/org/jboss/as/jaxrs/JaxrsExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,8 @@
public class JaxrsExtension implements Extension {

public static final String SUBSYSTEM_NAME = "jaxrs";
public static final String NAMESPACE_1_0 = "urn:jboss:domain:jaxrs:1.0";
public static final String NAMESPACE_2_0 = "urn:jboss:domain:jaxrs:2.0";

public static final ModelVersion MODEL_VERSION_1_0_0 = ModelVersion.create(1, 0, 0);
public static final ModelVersion MODEL_VERSION_2_0_0 = ModelVersion.create(2, 0, 0);

private static final ModelVersion CURRENT_MODEL_VERSION = MODEL_VERSION_2_0_0;
private static final ModelVersion CURRENT_MODEL_VERSION = ModelVersion.create(3, 0, 0);

private static final String RESOURCE_NAME = JaxrsExtension.class.getPackage().getName() + ".LocalDescriptions";
static PathElement SUBSYSTEM_PATH = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, SUBSYSTEM_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,25 @@
import static org.jboss.as.controller.parsing.ParseUtils.requireNoContent;

import java.util.List;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;

import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLElementWriter;
import org.jboss.staxmapper.XMLExtendedStreamReader;
import org.jboss.staxmapper.XMLExtendedStreamWriter;

public class JaxrsSubsystemParser_1_0 implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {

/**
* {@inheritDoc}
*/
@Override
public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException {
// Require no attributes or content
requireNoAttributes(reader);
requireNoContent(reader);
list.add(Util.createAddOperation(PathAddress.pathAddress(JaxrsExtension.SUBSYSTEM_PATH)));
}
public class JaxrsSubsystemParser_1_0 implements XMLStreamConstants, XMLElementReader<List<ModelNode>> {

/**
* {@inheritDoc}
*/
@Override
public void writeContent(final XMLExtendedStreamWriter streamWriter, final SubsystemMarshallingContext context) throws XMLStreamException {
context.startSubsystemElement(JaxrsExtension.NAMESPACE_1_0, true);
}
/**
* {@inheritDoc}
*/
@Override
public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException {
// Require no attributes or content
requireNoAttributes(reader);
requireNoContent(reader);
list.add(Util.createAddOperation(PathAddress.pathAddress(JaxrsExtension.SUBSYSTEM_PATH)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
public class JaxrsSubsystemParser_2_0 implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> {

static final PathAddress PATH_ADDRESS = PathAddress.pathAddress(JaxrsExtension.SUBSYSTEM_PATH);
private static final String NAMESPACE = "urn:jboss:domain:jaxrs:2.0";

@Override
public void readElement(final XMLExtendedStreamReader reader, final List<ModelNode> list) throws XMLStreamException {
Expand Down Expand Up @@ -158,7 +158,7 @@ public void readElement(final XMLExtendedStreamReader reader, final List<ModelNo
*/
@Override
public void writeContent(final XMLExtendedStreamWriter streamWriter, final SubsystemMarshallingContext context) throws XMLStreamException {
context.startSubsystemElement(JaxrsExtension.NAMESPACE_2_0, false);
context.startSubsystemElement(NAMESPACE, false);
ModelNode subsystem = context.getModelNode();
for (AttributeDefinition attr : JaxrsAttribute.ATTRIBUTES) {
attr.marshallAsElement(subsystem, true, streamWriter);
Expand Down
50 changes: 43 additions & 7 deletions jaxrs/src/main/java/org/jboss/as/jaxrs/JaxrsTransformers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@
package org.jboss.as.jaxrs;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.ExtensionTransformerRegistration;
import org.jboss.as.controller.transform.SubsystemTransformerRegistration;
import org.jboss.as.controller.transform.description.AttributeTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.ChainedTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.DiscardAttributeChecker;
import org.jboss.as.controller.transform.description.RejectAttributeChecker;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
* Jaxrs transformers.
*
* @author <a href="mailto:rsigal@redhat.com">Ron Sigal</a>
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class JaxrsTransformers implements ExtensionTransformerRegistration {
private static final String BYPASS_TRANSFORMER = "org.wildfly.jaxrs.unsupported.bypass.2.0.0.transformer";

// WildFly 8-10, JBoss EAP 7.0
private static final ModelVersion MODEL_VERSION_1_0_0 = ModelVersion.create(1, 0, 0);
// WildFly 11-21, JBoss EAP 7.1-7.3. Note that as of WildFly 19 the model should have been bumped but was missed.
// See https://issues.redhat.com/browse/WFLY-14210 for details.
private final ModelVersion MODEL_VERSION_2_0_0 = ModelVersion.create(2, 0, 0);

@Override
public String getSubsystemName() {
Expand All @@ -45,12 +56,29 @@ public String getSubsystemName() {

@Override
public void registerTransformers(SubsystemTransformerRegistration subsystemRegistration) {
registerTransformers_2_0_0(subsystemRegistration);
final ModelVersion[] modelVersions;
final ModelVersion target;
if (isByPassTransformers()) {
target = MODEL_VERSION_1_0_0;
modelVersions = new ModelVersion[] {MODEL_VERSION_1_0_0};
} else {
target = MODEL_VERSION_2_0_0;
modelVersions = new ModelVersion[] {MODEL_VERSION_2_0_0, MODEL_VERSION_1_0_0};
}
ChainedTransformationDescriptionBuilder chainedBuilder =
TransformationDescriptionBuilder.Factory.createChainedSubystemInstance(subsystemRegistration.getCurrentSubsystemVersion());

// Differences between 3.0.0 and 2.0.0
ResourceTransformationDescriptionBuilder builder300 =
chainedBuilder.createBuilder(subsystemRegistration.getCurrentSubsystemVersion(), target);
registerTransformers_3_0_0(builder300);

// Create chained transformers.
chainedBuilder.buildAndRegister(subsystemRegistration, modelVersions);
}

private static void registerTransformers_2_0_0(SubsystemTransformerRegistration subsystemRegistration) {
ResourceTransformationDescriptionBuilder builder = ResourceTransformationDescriptionBuilder.Factory.createSubsystemInstance();
AttributeTransformationDescriptionBuilder attributeBuilder = builder.getAttributeBuilder();
private static void registerTransformers_3_0_0(final ResourceTransformationDescriptionBuilder builder) {
final AttributeTransformationDescriptionBuilder attributeBuilder = builder.getAttributeBuilder();
checkAttribute(attributeBuilder, JaxrsAttribute.JAXRS_2_0_REQUEST_MATCHING);
checkAttribute(attributeBuilder, JaxrsAttribute.RESTEASY_ADD_CHARSET);
checkAttribute(attributeBuilder, JaxrsAttribute.RESTEASY_BUFFER_EXCEPTION_ENTITY);
Expand All @@ -72,11 +100,19 @@ private static void registerTransformers_2_0_0(SubsystemTransformerRegistration
checkAttribute(attributeBuilder, JaxrsAttribute.RESTEASY_USE_BUILTIN_PROVIDERS);
checkAttribute(attributeBuilder, JaxrsAttribute.RESTEASY_USE_CONTAINER_FORM_PARAMS);
checkAttribute(attributeBuilder, JaxrsAttribute.RESTEASY_WIDER_REQUEST_MATCHING);
TransformationDescription.Tools.register(builder.build(), subsystemRegistration, JaxrsExtension.MODEL_VERSION_1_0_0);
attributeBuilder.end();
}

private static void checkAttribute(AttributeTransformationDescriptionBuilder builder, AttributeDefinition attribute) {
builder.setDiscard(DiscardAttributeChecker.DEFAULT_VALUE, attribute)
.addRejectCheck(RejectAttributeChecker.DEFINED, attribute);
.addRejectCheck(RejectAttributeChecker.DEFINED, attribute);
}

private static boolean isByPassTransformers() {
final String value = WildFlySecurityManager.getPropertyPrivileged(BYPASS_TRANSFORMER, null);
if (value == null) {
return false;
}
return value.isEmpty() || Boolean.parseBoolean(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.io.IOException;
import java.util.List;

import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.RunningMode;
import org.jboss.as.model.test.FailedOperationTransformationConfig;
import org.jboss.as.model.test.ModelTestControllerVersion;
import org.jboss.as.model.test.ModelTestUtils;
Expand All @@ -42,6 +42,7 @@
* @author <a href="mailto:ema@rehdat.com>Jim Ma</a>
* @author <a href="mailto:alessio.soldano@jboss.com>Alessio Soldano</a>
* @author <a href="rsigal@redhat.com>Ron Sigal</a>
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
public class JaxrsTransformersTestCase extends AbstractSubsystemBaseTest {

Expand All @@ -54,60 +55,88 @@ protected String getSubsystemXml() throws IOException {
return readResource("jaxrs-2.0.xml");
}

@Test
public void testTransformers700() throws Exception {
testTransformers(ModelTestControllerVersion.EAP_7_0_0, "jaxrs-1.0.xml");
}

@Test
public void testTransformers710() throws Exception {
testTransformers(ModelTestControllerVersion.EAP_7_1_0, "jaxrs-1.0.xml");
}

@Test
public void testTransformers720() throws Exception {
testTransformers_2_0_to_1_0(ModelTestControllerVersion.EAP_7_2_0);
testTransformers(ModelTestControllerVersion.EAP_7_2_0, "jaxrs-1.0.xml");
}

@Test
public void testTransformers730() throws Exception {
testTransformers(ModelTestControllerVersion.EAP_7_3_0, "jaxrs-1.0.xml");
}

@Test
public void testRejections700() throws Exception {
testRejections(ModelTestControllerVersion.EAP_7_0_0, "jaxrs-2.0.xml", getFailedTransformationConfig());
}

@Test
public void testRejections710() throws Exception {
testRejections(ModelTestControllerVersion.EAP_7_1_0, "jaxrs-2.0.xml", getFailedTransformationConfig());
}

@Test
public void testRejections_1_0_0() throws Exception {
testRejections_2_0_0(ModelTestControllerVersion.EAP_7_2_0);
public void testRejections720() throws Exception {
testRejections(ModelTestControllerVersion.EAP_7_2_0, "jaxrs-2.0.xml", getFailedTransformationConfig());
}

/**
* Tests transformation of model from version 2.0 to version 1.0.
*/
private void testTransformers_2_0_to_1_0(ModelTestControllerVersion controllerVersion) throws Exception {
@Test
public void testRejections730() throws Exception {
testRejections(ModelTestControllerVersion.EAP_7_3_0, "jaxrs-2.0.xml", getFailedTransformationConfig());
}

@SuppressWarnings("SameParameterValue")
private void testTransformers(final ModelTestControllerVersion controllerVersion, final String xmlFileName) throws Exception {
final ModelVersion version = controllerVersion.getSubsystemModelVersion(getMainSubsystemName());
// create builder for current subsystem version
KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXmlResource("jaxrs-1.0.xml");
KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization()).setSubsystemXmlResource(xmlFileName);

// create builder for legacy subsystem version
builder.createLegacyKernelServicesBuilder(null, controllerVersion, JaxrsExtension.MODEL_VERSION_1_0_0)
.addMavenResourceURL("org.jboss.eap:wildfly-jaxrs:" + controllerVersion.getMavenGavVersion())
.configureReverseControllerCheck(AdditionalInitialization.MANAGEMENT, null);
builder.createLegacyKernelServicesBuilder(null, controllerVersion, version)
.addMavenResourceURL(controllerVersion.getMavenGroupId() + ":wildfly-jaxrs:" + controllerVersion.getMavenGavVersion())
.configureReverseControllerCheck(AdditionalInitialization.MANAGEMENT, null);

KernelServices mainServices = builder.build();
KernelServices legacyServices = mainServices.getLegacyServices(JaxrsExtension.MODEL_VERSION_1_0_0);
KernelServices legacyServices = mainServices.getLegacyServices(version);

Assert.assertNotNull(legacyServices);
Assert.assertTrue("main services did not boot", mainServices.isSuccessfulBoot());
Assert.assertTrue(legacyServices.isSuccessfulBoot());

checkSubsystemModelTransformation(mainServices, JaxrsExtension.MODEL_VERSION_1_0_0);
checkSubsystemModelTransformation(mainServices, version);
}

/**
* Tests rejections of attributes introduced in model version 2.0.
*/
private void testRejections_2_0_0(ModelTestControllerVersion controllerVersion) throws Exception {
@SuppressWarnings("SameParameterValue")
private void testRejections(final ModelTestControllerVersion controllerVersion, final String xmlFileName, final FailedOperationTransformationConfig config) throws Exception {
final ModelVersion version = controllerVersion.getSubsystemModelVersion(getMainSubsystemName());
// create builder for current subsystem version
KernelServicesBuilder builder = createKernelServicesBuilder(createAdditionalInitialization());

// create builder for legacy subsystem version
builder.createLegacyKernelServicesBuilder(null, controllerVersion, JaxrsExtension.MODEL_VERSION_1_0_0)
.addMavenResourceURL("org.jboss.eap:wildfly-jaxrs:" + controllerVersion.getMavenGavVersion())
.configureReverseControllerCheck(AdditionalInitialization.MANAGEMENT, null)
.dontPersistXml();
builder.createLegacyKernelServicesBuilder(null, controllerVersion, version)
.addMavenResourceURL(controllerVersion.getMavenGroupId() + ":wildfly-jaxrs:" + controllerVersion.getMavenGavVersion())
.configureReverseControllerCheck(AdditionalInitialization.MANAGEMENT, null)
.dontPersistXml();

KernelServices mainServices = builder.build();
KernelServices legacyServices = mainServices.getLegacyServices(JaxrsExtension.MODEL_VERSION_1_0_0);
KernelServices legacyServices = mainServices.getLegacyServices(version);

Assert.assertNotNull(legacyServices);
Assert.assertTrue("main services did not boot", mainServices.isSuccessfulBoot());
Assert.assertTrue(legacyServices.isSuccessfulBoot());

List<ModelNode> xmlOps = builder.parseXmlResource("jaxrs-2.0.xml");
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, JaxrsExtension.MODEL_VERSION_1_0_0, xmlOps, getFailedTransformationConfig());
List<ModelNode> xmlOps = builder.parseXmlResource(xmlFileName);
ModelTestUtils.checkFailedTransformedBootOperations(mainServices, version, xmlOps, config);
}

private FailedOperationTransformationConfig getFailedTransformationConfig() {
Expand Down Expand Up @@ -136,16 +165,7 @@ private FailedOperationTransformationConfig getFailedTransformationConfig() {
JaxrsAttribute.RESTEASY_USE_BUILTIN_PROVIDERS,
JaxrsAttribute.RESTEASY_USE_CONTAINER_FORM_PARAMS,
JaxrsAttribute.RESTEASY_WIDER_REQUEST_MATCHING
));
}

protected AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization() {
@Override
protected RunningMode getRunningMode() {
return RunningMode.ADMIN_ONLY;
}
};
));
}

}

0 comments on commit 6875cc3

Please sign in to comment.