Merge latest changes from trunk.
diff --git a/modules/rampart-integration/pom.xml b/modules/rampart-integration/pom.xml
index c666f15..3871110 100644
--- a/modules/rampart-integration/pom.xml
+++ b/modules/rampart-integration/pom.xml
@@ -656,24 +656,9 @@
<artifactId>log4j</artifactId>
</dependency>
<dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-util</artifactId>
- <version>${jetty.version}</version>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-webapp</artifactId>
- <version>${jetty.version}</version>
- </dependency>
- <dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-testutils</artifactId>
<version>${axis2.version}</version>
</dependency>
- <dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcpkix-jdk15on</artifactId>
- <version>${bcprov.jdk15.version}</version>
- </dependency>
</dependencies>
</project>
diff --git a/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java b/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
deleted file mode 100644
index 6742b6e..0000000
--- a/modules/rampart-integration/src/main/java/org/apache/axis2/integration/JettyServer.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright 2004 - 2014 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.axis2.integration;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.math.BigInteger;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.KeyStore;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SecureRandom;
-import java.security.cert.X509Certificate;
-import java.util.Date;
-import java.util.Random;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-
-import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.eclipse.jetty.util.ssl.SslContextFactory;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.junit.rules.ExternalResource;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.transport.http.AxisServlet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.bouncycastle.asn1.x500.X500Name;
-import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
-import org.bouncycastle.cert.X509CertificateHolder;
-import org.bouncycastle.cert.X509v3CertificateBuilder;
-import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
-import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
-
-/**
- * Support for running an embedded Jetty server
- */
-public class JettyServer extends ExternalResource {
- /**
- * The alias of the certificate to configure for Jetty's ssl context factory: {@value}
- */
- private static final String CERT_ALIAS = "server";
-
- /**
- * Webapp resource base directory to use: {@value}
- */
- private static final String WEBAPP_DIR = "target" + File.separator + "webapp";
-
- private static final Log log = LogFactory.getLog(JettyServer.class);
-
- private final String repository;
- private final boolean secure;
- private File keyStoreFile;
- private File trustStoreFile;
- private Server server;
- private boolean systemPropertiesSet;
- private String savedTrustStore;
- private String savedTrustStorePassword;
- private String savedTrustStoreType;
-
- /**
- * Constructor.
- *
- * @param repository
- * The path to the Axis2 repository to use. Must not be null or empty.
- * @param secure
- * Whether to enable HTTPS.
- */
- public JettyServer(String repository, boolean secure) {
- if (repository == null || repository.trim().length() == 0) {
- throw new IllegalArgumentException("Axis2 repository must not be null or empty");
- }
- this.repository = repository;
- this.secure = secure;
- }
-
- private String generatePassword(Random random) {
- char[] password = new char[8];
- for (int i=0; i<password.length; i++) {
- password[i] = (char)('0' + random.nextInt(10));
- }
- return new String(password);
- }
-
- private void writeKeyStore(KeyStore keyStore, File file, String password) throws Exception {
- FileOutputStream out = new FileOutputStream(file);
- try {
- keyStore.store(out, password.toCharArray());
- } finally {
- out.close();
- }
- }
-
- @Override
- protected void before() throws Throwable {
- server = new Server();
-
- if (!secure) {
- SelectChannelConnector connector = new SelectChannelConnector();
- server.addConnector(connector);
- } else {
- SecureRandom random = new SecureRandom();
-
- // Generate key pair
- KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
- keyPairGenerator.initialize(1024, random);
- KeyPair keyPair = keyPairGenerator.generateKeyPair();
- PrivateKey privateKey = keyPair.getPrivate();
- PublicKey publicKey = keyPair.getPublic();
-
- // Generate certificate
- X500Name dn = new X500Name("cn=localhost,o=Apache");
- BigInteger serial = BigInteger.valueOf(random.nextInt());
- Date notBefore = new Date();
- Date notAfter = new Date(notBefore.getTime() + 3600000L);
- SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(publicKey.getEncoded());
- X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(dn, serial, notBefore, notAfter, dn, subPubKeyInfo);
- X509CertificateHolder certHolder = certBuilder.build(new JcaContentSignerBuilder("SHA1WithRSA").build(privateKey));
- X509Certificate cert = new JcaX509CertificateConverter().getCertificate(certHolder);
-
- // Build key store
- keyStoreFile = File.createTempFile("keystore", "jks", null);
- String keyStorePassword = generatePassword(random);
- String keyPassword = generatePassword(random);
- KeyStore keyStore = KeyStore.getInstance("JKS");
- keyStore.load(null, null);
- keyStore.setKeyEntry(CERT_ALIAS, privateKey, keyPassword.toCharArray(), new X509Certificate[] { cert });
- writeKeyStore(keyStore, keyStoreFile, keyStorePassword);
-
- // Build trust store
- trustStoreFile = File.createTempFile("truststore", "jks", null);
- String trustStorePassword = generatePassword(random);
- KeyStore trustStore = KeyStore.getInstance("JKS");
- trustStore.load(null, null);
- trustStore.setCertificateEntry(CERT_ALIAS, cert);
- writeKeyStore(trustStore, trustStoreFile, trustStorePassword);
-
- SslContextFactory sslContextFactory = new SslContextFactory();
- sslContextFactory.setKeyStorePath(keyStoreFile.getAbsolutePath());
- sslContextFactory.setKeyStorePassword(keyStorePassword);
- sslContextFactory.setKeyManagerPassword(keyPassword);
- sslContextFactory.setCertAlias(CERT_ALIAS);
- SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
-
- server.addConnector(sslConnector);
-
- savedTrustStore = System.getProperty("javax.net.ssl.trustStore");
- System.setProperty("javax.net.ssl.trustStore", trustStoreFile.getAbsolutePath());
- savedTrustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
- System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
- savedTrustStoreType = System.getProperty("javax.net.ssl.trustStoreType");
- System.setProperty("javax.net.ssl.trustStoreType", "JKS");
- systemPropertiesSet = true;
- }
-
- WebAppContext context = new WebAppContext();
- File webappDir = new File(WEBAPP_DIR);
- if (!webappDir.exists() && !webappDir.mkdirs()) {
- log.error("Failed to create Axis2 webapp directory: " + webappDir.getAbsolutePath());
- }
-
- context.setResourceBase(webappDir.getAbsolutePath());
- context.setContextPath("/axis2");
- context.setParentLoaderPriority(true);
- context.setThrowUnavailableOnStartupException(true);
-
- final ConfigurationContext configurationContext =
- ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository);
- @SuppressWarnings("serial")
- ServletHolder servlet = new ServletHolder(new AxisServlet() {
- @Override
- protected ConfigurationContext initConfigContext(ServletConfig config)
- throws ServletException {
- return configurationContext;
- }
- });
-
- //load on startup to trigger Axis2 initialization and service deployment
- //this is for backward compatibility with the SimpleHttpServer which initializes Axis2 on startup
- servlet.setInitOrder(0);
-
- context.addServlet(servlet, "/services/*");
-
- server.setHandler(context);
-
- try {
- server.start();
- }
- catch (SecurityException e) {
- if (e.getMessage().equals("class \"javax.servlet.ServletRequestListener\"'s signer information does not match signer information of other classes in the same package")) {
- log.error(
- "It is likely your test classpath contains multiple different versions of servlet api.\n" +
- "If you are running this test in an IDE, please configure it to exclude Rampart's core module servlet api dependency.");
- throw e;
- }
- }
-
- log.info("Server started on port " + getPort());
- }
-
- @Override
- protected void after() {
- if (server != null) {
- log.info("Stop called");
- try {
- server.stop();
- } catch (Exception ex) {
- log.error("Failed to stop Jetty server", ex);
- }
- server = null;
- }
- if (systemPropertiesSet) {
- if (savedTrustStore != null) {
- System.setProperty("javax.net.ssl.trustStore", savedTrustStore);
- } else {
- System.clearProperty("javax.net.ssl.trustStore");
- }
- if (savedTrustStorePassword != null) {
- System.setProperty("javax.net.ssl.trustStorePassword", savedTrustStorePassword);
- } else {
- System.clearProperty("javax.net.ssl.trustStorePassword");
- }
- if (savedTrustStoreType != null) {
- System.setProperty("javax.net.ssl.trustStoreType", savedTrustStoreType);
- } else {
- System.clearProperty("javax.net.ssl.trustStoreType");
- }
- savedTrustStore = null;
- savedTrustStorePassword = null;
- savedTrustStoreType = null;
- systemPropertiesSet = false;
- }
- if (keyStoreFile != null) {
- keyStoreFile.delete();
- keyStoreFile = null;
- }
- if (trustStoreFile != null) {
- trustStoreFile.delete();
- trustStoreFile = null;
- }
- }
-
- /**
- * @return Jetty's http connector port.
- * @throws IllegalStateException If Jetty is not running or the http connector cannot be found.
- */
- public int getPort() throws IllegalStateException {
- if (server == null) {
- throw new IllegalStateException("Jetty server is not initialized");
- }
- if (!server.isStarted()) {
- throw new IllegalStateException("Jetty server is not started");
- }
-
- Connector[] connectors = server.getConnectors();
- if (connectors.length == 0) {
- throw new IllegalStateException("Jetty server is not configured with any connectors");
- }
-
- for (Connector connector : connectors) {
- if (connector instanceof SelectChannelConnector) {
- //must be the http connector
- return connector.getLocalPort();
- }
- }
-
- throw new IllegalStateException("Could not find Jetty http connector");
- }
-
- public String getEndpoint(String serviceName) {
- return String.format("%s://localhost:%s/axis2/services/%s", secure ? "https" : "http", getPort(), serviceName);
- }
-
- public EndpointReference getEndpointReference(String serviceName) {
- return new EndpointReference(getEndpoint(serviceName));
- }
-}
diff --git a/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java b/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
index 80fc3e1..3b484c1 100644
--- a/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
+++ b/modules/rampart-integration/src/main/java/org/apache/rahas/TestClient.java
@@ -28,10 +28,9 @@
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.integration.JettyServer;
+import org.apache.axis2.testutils.ClientHelper;
+import org.apache.axis2.testutils.JettyServer;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
@@ -43,40 +42,15 @@
@Rule
public final JettyServer server = new JettyServer(TESTING_PATH + getServiceRepo(), false);
+ @Rule
+ public final ClientHelper clientHelper = new ClientHelper(server, TESTING_PATH + "rahas_client_repo");
+
/**
*/
@Test
public void testRequest() throws Exception {
- // Get the repository location from the args
- String repo = TESTING_PATH + "rahas_client_repo";
-
- ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repo,
- null);
- ServiceClient serviceClient = new ServiceClient(configContext, null);
- Options options = new Options();
-
- System.setProperty("javax.net.ssl.keyStorePassword", "password");
- System.setProperty("javax.net.ssl.keyStoreType", "JKS");
- System.setProperty("javax.net.ssl.trustStore", "/home/ruchith/Desktop/interop/certs/interop2.jks");
- System.setProperty("javax.net.ssl.trustStorePassword", "password");
- System.setProperty("javax.net.ssl.trustStoreType","JKS");
-
- options.setTo(server.getEndpointReference("SecureService"));
-// options.setTo(new EndpointReference("http://127.0.0.1:" + 9090 + "/axis2/services/UTSAMLHoK"));
-// options.setTo(new EndpointReference("https://www-lk.wso2.com:8443/axis2/services/UTSAMLHoK"));
-// options.setTo(new EndpointReference("https://192.18.49.133:2343/jaxws-s1-sts/sts"));
-// options.setTo(new EndpointReference("https://207.200.37.116/SxSts/Scenario_1_IssuedTokenOverTransport_UsernameOverTransport"));
-// options.setTo(new EndpointReference("http://localhost:9090/SxSts/Scenario_4_IssuedToken_MutualCertificate10"));
-
-// options.setTo(new EndpointReference("http://127.0.0.1:" + 9090 + "/axis2/services/MutualCertsSAMLHoK"));
-// options.setTo(new EndpointReference("http://www-lk.wso2.com:8888/axis2/services/MutualCertsSAMLHoK"));
-// options.setTo(new EndpointReference("https://131.107.72.15/trust/Addressing2004/UserName"));
-// options.setTo(new EndpointReference("https://131.107.72.15/trust/UserName"));
-// options.setTo(new EndpointReference("http://127.0.0.1:" + 9090 + "/trust/X509WSS10"));
-// options.setTo(new EndpointReference("https://131.107.72.15/trust/UserName"));
-// options.setTo(new EndpointReference("http://127.0.0.1:" + 9090 + "/jaxws-s4-sts/sts"));
-// options.setTo(new EndpointReference("http://127.0.0.1:9090/jaxws-s4/simple"));
-// options.setTo(new EndpointReference("http://127.0.0.1:" + 9090 + "/axis2/services/UTSAMLBearer"));
+ ServiceClient serviceClient = clientHelper.createServiceClient("SecureService");
+ Options options = serviceClient.getOptions();
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setAction(this.getRequestAction());
@@ -90,8 +64,6 @@
serviceClient.engageModule("addressing");
serviceClient.engageModule("rampart");
- serviceClient.setOptions(options);
-
//Blocking invocation
OMElement result = serviceClient.sendReceive(getRequest());
diff --git a/modules/rampart-integration/src/test/java/org/apache/rampart/AbstractRampartTest.java b/modules/rampart-integration/src/test/java/org/apache/rampart/AbstractRampartTest.java
index a009934..dbcdbad 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rampart/AbstractRampartTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rampart/AbstractRampartTest.java
@@ -26,7 +26,6 @@
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.integration.JettyServer;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
diff --git a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java
index 8554871..c489900 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartKerberosTest.java
@@ -11,7 +11,7 @@
import org.apache.axiom.om.OMElement;
import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.integration.JettyServer;
+import org.apache.axis2.testutils.JettyServer;
import org.apache.commons.io.IOUtils;
import org.apache.neethi.Policy;
import org.apache.rampart.policy.model.KerberosConfig;
diff --git a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
index 064d197..1791434 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rampart/RampartTest.java
@@ -30,10 +30,9 @@
import org.apache.axis2.Constants;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.integration.JettyServer;
+import org.apache.axis2.testutils.ClientHelper;
+import org.apache.axis2.testutils.JettyServer;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.junit.Rule;
@@ -50,8 +49,26 @@
public final JettyServer server = new JettyServer(TESTING_PATH + "rampart_service_repo", false);
@Rule
+ public final ClientHelper clientHelper = new ClientHelper(server, TESTING_PATH + "rampart_client_repo") {
+ @Override
+ protected void configureServiceClient(ServiceClient serviceClient) throws Exception {
+ serviceClient.engageModule("addressing");
+ serviceClient.engageModule("rampart");
+ }
+ };
+
+ @Rule
public final JettyServer secureServer = new JettyServer(TESTING_PATH + "rampart_service_repo", true);
+ @Rule
+ public final ClientHelper secureClientHelper = new ClientHelper(secureServer, TESTING_PATH + "rampart_client_repo") {
+ @Override
+ protected void configureServiceClient(ServiceClient serviceClient) throws Exception {
+ serviceClient.engageModule("addressing");
+ serviceClient.engageModule("rampart");
+ }
+ };
+
static {
try {
resources = ResourceBundle.getBundle("org.apache.rampart.errors");
@@ -60,28 +77,9 @@
}
}
- private ServiceClient getServiceClientInstance() throws AxisFault {
-
- String repository = TESTING_PATH + "rampart_client_repo";
-
- ConfigurationContext configContext = ConfigurationContextFactory.
- createConfigurationContextFromFileSystem(repository, null);
- ServiceClient serviceClient = new ServiceClient(configContext, null);
-
-
- serviceClient.engageModule("addressing");
- serviceClient.engageModule("rampart");
-
- return serviceClient;
-
- }
-
@Test
public void testWithPolicy() {
try {
-
- ServiceClient serviceClient = getServiceClientInstance();
-
//TODO : figure this out !!
boolean basic256Supported = false;
@@ -101,17 +99,15 @@
// Testcase - 25 is failing, for the moment skipping it.
continue;
}
- Options options = new Options();
+
+ ServiceClient serviceClient = (i == 13 ? secureClientHelper : clientHelper).createServiceClient("SecureService" + i);
+ Options options = serviceClient.getOptions();
if( i == 13 ) {
- options.setTo(secureServer.getEndpointReference("SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
options.setPassword("password");
}
- else {
- options.setTo(server.getEndpointReference("SecureService" + i));
- }
System.out.println("Testing WS-Sec: custom scenario " + i);
options.setAction("urn:echo");
@@ -119,7 +115,6 @@
ServiceContext context = serviceClient.getServiceContext();
context.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy("/rampart/policy/" + i + ".xml"));
- serviceClient.setOptions(options);
if (i == 31) {
OMNamespace omNamespace = OMAbstractFactory.getOMFactory().createOMNamespace(
@@ -173,24 +168,21 @@
//Skip the Basic256 tests
continue;
}
- Options options = new Options();
+
+ ServiceClient serviceClient = (i == 13 ? secureClientHelper : clientHelper).createServiceClient("SecureService" + i);
+ Options options = serviceClient.getOptions();
if (i == 13) {
- options.setTo(secureServer.getEndpointReference("SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
options.setPassword("password");
}
- else {
- options.setTo(server.getEndpointReference("SecureService" + i));
- }
System.out.println("Testing WS-Sec: negative scenario " + i);
options.setAction("urn:returnError");
ServiceContext context = serviceClient.getServiceContext();
context.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy("/rampart/policy/" + i + ".xml"));
- serviceClient.setOptions(options);
try {
//Blocking invocation
@@ -204,23 +196,19 @@
for (int i = 1; i <= 6; i++) { //<-The number of tests we have
- Options options = new Options();
-
+ ServiceClient serviceClient;
if (i == 3 || i == 6) {
- options.setTo(secureServer.getEndpointReference("SecureServiceSC" + i));
+ serviceClient = secureClientHelper.createServiceClient("SecureServiceSC" + i);
}
else {
- options.setTo(server.getEndpointReference("SecureServiceSC" + i));
+ serviceClient = clientHelper.createServiceClient("SecureServiceSC" + i);
}
+ Options options = serviceClient.getOptions();
System.out.println("Testing WS-SecConv: custom scenario " + i);
options.setAction("urn:echo");
- //Create a new service client instance for each secure conversation scenario
- serviceClient = getServiceClientInstance();
-
serviceClient.getServiceContext().setProperty(RampartMessageData.KEY_RAMPART_POLICY, loadPolicy("/rampart/policy/sc-" + i + ".xml"));
- serviceClient.setOptions(options);
//Blocking invocation
serviceClient.sendReceive(getEchoElement());
diff --git a/pom.xml b/pom.xml
index 4f49a17..d89871d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -624,8 +624,6 @@
<failIfNoTests>false</failIfNoTests>
<jacoco.version>0.7.5.201505241946</jacoco.version>
-
- <jetty.version>7.6.15.v20140411</jetty.version>
</properties>
<pluginRepositories>