fix: exclude Jackson from JBoss Modules to avoid classloading issues (and improve security)
chore(manager-test): tidy up contracts test
MODIFY
gateway/platforms/war/wildfly8/gateway/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
gateway/platforms/war/wildfly8/gateway/src/main/webapp/WEB-INF/jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<dependencies>
- <module name="org.codehaus.jackson.jackson-core-asl" />
- <module name="org.codehaus.jackson.jackson-mapper-asl" />
<module name="org.infinispan" />
- <module name="org.apache.log4j" />
- <module name="org.slf4j" />
+ <module name="org.hibernate" />
+ <module name="org.apache.log4j" /> <!-- Remove? -->
+ <module name="org.slf4j" /> <!-- Remove? -->
<module name="org.picketbox" />
+ <module name="org.hibernate.commons-annotations" />
+ <module name="org.jboss.logging" services="import"/>
</dependencies>
+ <exclusions>
+ <module name="com.fasterxml.jackson.core.jackson-core" />
+ <module name="com.fasterxml.jackson.core.jackson-annotations" />
+ <module name="com.fasterxml.jackson.core.jackson-databind" />
+ <module name="com.fasterxml.jackson.datatype.jackson-datatype-jdk8" />
+ <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" />
+ </exclusions>
<exclude-subsystems>
<subsystem name="webservices" />
</exclude-subsystems>

MODIFY
manager/api/exceptions/src/main/java/io/apiman/manager/api/rest/exceptions/util/ExceptionFactory.java
manager/api/exceptions/src/main/java/io/apiman/manager/api/rest/exceptions/util/ExceptionFactory.java
@@ -122,6 +122,14 @@ public final class ExceptionFactory {
return new ContractAlreadyExistsException(Messages.i18n.format("ContractAlreadyExists")); //$NON-NLS-1$
}
+ /**
+ * Creates an exception.
+ * @return the exception
+ */
+ public static ContractAlreadyExistsException contractDuplicateException() {
+ return new ContractAlreadyExistsException(Messages.i18n.format("ContractDuplicate")); //$NON-NLS-1$
+ }
+
/**
* Creates an exception from an client id.
* @param clientId the client id

MODIFY
manager/api/exceptions/src/main/resources/io/apiman/manager/api/rest/exceptions/i18n/messages.properties
manager/api/exceptions/src/main/resources/io/apiman/manager/api/rest/exceptions/i18n/messages.properties
@@ -25,6 +25,7 @@ PlanAlreadyExists=Plan already exists: {0}
PlanDoesNotExist=Plan does not exist: {0}
PlanVersionDoesNotExist=Plan Version does not exist: {0}:{1}
ContractAlreadyExists=Contract already exists.
+ContractDuplicate=Error creating contract: duplicate contract detected.
ContractDoesNotExist=Contract does not exist: {0}
ContractNotYetApproved=Contract(s) are not yet in approved state: {0}
ContractWrongState=Could not complete action: API was in the wrong status. Expected {0}, but was {1}

MODIFY
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
manager/api/jpa/src/main/java/io/apiman/manager/api/jpa/JpaStorage.java
@@ -165,7 +165,7 @@ public class JpaStorage extends AbstractJpaStorage implements IStorage, IStorage
csb.getApiId().equals(contract.getApi().getApi().getId()) &&
csb.getApiVersion().equals(contract.getApi().getVersion()))
{
- throw new StorageException("Error creating contract: duplicate contract detected."); //$NON-NLS-1$
+ throw new IllegalStateException("Error creating contract: duplicate contract detected."); //$NON-NLS-1$
}
}
super.create(contract);

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/util/RestHelper.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/rest/impl/util/RestHelper.java
@@ -126,7 +126,7 @@ public final class RestHelper {
apiVersion.setVersion(apiVersionBean.getVersion());
apiVersion.setDefinitionType(apiVersionBean.getDefinitionType());
apiVersion.setExposeInPortal(apiVersionBean.isExposeInPortal());
- apiVersion.setExtendedDescription(apiVersion.getExtendedDescription());
+ apiVersion.setExtendedDescription(apiVersionBean.getExtendedDescription());
return apiVersion;
}

MODIFY
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ContractService.java
manager/api/rest-impl/src/main/java/io/apiman/manager/api/service/ContractService.java
@@ -171,7 +171,11 @@ public class ContractService implements DataAccessUtilMixin {
contract.setStatus(ContractStatus.AwaitingApproval);
}
+ try {
storage.createContract(contract);
+ } catch (IllegalStateException ise) {
+ throw ExceptionFactory.contractDuplicateException();
+ }
storage.createAuditEntry(AuditUtils.contractCreatedFromClient(contract, securityContext));
storage.createAuditEntry(AuditUtils.contractCreatedToApi(contract, securityContext));

MODIFY
manager/test/api/src/test/resources/test-plan-data/contracts/contracts/013_create-duplicate-contract.resttest
manager/test/api/src/test/resources/test-plan-data/contracts/contracts/013_create-duplicate-contract.resttest
@@ -14,5 +14,5 @@ Content-Type: application/json
{
"type" : "ContractAlreadyExistsException",
"errorCode" : 4005,
- "message" : "Contract already exists."
+ "message" : "Error creating contract: duplicate contract detected."
}

MODIFY
manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/003_create-contract-2.resttest
manager/test/api/src/test/resources/test-plan-data/contracts/multi-contract/003_create-contract-2.resttest
@@ -8,11 +8,11 @@ Content-Type: application/json
"planId" : "PlanB"
}
----
-500
+409
Content-Type: application/json
{
- "type": "SystemErrorException",
- "message": "io.apiman.manager.api.core.exceptions.StorageException: Error creating contract: duplicate contract detected.",
+ "type": "ContractAlreadyExistsException",
+ "message": "Error creating contract: duplicate contract detected.",
"stacktrace": "*"
}
\ No newline at end of file

MODIFY
manager/test/api/src/test/resources/test-plans/contracts-testPlan.xml
manager/test/api/src/test/resources/test-plans/contracts-testPlan.xml
<!-- Some Error Cases -->
<testGroup name="Error Cases">
- <test name="Request Non-existant Contract">test-plan-data/contracts/error-cases/001_get-contract-404.resttest</test>
- <test name="Create Contract For Non-Existant Client">test-plan-data/contracts/error-cases/002_create-contract-no-client.resttest</test>
+ <test name="Request Non-existent Contract">test-plan-data/contracts/error-cases/001_get-contract-404.resttest</test>
+ <test name="Create Contract For Non-Existent Client">test-plan-data/contracts/error-cases/002_create-contract-no-client.resttest</test>
</testGroup>
</testPlan>

fix: exclude Jackson from JBoss Modules to avoid classloading issues (and improve security)

chore(manager-test): tidy up contracts test