Merge latest changes from trunk.
diff --git a/modules/rampart-integration/pom.xml b/modules/rampart-integration/pom.xml
index 8fed00a..1894caf 100644
--- a/modules/rampart-integration/pom.xml
+++ b/modules/rampart-integration/pom.xml
@@ -85,6 +85,7 @@
</goals>
<configuration>
<modules>addressing,rampart,rahas</modules>
+ <axis2xml>src/test/resources/conf/axis2.xml</axis2xml>
<outputDirectory>target/test-resources/rampart_service_repo</outputDirectory>
</configuration>
</execution>
@@ -105,6 +106,7 @@
</goals>
<configuration>
<modules>addressing,rampart,rahas</modules>
+ <axis2xml>src/test/resources/conf/axis2.xml</axis2xml>
<outputDirectory>target/test-resources/rahas_service_repo_1</outputDirectory>
</configuration>
</execution>
@@ -115,6 +117,7 @@
</goals>
<configuration>
<modules>addressing,rampart,rahas</modules>
+ <axis2xml>src/test/resources/conf/axis2.xml</axis2xml>
<outputDirectory>target/test-resources/rahas_service_repo_3</outputDirectory>
</configuration>
</execution>
@@ -126,6 +129,7 @@
<configuration>
<modules>addressing,rampart</modules>
<axis2xml>src/test/resources/conf/axis2.xml</axis2xml>
+ <configurationDirectory>conf</configurationDirectory>
<outputDirectory>target/test-resources/default_security_client_repo</outputDirectory>
</configuration>
</execution>
@@ -136,13 +140,11 @@
</goals>
<configuration>
<modules>addressing,rampart,rahas</modules>
+ <axis2xml>src/test/resources/conf/axis2.xml</axis2xml>
<outputDirectory>target/test-resources/rahas_service_repo_5</outputDirectory>
</configuration>
</execution>
</executions>
- <configuration>
- <configurationDirectory>conf</configurationDirectory>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -368,83 +370,6 @@
</execution>
</executions>
</plugin>
- <plugin>
- <artifactId>maven-clean-plugin</artifactId>
- <executions>
- <execution>
- <!-- Need to clean the keystore because keytool-maven-plugin is not idempotent and fails
- when executing mvn install twice in a row. Note that keytool-maven-plugin also has
- a "clean" goal but we don't use it because it generates a warning if the keystore
- doesn't exist. -->
- <phase>generate-test-resources</phase>
- <goals>
- <goal>clean</goal>
- </goals>
- <configuration>
- <excludeDefaultDirectories>true</excludeDefaultDirectories>
- <filesets>
- <fileset>
- <directory>${project.build.directory}/test-resources/jetty</directory>
- <includes>
- <include>server.jks</include>
- <include>server.cer</include>
- <include>client.jks</include>
- </includes>
- </fileset>
- </filesets>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>keytool-maven-plugin</artifactId>
- <version>1.5</version>
- <executions>
- <execution>
- <id>generate-key-pair</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>generateKeyPair</goal>
- </goals>
- <configuration>
- <alias>server</alias>
- <dname>cn=localhost,o=OASIS</dname>
- <keyalg>RSA</keyalg>
- <keypass>password</keypass>
- <keystore>${project.build.directory}/test-resources/jetty/server.jks</keystore>
- <storepass>password</storepass>
- </configuration>
- </execution>
- <execution>
- <id>export-certificate</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>exportCertificate</goal>
- </goals>
- <configuration>
- <alias>server</alias>
- <file>${project.build.directory}/test-resources/jetty/server.cer</file>
- <keystore>${project.build.directory}/test-resources/jetty/server.jks</keystore>
- <storepass>password</storepass>
- </configuration>
- </execution>
- <execution>
- <id>import-certificate</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>importCertificate</goal>
- </goals>
- <configuration>
- <alias>server</alias>
- <file>${project.build.directory}/test-resources/jetty/server.cer</file>
- <keystore>${project.build.directory}/test-resources/jetty/client.jks</keystore>
- <storepass>password</storepass>
- <noprompt>true</noprompt>
- </configuration>
- </execution>
- </executions>
- </plugin>
<!--plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
@@ -585,5 +510,10 @@
<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
index ce2b863..6742b6e 100644
--- 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
@@ -16,6 +16,20 @@
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;
@@ -24,145 +38,145 @@
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.webapp.WebAppContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.axis2.testutils.PortAllocator;
+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 {
-
- /**
- * Keystore to configure for Jetty's ssl context factory: {@value}
- */
- public static final String KEYSTORE = "target/test-resources/jetty/server.jks";
-
- /**
- * Keymanager password to configure for Jetty's ssl context factory: {@value
- */
- public static final String KEYMAN_PASSWORD = "password";
-
- /**
- * Keystore password to configure for Jetty's ssl context factory: {@value}
- */
- public static final String KEYSTORE_PASSWORD = "password";
-
+public class JettyServer extends ExternalResource {
/**
* The alias of the certificate to configure for Jetty's ssl context factory: {@value}
*/
- public static final String CERT_ALIAS = "server";
-
- /**
- * Client keystore containing Jetty's server certificate as trusted certificate entry: : {@value}
- */
- public static final String CLIENT_KEYSTORE = "target/test-resources/jetty/client.jks";
-
- /**
- * Axis2 configuration file to use: {@value}
- */
- public static final String AXIS2_XML = "src/test/resources/conf/axis2.xml";
+ private static final String CERT_ALIAS = "server";
/**
* Webapp resource base directory to use: {@value}
*/
- public static final String WEBAPP_DIR = "target" + File.separator + "webapp";
+ private static final String WEBAPP_DIR = "target" + File.separator + "webapp";
- private static final Logger logger = LoggerFactory.getLogger(JettyServer.class);
+ private static final Log log = LogFactory.getLog(JettyServer.class);
- private static Server server;
-
- private JettyServer() {
-
- }
+ 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;
/**
- * Starts the embedded Jetty server using dynamic port allocation with both http and https connectors enabled.
+ * Constructor.
*
- * @param repository The path to the Axis2 repository to use. Must not be null or empty.
- *
- * @throws Exception
+ * @param repository
+ * The path to the Axis2 repository to use. Must not be null or empty.
+ * @param secure
+ * Whether to enable HTTPS.
*/
- public static synchronized void start(String repository) throws Exception {
- start(repository, true, true);
- }
-
- /**
- * Starts the embedded Jetty server using dynamic port allocation.
- *
- * @param repository The path to the Axis2 repository to use. Must not be null or empty.
- * @param enableHttp Specifies whether to enable http connector.
- * @param enableHttps Specifies whether to enable https connector.
- *
- * @throws Exception
- */
- public static synchronized void start(String repository, boolean enableHttp, boolean enableHttps) throws Exception {
- int httpPort = enableHttp ? PortAllocator.allocatePort() : -1;
- int httpsPort = enableHttps ? PortAllocator.allocatePort() : -1;
-
- start(repository, httpPort, httpsPort);
- }
-
- /**
- * Starts the embedded Jetty server.
- *
- * @param repository The path to the Axis2 repository to use. Must not be null or empty.
- * @param httpPort The http port to use. Set to <code>-1</code> to disable http connector.
- * @param httpsPort The https port to use. Set to <code>-1</code> to disable https connector.
- *
- * @throws Exception
- * @throws IllegalArgumentException If both ports are set to <code>-1</code>
- */
- public static synchronized void start(String repository, int httpPort, int httpsPort) throws Exception {
+ public JettyServer(String repository, boolean secure) {
if (repository == null || repository.trim().length() == 0) {
throw new IllegalArgumentException("Axis2 repository must not be null or empty");
}
- else if (httpPort == -1 && httpsPort == -1) {
- throw new IllegalArgumentException("At least one port must be specified.");
- }
+ 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();
- SelectChannelConnector connector = null;
- if (httpPort == -1) {
- logger.debug("Http connector is disabled");
- }
- else {
- logger.info("Starting http connector on port: " + httpPort);
-
- connector = new SelectChannelConnector();
- connector.setPort(httpPort);
+ if (!secure) {
+ SelectChannelConnector connector = new SelectChannelConnector();
server.addConnector(connector);
- }
-
- if (httpsPort == -1) {
- logger.debug("Https connector is disabled");
- }
- else {
+ } 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(KEYSTORE);
- sslContextFactory.setKeyStorePassword(KEYSTORE_PASSWORD);
- sslContextFactory.setKeyManagerPassword(KEYMAN_PASSWORD);
- sslContextFactory.setTrustStore(KEYSTORE);
- sslContextFactory.setTrustStorePassword(KEYSTORE_PASSWORD);
+ sslContextFactory.setKeyStorePath(keyStoreFile.getAbsolutePath());
+ sslContextFactory.setKeyStorePassword(keyStorePassword);
+ sslContextFactory.setKeyManagerPassword(keyPassword);
sslContextFactory.setCertAlias(CERT_ALIAS);
SslSelectChannelConnector sslConnector = new SslSelectChannelConnector(sslContextFactory);
- logger.info("Starting https connector on port: " + httpsPort);
-
- sslConnector.setPort(httpsPort);
server.addConnector(sslConnector);
- if (connector != null) {
- connector.setConfidentialPort(httpsPort);
- }
+ 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()) {
- logger.error("Failed to create Axis2 webapp directory: " + webappDir.getAbsolutePath());
+ log.error("Failed to create Axis2 webapp directory: " + webappDir.getAbsolutePath());
}
context.setResourceBase(webappDir.getAbsolutePath());
@@ -170,10 +184,16 @@
context.setParentLoaderPriority(true);
context.setThrowUnavailableOnStartupException(true);
- ServletHolder servlet = new ServletHolder();
- servlet.setClassName(AxisServlet.class.getName());
- servlet.setInitParameter("axis2.repository.path", repository);
- servlet.setInitParameter("axis2.xml.path", AXIS2_XML);
+ 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
@@ -188,33 +208,69 @@
}
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")) {
- logger.error(
+ 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());
}
- /**
- * Stops the embedded Jetty server.
- *
- * @throws Exception
- */
- public static synchronized void stop() throws Exception {
+ @Override
+ protected void after() {
if (server != null) {
- logger.info("Stop called");
- server.stop();
+ 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 static synchronized int getHttpPort() throws IllegalStateException {
- assertStarted();
+ 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) {
@@ -222,44 +278,20 @@
}
for (Connector connector : connectors) {
- if ((connector instanceof SelectChannelConnector) &&
- !(connector instanceof SslSelectChannelConnector)) {
+ if (connector instanceof SelectChannelConnector) {
//must be the http connector
- return connector.getPort();
+ return connector.getLocalPort();
}
}
throw new IllegalStateException("Could not find Jetty http connector");
}
-
- /**
- * @return Jetty's ssl connector port.
- * @throws IllegalStateException If Jetty is not running or the ssl connector cannot be found.
- */
- public static synchronized int getHttpsPort() throws IllegalStateException {
- assertStarted();
-
- 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 SslSelectChannelConnector) {
- //must be the https connector
- return connector.getPort();
- }
- }
-
- throw new IllegalStateException("Could not find Jetty https connector");
+
+ public String getEndpoint(String serviceName) {
+ return String.format("%s://localhost:%s/axis2/services/%s", secure ? "https" : "http", getPort(), serviceName);
}
-
- private static void assertStarted() throws IllegalStateException {
- if (server == null) {
- throw new IllegalStateException("Jetty server is not initialized");
- }
- else if (!server.isStarted()) {
- throw new IllegalStateException("Jetty server is not started");
- }
+
+ public EndpointReference getEndpointReference(String serviceName) {
+ return new EndpointReference(getEndpoint(serviceName));
}
}
diff --git a/modules/rampart-integration/src/main/java/org/apache/axis2/integration/TestConstants.java b/modules/rampart-integration/src/main/java/org/apache/axis2/integration/TestConstants.java
new file mode 100644
index 0000000..c20a517
--- /dev/null
+++ b/modules/rampart-integration/src/main/java/org/apache/axis2/integration/TestConstants.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+
+public final class TestConstants {
+ public static final String TESTING_PATH = "target/test-resources/";
+
+ private TestConstants() {}
+}
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 33f850b..80fc3e1 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
@@ -16,6 +16,8 @@
package org.apache.rahas;
+import static org.apache.axis2.integration.TestConstants.TESTING_PATH;
+
import java.io.FileInputStream;
import java.io.InputStream;
@@ -24,7 +26,6 @@
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingConstants;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
@@ -34,30 +35,20 @@
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.rampart.RampartMessageData;
+import org.junit.Rule;
+import org.junit.Test;
-import junit.framework.TestCase;
+public abstract class TestClient {
-public abstract class TestClient extends TestCase {
-
- protected int port = 5555;
-
- public TestClient(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- JettyServer.start(Constants.TESTING_PATH + getServiceRepo(), port, -1);
- }
-
- protected void tearDown() throws Exception {
- JettyServer.stop();
- }
+ @Rule
+ public final JettyServer server = new JettyServer(TESTING_PATH + getServiceRepo(), false);
/**
*/
+ @Test
public void testRequest() throws Exception {
// Get the repository location from the args
- String repo = Constants.TESTING_PATH + "rahas_client_repo";
+ String repo = TESTING_PATH + "rahas_client_repo";
ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repo,
null);
@@ -70,7 +61,7 @@
System.setProperty("javax.net.ssl.trustStorePassword", "password");
System.setProperty("javax.net.ssl.trustStoreType","JKS");
- options.setTo(new EndpointReference("http://127.0.0.1:" + port + "/axis2/services/SecureService"));
+ 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"));
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
index dda4c7c..546bac4 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenCertForHoKTest.java
@@ -22,13 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAML2TokenCertForHoKTest extends TestClient{
- public RahasSAML2TokenCertForHoKTest(String name) {
- super(name);
- }
-
public String getServiceRepo() {
return "rahas_service_repo_1";
}
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
index 9d34316..9e35c98 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenTest.java
@@ -22,15 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
-import javax.xml.namespace.QName;
-public class RahasSAML2TokenTest extends TestClient{
- /**
- * @param name
- */
- public RahasSAML2TokenTest(String name) {
- super(name);
- }
+import static org.junit.Assert.assertNotNull;
+import javax.xml.namespace.QName;
+
+public class RahasSAML2TokenTest extends TestClient{
public String getServiceRepo() {
return "rahas_service_repo_1";
}
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
index 72f70bd..76967c5 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAML2TokenUTForBearerTest.java
@@ -33,6 +33,10 @@
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayInputStream;
import java.util.List;
@@ -41,11 +45,6 @@
* @author Ruchith Fernando (ruchith.fernando@gmail.com)
*/
public class RahasSAML2TokenUTForBearerTest extends TestClient {
-
- public RahasSAML2TokenUTForBearerTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
index 1104743..8acb16e 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenAttributeTest.java
@@ -1,5 +1,7 @@
package org.apache.rahas;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
@@ -9,11 +11,6 @@
import org.apache.ws.secpolicy.SP11Constants;
public class RahasSAMLTokenAttributeTest extends TestClient{
-
- public RahasSAMLTokenAttributeTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
index 4fa687c..9bdcd87 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKTest.java
@@ -22,15 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
-
public class RahasSAMLTokenCertForHoKTest extends TestClient {
-
- public RahasSAMLTokenCertForHoKTest(String name) {
- super(name);
- }
-
public String getServiceRepo() {
return "rahas_service_repo_1";
}
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
index 8c59a25..006b9a0 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenCertForHoKV1205Test.java
@@ -22,15 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP12Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenCertForHoKV1205Test extends TestClient {
-
-
- public RahasSAMLTokenCertForHoKV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem =
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
index cb579f5..61ed5d2 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenTest.java
@@ -22,18 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenTest extends TestClient {
-
-
- /**
- * @param name
- */
- public RahasSAMLTokenTest(String name) {
- super(name);
- }
-
public String getServiceRepo() {
return "rahas_service_repo_1";
}
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
index 94d0827..93ed846 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerTest.java
@@ -34,6 +34,10 @@
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.io.ByteArrayInputStream;
import java.util.List;
@@ -42,11 +46,6 @@
* @author Ruchith Fernando (ruchith.fernando@gmail.com)
*/
public class RahasSAMLTokenUTForBearerTest extends TestClient {
-
- public RahasSAMLTokenUTForBearerTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
index 3be3e08..bfd771f 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForBearerV1205Test.java
@@ -22,17 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP12Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenUTForBearerV1205Test extends TestClient {
-
- /**
- * @param name
- */
- public RahasSAMLTokenUTForBearerV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_12);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
index cb88a79..9e21c61 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKTest.java
@@ -22,14 +22,11 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP11Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
public class RahasSAMLTokenUTForHoKTest extends TestClient {
-
- public RahasSAMLTokenUTForHoKTest(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_02);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
index 5e816e1..d15ba09 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenUTForHoKV1205Test.java
@@ -16,6 +16,8 @@
package org.apache.rahas;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
@@ -30,13 +32,6 @@
byte[] clientEntr;
- /**
- * @param name
- */
- public RahasSAMLTokenUTForHoKV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_12);
diff --git a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
index 5ae0782..3fddd7f 100644
--- a/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
+++ b/modules/rampart-integration/src/test/java/org/apache/rahas/RahasSAMLTokenV1205Test.java
@@ -22,20 +22,14 @@
import org.apache.neethi.Policy;
import org.apache.ws.secpolicy.SP12Constants;
+import static org.junit.Assert.assertNotNull;
+
import javax.xml.namespace.QName;
/**
* RahasSAMLTokenTest with the WS-SX namespaces
*/
public class RahasSAMLTokenV1205Test extends TestClient {
-
- /**
- * @param name
- */
- public RahasSAMLTokenV1205Test(String name) {
- super(name);
- }
-
public OMElement getRequest() {
try {
OMElement rstElem = TrustUtil.createRequestSecurityTokenElement(RahasConstants.VERSION_05_12);
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 622a627..064d197 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
@@ -16,12 +16,10 @@
package org.apache.rampart;
-import static org.apache.axis2.integration.JettyServer.getHttpPort;
-import static org.apache.axis2.integration.JettyServer.getHttpsPort;
-import static org.apache.axis2.integration.JettyServer.CLIENT_KEYSTORE;
-import static org.apache.axis2.integration.JettyServer.KEYSTORE_PASSWORD;
+import static org.apache.axis2.integration.TestConstants.TESTING_PATH;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
@@ -30,7 +28,6 @@
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ConfigurationContext;
@@ -39,17 +36,21 @@
import org.apache.axis2.integration.JettyServer;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
+import org.junit.Rule;
+import org.junit.Test;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-
-public class RampartTest extends TestCase {
+public class RampartTest {
private static ResourceBundle resources;
- private String trustStore;
- private String trustStorePassword;
- private String trustStoreType;
+
+ @Rule
+ public final JettyServer server = new JettyServer(TESTING_PATH + "rampart_service_repo", false);
+
+ @Rule
+ public final JettyServer secureServer = new JettyServer(TESTING_PATH + "rampart_service_repo", true);
static {
try {
@@ -59,55 +60,9 @@
}
}
- public RampartTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- trustStore = System.getProperty("javax.net.ssl.trustStore");
- System.setProperty("javax.net.ssl.trustStore", CLIENT_KEYSTORE);
-
- trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
- System.setProperty("javax.net.ssl.trustStorePassword", KEYSTORE_PASSWORD);
-
- trustStoreType = System.getProperty("javax.net.ssl.trustStoreType");
- System.setProperty("javax.net.ssl.trustStoreType", "JKS");
-
- JettyServer.start(Constants.TESTING_PATH + "rampart_service_repo");
- }
-
-
- protected void tearDown() throws Exception {
- try {
- JettyServer.stop();
- }
- finally {
- if (trustStore != null) {
- System.setProperty("javax.net.ssl.trustStore", trustStore);
- }
- else {
- System.clearProperty("javax.net.ssl.trustStore");
- }
-
- if (trustStorePassword != null) {
- System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
- }
- else {
- System.clearProperty("javax.net.ssl.trustStorePassword");
- }
-
- if (trustStoreType != null) {
- System.setProperty("javax.net.ssl.trustStoreType", trustStoreType);
- }
- else {
- System.clearProperty("javax.net.ssl.trustStoreType");
- }
- }
- }
-
private ServiceClient getServiceClientInstance() throws AxisFault {
- String repository = Constants.TESTING_PATH + "rampart_client_repo";
+ String repository = TESTING_PATH + "rampart_client_repo";
ConfigurationContext configContext = ConfigurationContextFactory.
createConfigurationContextFromFileSystem(repository, null);
@@ -121,6 +76,7 @@
}
+ @Test
public void testWithPolicy() {
try {
@@ -148,17 +104,13 @@
Options options = new Options();
if( i == 13 ) {
- options.setTo(new EndpointReference("https://localhost:" +
- getHttpsPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(secureServer.getEndpointReference("SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
options.setPassword("password");
}
else {
- options.setTo(new EndpointReference("http://localhost:" +
- getHttpPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(server.getEndpointReference("SecureService" + i));
}
System.out.println("Testing WS-Sec: custom scenario " + i);
@@ -224,17 +176,13 @@
Options options = new Options();
if (i == 13) {
- options.setTo(new EndpointReference("https://localhost:" +
- getHttpsPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(secureServer.getEndpointReference("SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
options.setPassword("password");
}
else {
- options.setTo(new EndpointReference("http://localhost:" +
- getHttpPort() +
- "/axis2/services/SecureService" + i));
+ options.setTo(server.getEndpointReference("SecureService" + i));
}
System.out.println("Testing WS-Sec: negative scenario " + i);
options.setAction("urn:returnError");
@@ -259,10 +207,10 @@
Options options = new Options();
if (i == 3 || i == 6) {
- options.setTo(new EndpointReference("https://localhost:" + getHttpsPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(secureServer.getEndpointReference("SecureServiceSC" + i));
}
else {
- options.setTo(new EndpointReference("http://localhost:" + getHttpPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(server.getEndpointReference("SecureServiceSC" + i));
}
System.out.println("Testing WS-SecConv: custom scenario " + i);