Merge latest changes from trunk.
git-svn-id: https://svn.apache.org/repos/asf/axis/axis2/java/rampart/branches/RAMPART-433@1778802 13f79535-47bb-0310-9956-ffa450edef68
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..d3ec600 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
@@ -24,6 +24,7 @@
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.axis2.testutils.PortAllocator;
@@ -32,7 +33,7 @@
/**
* Support for running an embedded Jetty server
*/
-public class JettyServer {
+public class JettyServer extends ExternalResource {
/**
* Keystore to configure for Jetty's ssl context factory: {@value}
@@ -71,57 +72,41 @@
private static final Logger logger = LoggerFactory.getLogger(JettyServer.class);
- private static Server server;
-
- private JettyServer() {
-
- }
+ private final String repository;
+ private final int httpPort;
+ private final int httpsPort;
+ private Server server;
/**
- * 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
- */
- 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
+ * @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. Set to
+ * <code>0</code> to enable dynamic port allocation.
+ * @param httpsPort
+ * The https port to use. Set to <code>-1</code> to disable https connector. Set to
+ * <code>0</code> to enable dynamic port allocation.
* @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, int httpPort, int httpsPort) {
if (repository == null || repository.trim().length() == 0) {
throw new IllegalArgumentException("Axis2 repository must not be null or empty");
}
- else if (httpPort == -1 && httpsPort == -1) {
+ if (httpPort == -1 && httpsPort == -1) {
throw new IllegalArgumentException("At least one port must be specified.");
}
+ this.repository = repository;
+ this.httpPort = httpPort;
+ this.httpsPort = httpsPort;
+ }
+ @Override
+ protected void before() throws Throwable {
+ int httpPort = this.httpPort == 0 ? PortAllocator.allocatePort() : this.httpPort;
+ int httpsPort = this.httpsPort == 0 ? PortAllocator.allocatePort() : this.httpsPort;
+
server = new Server();
SelectChannelConnector connector = null;
@@ -196,15 +181,15 @@
}
}
- /**
- * 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();
+ try {
+ server.stop();
+ } catch (Exception ex) {
+ logger.error("Failed to stop Jetty server", ex);
+ }
server = null;
}
}
@@ -213,7 +198,7 @@
* @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 {
+ public int getHttpPort() throws IllegalStateException {
assertStarted();
Connector[] connectors = server.getConnectors();
@@ -236,7 +221,7 @@
* @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 {
+ public int getHttpsPort() throws IllegalStateException {
assertStarted();
Connector[] connectors = server.getConnectors();
@@ -254,7 +239,7 @@
throw new IllegalStateException("Could not find Jetty https connector");
}
- private static void assertStarted() throws IllegalStateException {
+ private void assertStarted() throws IllegalStateException {
if (server == null) {
throw new IllegalStateException("Jetty server is not initialized");
}
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..b6a686c 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
@@ -34,27 +34,19 @@
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 extends TestCase {
+public abstract class TestClient {
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(Constants.TESTING_PATH + getServiceRepo(), port, -1);
/**
*/
+ @Test
public void testRequest() throws Exception {
// Get the repository location from the args
String repo = Constants.TESTING_PATH + "rahas_client_repo";
diff --git a/modules/rampart-integration/src/main/java/org/apache/rampart/KerberosDelegationService.java b/modules/rampart-integration/src/main/java/org/apache/rampart/KerberosDelegationService.java
index e1dd204..ee010b0 100644
--- a/modules/rampart-integration/src/main/java/org/apache/rampart/KerberosDelegationService.java
+++ b/modules/rampart-integration/src/main/java/org/apache/rampart/KerberosDelegationService.java
@@ -3,6 +3,7 @@
import java.net.MalformedURLException;
import java.net.URL;
+import javax.servlet.http.HttpServletRequest;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
@@ -13,7 +14,7 @@
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.context.MessageContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.neethi.Policy;
import org.apache.rampart.policy.model.KerberosConfig;
@@ -26,9 +27,10 @@
public OMElement echo(OMElement elem) throws MalformedURLException, IllegalStateException, AxisFault {
+ int port = ((HttpServletRequest)MessageContext.getCurrentMessageContext().getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST)).getLocalPort();
final String serviceName = "KerberosOverTransportKeytab";
- URL wsdlUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", JettyServer.getHttpsPort(), serviceName));
+ URL wsdlUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", port, serviceName));
ConfigurationContext configContext = ConfigurationContextFactory.
createConfigurationContextFromFileSystem("target/test-resources/rampart_client_repo", null);
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/AbstractRampartTest.java b/modules/rampart-integration/src/test/java/org/apache/rampart/AbstractRampartTest.java
index 2b4e017..ece019c 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
@@ -23,8 +23,6 @@
import java.util.MissingResourceException;
import java.util.ResourceBundle;
-import junit.framework.TestCase;
-
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
@@ -37,12 +35,15 @@
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
/**
* Base test class for integration tests that require Axis2 web application running in a web container.
* The class uses Axis2 web application deployed via {@link JettyServer}.
*/
-public abstract class AbstractRampartTest extends TestCase {
+public abstract class AbstractRampartTest {
/**
* Default client connection timeout in milliseconds: {@value}
@@ -54,6 +55,11 @@
protected static final String RAMPART_SERVICE_REPO_PATH = "target/test-resources/rampart_service_repo";
protected static ResourceBundle resources;
+
+ @Rule
+ public final JettyServer server = new JettyServer(
+ RAMPART_SERVICE_REPO_PATH, isEnableHttp() ? 0 : -1, isEnableHttps() ? 0 : -1);
+
protected String trustStore;
protected String trustStorePassword;
protected String trustStoreType;
@@ -65,19 +71,9 @@
throw new RuntimeException(e.getMessage());
}
}
-
- public AbstractRampartTest() {
-
- }
- public AbstractRampartTest(String name) {
- super(name);
- }
-
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
trustStore = System.getProperty("javax.net.ssl.trustStore");
System.setProperty("javax.net.ssl.trustStore", CLIENT_KEYSTORE);
@@ -86,54 +82,31 @@
trustStoreType = System.getProperty("javax.net.ssl.trustStoreType");
System.setProperty("javax.net.ssl.trustStoreType", "JKS");
-
- JettyServer.start(RAMPART_SERVICE_REPO_PATH, isEnableHttp(), isEnableHttps());
}
- /* (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- try {
- JettyServer.stop();
+ @After
+ public void tearDown() throws Exception {
+ if (trustStore != null) {
+ System.setProperty("javax.net.ssl.trustStore", trustStore);
}
- 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");
- }
+ else {
+ System.clearProperty("javax.net.ssl.trustStore");
}
- }
-
- /**
- * @return Jetty http port, see {@link JettyServer#getHttpPort()}
- */
- protected int getHttpPort() {
- return JettyServer.getHttpPort();
- }
-
- /**
- * @return Jetty https port, see {@link JettyServer#getHttpsPort()}
- */
- protected int getHttpsPort() {
- return JettyServer.getHttpsPort();
+
+ 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");
+ }
}
protected ServiceClient getServiceClientInstance() throws AxisFault {
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 ff87fb4..2ee02a9 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
@@ -17,6 +17,9 @@
import org.apache.rampart.policy.model.RampartConfig;
import org.apache.rampart.util.KerberosServer;
import org.custommonkey.xmlunit.XMLAssert;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.xml.sax.SAXException;
/**
@@ -69,9 +72,10 @@
*/
protected String krb5Conf;
+ @Test
public void testKerberosOverTransportKeytab() throws XMLStreamException, SAXException, IOException {
final String serviceName = "KerberosOverTransportKeytab";
- URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", getHttpsPort(), serviceName));
+ URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", server.getHttpsPort(), serviceName));
ServiceClient serviceClient = getServiceClientInstance(serviceUrl);
@@ -95,9 +99,10 @@
XMLAssert.assertXMLEqual(echoElement.toStringWithConsume(), result.toStringWithConsume());
}
+ @Test
public void testKerberosOverTransportPWCB() throws XMLStreamException, SAXException, IOException {
final String serviceName = "KerberosOverTransportPWCB";
- URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", getHttpsPort(), serviceName));
+ URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", server.getHttpsPort(), serviceName));
ServiceClient serviceClient = getServiceClientInstance(serviceUrl);
@@ -123,10 +128,10 @@
XMLAssert.assertXMLEqual(echoElement.toStringWithConsume(), result.toStringWithConsume());
}
-
+ @Test
public void testKerberosDelegation() throws XMLStreamException, SAXException, IOException {
final String serviceName = "KerberosDelegation";
- URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", getHttpsPort(), serviceName));
+ URL serviceUrl = new URL(String.format("https://localhost:%s/axis2/services/%s?wsdl", server.getHttpsPort(), serviceName));
ServiceClient serviceClient = getServiceClientInstance(serviceUrl);
@@ -151,13 +156,8 @@
XMLAssert.assertXMLEqual(echoElement.toStringWithConsume(), result.toStringWithConsume());
}
- /* (non-Javadoc)
- * @see org.apache.rampart.AbstractRampartTest#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
+ @Before
+ public void setUpKerberos() throws Exception {
System.setProperty("sun.security.krb5.debug", "true");
System.setProperty("sun.security.jgss.debug", "true");
@@ -176,13 +176,8 @@
System.setProperty(JAAS_CONF_SYS_PROP, KERBEROS_JAAS_CONF);
}
- /* (non-Javadoc)
- * @see org.apache.rampart.AbstractRampartTest#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
-
+ @After
+ public void tearDownKerberos() throws Exception {
KerberosServer.stopKerberosServer();
if (jaasConf != null) {
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..cd0534e 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,11 @@
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.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;
@@ -39,14 +38,22 @@
import org.apache.axis2.integration.JettyServer;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
+import org.junit.After;
+import org.junit.Before;
+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;
+
+ @Rule
+ public final JettyServer server = new JettyServer(Constants.TESTING_PATH + "rampart_service_repo", 0, 0);
+
private String trustStore;
private String trustStorePassword;
private String trustStoreType;
@@ -59,11 +66,8 @@
}
}
- public RampartTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
trustStore = System.getProperty("javax.net.ssl.trustStore");
System.setProperty("javax.net.ssl.trustStore", CLIENT_KEYSTORE);
@@ -72,36 +76,30 @@
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();
+ @After
+ public void tearDown() throws Exception {
+ if (trustStore != null) {
+ System.setProperty("javax.net.ssl.trustStore", trustStore);
}
- 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");
- }
+ 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");
}
}
@@ -121,6 +119,7 @@
}
+ @Test
public void testWithPolicy() {
try {
@@ -149,7 +148,7 @@
if( i == 13 ) {
options.setTo(new EndpointReference("https://localhost:" +
- getHttpsPort() +
+ server.getHttpsPort() +
"/axis2/services/SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
@@ -157,7 +156,7 @@
}
else {
options.setTo(new EndpointReference("http://localhost:" +
- getHttpPort() +
+ server.getHttpPort() +
"/axis2/services/SecureService" + i));
}
@@ -225,7 +224,7 @@
if (i == 13) {
options.setTo(new EndpointReference("https://localhost:" +
- getHttpsPort() +
+ server.getHttpsPort() +
"/axis2/services/SecureService" + i));
//Username token created with user/pass from options
options.setUserName("alice");
@@ -233,7 +232,7 @@
}
else {
options.setTo(new EndpointReference("http://localhost:" +
- getHttpPort() +
+ server.getHttpPort() +
"/axis2/services/SecureService" + i));
}
System.out.println("Testing WS-Sec: negative scenario " + i);
@@ -259,10 +258,10 @@
Options options = new Options();
if (i == 3 || i == 6) {
- options.setTo(new EndpointReference("https://localhost:" + getHttpsPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(new EndpointReference("https://localhost:" + server.getHttpsPort() + "/axis2/services/SecureServiceSC" + i));
}
else {
- options.setTo(new EndpointReference("http://localhost:" + getHttpPort() + "/axis2/services/SecureServiceSC" + i));
+ options.setTo(new EndpointReference("http://localhost:" + server.getHttpPort() + "/axis2/services/SecureServiceSC" + i));
}
System.out.println("Testing WS-SecConv: custom scenario " + i);
diff --git a/pom.xml b/pom.xml
index bb52e99..4f49a17 100644
--- a/pom.xml
+++ b/pom.xml
@@ -547,7 +547,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>3.8.2</version>
+ <version>4.12</version>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
@@ -616,7 +616,7 @@
<axis2.version>1.8.0-SNAPSHOT</axis2.version>
<axiom.version>1.3.0-SNAPSHOT</axiom.version>
- <wss4j.version>1.6.17</wss4j.version>
+ <wss4j.version>1.6.19</wss4j.version>
<opensaml.version>2.5.1-1</opensaml.version>
<bcprov.jdk15.version>1.49</bcprov.jdk15.version>