This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git
The following commit(s) were added to refs/heads/master by this push:
new 07e169c fediz-systests-tomcat: extract TomcatLauncher (#43)
07e169c is described below
commit 07e169c00d5e22518dc32a9f7bd9c91cb69adfca
Author: Alexey Markevich <[email protected]>
AuthorDate: Thu May 16 15:07:54 2019 +0300
fediz-systests-tomcat: extract TomcatLauncher (#43)
* fediz-systests-tomcat: extract TomcatLauncher
* cleanup
---
pom.xml | 5 +-
.../cxf/fediz/systests/common/AbstractTests.java | 18 +--
systests/tomcat/pom.xml | 61 +++-------
.../systests/tomcat/AudienceRestrictionTest.java | 132 ++------------------
.../systests/tomcat/ClientCertificateTest.java | 116 ++----------------
.../cxf/fediz/systests/tomcat/HolderOfKeyTest.java | 134 ++------------------
.../cxf/fediz/systests/tomcat/TokenExpiryTest.java | 117 ++----------------
.../cxf/fediz/systests/tomcat/TomcatLauncher.java | 135 +++++++++++++++++++++
.../cxf/fediz/systests/tomcat/TomcatTest.java | 117 ++----------------
.../apache/cxf/fediz/systests/tomcat/WReqTest.java | 132 ++------------------
systests/tomcat/src/test/resources/alice.cer | Bin 873 -> 0 bytes
11 files changed, 228 insertions(+), 739 deletions(-)
diff --git a/pom.xml b/pom.xml
index 1e5230b..cba4170 100644
--- a/pom.xml
+++ b/pom.xml
@@ -359,10 +359,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
- <version>3.0.2</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
+ <version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
diff --git
a/systests/tests/src/test/java/org/apache/cxf/fediz/systests/common/AbstractTests.java
b/systests/tests/src/test/java/org/apache/cxf/fediz/systests/common/AbstractTests.java
index df7b7c6..5880438 100644
---
a/systests/tests/src/test/java/org/apache/cxf/fediz/systests/common/AbstractTests.java
+++
b/systests/tests/src/test/java/org/apache/cxf/fediz/systests/common/AbstractTests.java
@@ -20,12 +20,12 @@
package org.apache.cxf.fediz.systests.common;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
-import java.util.Scanner;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -759,9 +759,7 @@ public abstract class AbstractTests {
// Parse the form to get the token (wresult)
DomNodeList<DomElement> results =
idpPage.getElementsByTagName("input");
- Scanner s =
- new
Scanner(this.getClass().getClassLoader().getResource("entity.xml").openStream()).useDelimiter("\\A");
- String entity = s.next();
+ String entity = getResourceAsString("/entity.xml");
String reference = "&m;";
for (DomElement result : results) {
@@ -833,9 +831,7 @@ public abstract class AbstractTests {
// Parse the form to get the token (wresult)
DomNodeList<DomElement> results =
idpPage.getElementsByTagName("input");
- Scanner s =
- new
Scanner(this.getClass().getClassLoader().getResource("entity2.xml").openStream()).useDelimiter("\\A");
- String entity = s.next();
+ String entity = getResourceAsString("/entity2.xml");
String reference = "&m;";
for (DomElement result : results) {
@@ -1026,4 +1022,12 @@ public abstract class AbstractTests {
}
+ private static String getResourceAsString(String location) throws
IOException {
+ try (InputStream is =
AbstractTests.class.getResourceAsStream(location)) {
+ byte[] content = new byte[is.available()];
+ is.read(content);
+ return new String(content);
+ }
+ }
+
}
diff --git a/systests/tomcat/pom.xml b/systests/tomcat/pom.xml
index 91da055..8082171 100644
--- a/systests/tomcat/pom.xml
+++ b/systests/tomcat/pom.xml
@@ -26,13 +26,9 @@
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.apache.cxf.fediz.systests</groupId>
- <artifactId>fediz-systests-tomcat8</artifactId>
- <name>Apache Fediz Systests Tomcat 8</name>
- <packaging>jar</packaging>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- </properties>
+ <artifactId>fediz-systests-tomcat</artifactId>
+ <name>Apache Fediz Systests Tomcat</name>
+
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
@@ -62,9 +58,8 @@
<groupId>org.apache.cxf.fediz.systests</groupId>
<artifactId>fediz-systests-tests</artifactId>
<version>${project.version}</version>
- <type>test-jar</type>
- <scope>test</scope>
<classifier>tests</classifier>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -80,22 +75,6 @@
</dependency>
</dependencies>
<build>
- <testResources>
- <testResource>
- <directory>src/test/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/fediz_config*.xml</include>
- </includes>
- </testResource>
- <testResource>
- <directory>src/test/resources</directory>
- <filtering>false</filtering>
- <excludes>
- <exclude>**/fediz_config*.xml</exclude>
- </excludes>
- </testResource>
- </testResources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@@ -134,7 +113,7 @@
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
-
<outputDirectory>target/tomcat/idp/webapps/fediz-idp</outputDirectory>
+
<outputDirectory>${project.build.directory}/tomcat/idp/webapps/fediz-idp</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.apache.cxf.fediz</groupId>
@@ -142,7 +121,7 @@
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
-
<outputDirectory>target/tomcat/idp/webapps/fediz-idp-sts</outputDirectory>
+
<outputDirectory>${project.build.directory}/tomcat/idp/webapps/fediz-idp-sts</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.apache.cxf.fediz.systests.webapps</groupId>
@@ -150,7 +129,7 @@
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
-
<outputDirectory>target/tomcat/rp/webapps/simpleWebapp</outputDirectory>
+
<outputDirectory>${project.build.directory}/tomcat/rp/webapps/simpleWebapp</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>org.apache.cxf.fediz.systests</groupId>
@@ -159,7 +138,7 @@
<classifier>tests</classifier>
<type>jar</type>
<overWrite>true</overWrite>
-
<outputDirectory>target/test-classes</outputDirectory>
+
<outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
<includes>**/*.jks</includes>
</artifactItem>
</artifactItems>
@@ -176,13 +155,13 @@
<executions>
<execution>
<id>copy-entities-to-idp</id>
- <phase>generate-test-sources</phase>
+ <phase>generate-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
-
<outputDirectory>${basedir}/target/tomcat/idp/webapps/fediz-idp/WEB-INF/classes</outputDirectory>
- <resources>
+
<outputDirectory>${project.build.directory}/tomcat/idp/webapps/fediz-idp/WEB-INF/classes</outputDirectory>
+ <resources>
<resource>
<directory>${basedir}/src/test/resources/realma</directory>
<includes>
@@ -190,18 +169,18 @@
</includes>
<filtering>true</filtering>
</resource>
- </resources>
- </configuration>
+ </resources>
+ </configuration>
</execution>
<execution>
<id>copy-customised-sts-config</id>
- <phase>generate-test-sources</phase>
+ <phase>generate-test-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
-
<outputDirectory>${basedir}/target/tomcat/idp/webapps/fediz-idp-sts/WEB-INF</outputDirectory>
- <resources>
+
<outputDirectory>${project.build.directory}/tomcat/idp/webapps/fediz-idp-sts/WEB-INF</outputDirectory>
+ <resources>
<resource>
<directory>${basedir}/src/test/resources/realma</directory>
<includes>
@@ -209,9 +188,9 @@
</includes>
<filtering>false</filtering>
</resource>
- </resources>
- <overwrite>true</overwrite>
- </configuration>
+ </resources>
+ <overwrite>true</overwrite>
+ </configuration>
</execution>
</executions>
</plugin>
@@ -231,7 +210,7 @@
<wt.headless>true</wt.headless>
<idp.https.port>${idp.https.port}</idp.https.port>
<rp.https.port>${rp.https.port}</rp.https.port>
-
<java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file>
+
<java.util.logging.config.file>${project.build.testOutputDirectory}/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
<includes>
<include>**/systests/**</include>
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/AudienceRestrictionTest.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/AudienceRestrictionTest.java
index a5bbcdf..64b9006 100644
---
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/AudienceRestrictionTest.java
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/AudienceRestrictionTest.java
@@ -20,11 +20,11 @@
package org.apache.cxf.fediz.systests.tomcat;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-
-import javax.servlet.ServletException;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -32,142 +32,34 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
/**
* A test to make sure that audience restriction validation is working
correctly in the plugin.
*/
public class AudienceRestrictionTest {
- static String idpHttpsPort;
- static String rpHttpsPort;
-
- private static Tomcat idpServer;
- private static Tomcat rpServer;
+ private static final String SERVLET_CONTEXT_NAME =
"fedizhelloworld_audrestr";
@BeforeClass
public static void init() throws Exception {
- idpHttpsPort = System.getProperty("idp.https.port");
- Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
- rpHttpsPort = System.getProperty("rp.https.port");
- Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
- idpServer = startServer(true, idpHttpsPort);
- rpServer = startServer(false, rpHttpsPort);
- }
-
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
- Tomcat server = new Tomcat();
- server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
-
- if (idp) {
- server.getHost().setAppBase("tomcat/idp/webapps");
- } else {
- server.getHost().setAppBase("tomcat/rp/webapps");
- }
- server.getHost().setAutoDeploy(true);
- server.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(port));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setAttribute("keyAlias", "mytomidpkey");
- httpsConnector.setAttribute("keystorePass", "tompass");
- httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
- httpsConnector.setAttribute("truststorePass", "tompass");
- httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
- httpsConnector.setAttribute("clientAuth", "want");
- // httpsConnector.setAttribute("clientAuth", "false");
- httpsConnector.setAttribute("sslProtocol", "TLS");
- httpsConnector.setAttribute("SSLEnabled", true);
-
- server.getService().addConnector(httpsConnector);
-
- if (idp) {
- File stsWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
- File idpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
- } else {
- File rpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "simpleWebapp");
- Context cxt = server.addWebapp("/fedizhelloworld_audrestr",
rpWebapp.getAbsolutePath());
-
- // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
- // to work
- File f = new File(currentDir +
"/src/test/resources/fediz_config.xml");
- String content = new String(Files.readAllBytes(f.toPath()),
"UTF-8");
- if (content.contains("idp.https.port")) {
- content = content.replaceAll("\\$\\{idp.https.port\\}", "" +
idpHttpsPort);
-
- File f2 = new File(baseDir + "/test-classes/fediz_config.xml");
- Files.write(f2.toPath(), content.getBytes());
- }
-
- FederationAuthenticator fa = new FederationAuthenticator();
- fa.setConfigFile(currentDir + File.separator + "target" +
File.separator
- + "test-classes" + File.separator +
"fediz_config.xml");
- cxt.getPipeline().addValve(fa);
- }
-
- server.start();
-
- return server;
+ TomcatLauncher.startServer(SERVLET_CONTEXT_NAME);
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
- }
-
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public String getIdpHttpsPort() {
- return idpHttpsPort;
- }
-
- public String getRpHttpsPort() {
- return rpHttpsPort;
+ public static void cleanup() throws Exception {
+ TomcatLauncher.shutdownServer();
}
@org.junit.Test
public void testSAMLTokenWithNonMatchingAudienceRestriction() throws
Exception {
- String url = "https://localhost:" + getRpHttpsPort() +
"/fedizhelloworld_audrestr/secure/fedservlet";
+ String url = "https://localhost:" + TomcatLauncher.getRpHttpsPort() +
'/' + SERVLET_CONTEXT_NAME
+ + "/secure/fedservlet";
String user = "alice";
String password = "ecila";
final WebClient webClient = new WebClient();
webClient.getOptions().setUseInsecureSSL(true);
webClient.getCredentialsProvider().setCredentials(
- new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())),
+ new AuthScope("localhost",
Integer.parseInt(TomcatLauncher.getIdpHttpsPort())),
new UsernamePasswordCredentials(user, password));
webClient.getOptions().setJavaScriptEnabled(false);
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/ClientCertificateTest.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/ClientCertificateTest.java
index 86c75a9..2419ea6 100644
---
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/ClientCertificateTest.java
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/ClientCertificateTest.java
@@ -19,21 +19,8 @@
package org.apache.cxf.fediz.systests.tomcat;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-
-import javax.servlet.ServletException;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
import org.apache.cxf.fediz.systests.common.AbstractClientCertTests;
-import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.BeforeClass;
/**
@@ -42,117 +29,28 @@ import org.junit.BeforeClass;
*/
public class ClientCertificateTest extends AbstractClientCertTests {
- static String idpHttpsPort;
- static String rpHttpsPort;
-
- private static Tomcat idpServer;
- private static Tomcat rpServer;
+ private static final String SERVLET_CONTEXT_NAME =
"fedizhelloworld_client_cert";
@BeforeClass
public static void init() throws Exception {
- idpHttpsPort = System.getProperty("idp.https.port");
- Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
- rpHttpsPort = System.getProperty("rp.https.port");
- Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
- idpServer = startServer(true, idpHttpsPort);
- rpServer = startServer(false, rpHttpsPort);
- }
-
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
- Tomcat server = new Tomcat();
- server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
-
- if (idp) {
- server.getHost().setAppBase("tomcat/idp/webapps");
- } else {
- server.getHost().setAppBase("tomcat/rp/webapps");
- }
- server.getHost().setAutoDeploy(true);
- server.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(port));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setAttribute("keyAlias", "mytomidpkey");
- httpsConnector.setAttribute("keystorePass", "tompass");
- httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
- httpsConnector.setAttribute("truststorePass", "tompass");
- httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
- httpsConnector.setAttribute("clientAuth", "want");
- // httpsConnector.setAttribute("clientAuth", "false");
- httpsConnector.setAttribute("sslProtocol", "TLS");
- httpsConnector.setAttribute("SSLEnabled", true);
-
- server.getService().addConnector(httpsConnector);
-
- if (idp) {
- File stsWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
- File idpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
- } else {
- File rpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "simpleWebapp");
- Context cxt = server.addWebapp("/fedizhelloworld_client_cert",
rpWebapp.getAbsolutePath());
-
- // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
- // to work
- File f = new File(currentDir +
"/src/test/resources/fediz_config.xml");
- String content = new String(Files.readAllBytes(f.toPath()),
"UTF-8");
- if (content.contains("idp.https.port")) {
- content = content.replaceAll("\\$\\{idp.https.port\\}", "" +
idpHttpsPort);
-
- File f2 = new File(baseDir + "/test-classes/fediz_config.xml");
- Files.write(f2.toPath(), content.getBytes());
- }
-
- FederationAuthenticator fa = new FederationAuthenticator();
- fa.setConfigFile(currentDir + File.separator + "target" +
File.separator
- + "test-classes" + File.separator +
"fediz_config.xml");
- cxt.getPipeline().addValve(fa);
- }
-
- server.start();
-
- return server;
+ TomcatLauncher.startServer(SERVLET_CONTEXT_NAME);
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
- }
-
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public static void cleanup() throws Exception {
+ TomcatLauncher.shutdownServer();
}
public String getIdpHttpsPort() {
- return idpHttpsPort;
+ return TomcatLauncher.getIdpHttpsPort();
}
public String getRpHttpsPort() {
- return rpHttpsPort;
+ return TomcatLauncher.getRpHttpsPort();
}
public String getServletContextName() {
- return "fedizhelloworld_client_cert";
+ return SERVLET_CONTEXT_NAME;
}
}
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/HolderOfKeyTest.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/HolderOfKeyTest.java
index 5b339b3..8870a6a 100644
---
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/HolderOfKeyTest.java
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/HolderOfKeyTest.java
@@ -19,11 +19,12 @@
package org.apache.cxf.fediz.systests.tomcat;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-
-import javax.servlet.ServletException;
+import org.apache.cxf.fediz.core.ClaimTypes;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
@@ -32,137 +33,28 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.cxf.fediz.core.ClaimTypes;
-import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
/**
* A test for sending a "PublicKey" KeyType request to the IdP via the "wreq"
parameter. This
* will cause the IdP/STS to issue a "HolderOfKey" SAML Assertion.
*/
public class HolderOfKeyTest {
- static String idpHttpsPort;
- static String rpHttpsPort;
-
- private static Tomcat idpServer;
- private static Tomcat rpServer;
+ private static final String SERVLET_CONTEXT_NAME = "fedizhelloworld_hok";
@BeforeClass
public static void init() throws Exception {
- idpHttpsPort = System.getProperty("idp.https.port");
- Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
- rpHttpsPort = System.getProperty("rp.https.port");
- Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
- idpServer = startServer(true, idpHttpsPort);
- rpServer = startServer(false, rpHttpsPort);
- }
-
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
- Tomcat server = new Tomcat();
- server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
-
- if (idp) {
- server.getHost().setAppBase("tomcat/idp/webapps");
- } else {
- server.getHost().setAppBase("tomcat/rp/webapps");
- }
- server.getHost().setAutoDeploy(true);
- server.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(port));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setAttribute("keyAlias", "mytomidpkey");
- httpsConnector.setAttribute("keystorePass", "tompass");
- httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
- httpsConnector.setAttribute("truststorePass", "tompass");
- httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
- httpsConnector.setAttribute("clientAuth", "want");
- // httpsConnector.setAttribute("clientAuth", "false");
- httpsConnector.setAttribute("sslProtocol", "TLS");
- httpsConnector.setAttribute("SSLEnabled", true);
-
- server.getService().addConnector(httpsConnector);
-
- if (idp) {
- File stsWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
- File idpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
- } else {
- File rpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "simpleWebapp");
- Context cxt = server.addWebapp("/fedizhelloworld_hok",
rpWebapp.getAbsolutePath());
-
- // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
- // to work
- File f = new File(currentDir +
"/src/test/resources/fediz_config.xml");
- String content = new String(Files.readAllBytes(f.toPath()),
"UTF-8");
- if (content.contains("idp.https.port")) {
- content = content.replaceAll("\\$\\{idp.https.port\\}", "" +
idpHttpsPort);
-
- File f2 = new File(baseDir + "/test-classes/fediz_config.xml");
- Files.write(f2.toPath(), content.getBytes());
- }
-
- FederationAuthenticator fa = new FederationAuthenticator();
- fa.setConfigFile(currentDir + File.separator + "target" +
File.separator
- + "test-classes" + File.separator +
"fediz_config.xml");
- cxt.getPipeline().addValve(fa);
- }
-
- server.start();
-
- return server;
+ TomcatLauncher.startServer(SERVLET_CONTEXT_NAME);
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
- }
-
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public String getIdpHttpsPort() {
- return idpHttpsPort;
- }
-
- public String getRpHttpsPort() {
- return rpHttpsPort;
+ public static void cleanup() throws Exception {
+ TomcatLauncher.shutdownServer();
}
@org.junit.Test
public void testHolderOfKey() throws Exception {
- String url = "https://localhost:" + getRpHttpsPort() +
"/fedizhelloworld_hok/secure/fedservlet";
+ String url = "https://localhost:" + TomcatLauncher.getRpHttpsPort() +
'/' + SERVLET_CONTEXT_NAME
+ + "/secure/fedservlet";
String user = "alice";
String password = "ecila";
@@ -171,7 +63,7 @@ public class HolderOfKeyTest {
webClient.getOptions().setSSLClientCertificate(
this.getClass().getClassLoader().getResource("client.jks"),
"storepass", "jks");
webClient.getCredentialsProvider().setCredentials(
- new AuthScope("localhost", Integer.parseInt(getIdpHttpsPort())),
+ new AuthScope("localhost",
Integer.parseInt(TomcatLauncher.getIdpHttpsPort())),
new UsernamePasswordCredentials(user, password));
webClient.getOptions().setJavaScriptEnabled(false);
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TokenExpiryTest.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TokenExpiryTest.java
index a6d5016..1274159 100644
---
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TokenExpiryTest.java
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TokenExpiryTest.java
@@ -20,21 +20,8 @@
package org.apache.cxf.fediz.systests.tomcat;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-
-import javax.servlet.ServletException;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
import org.apache.cxf.fediz.systests.common.AbstractExpiryTests;
-import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
import org.junit.AfterClass;
-import org.junit.Assert;
import org.junit.BeforeClass;
/**
@@ -42,117 +29,29 @@ import org.junit.BeforeClass;
*/
public class TokenExpiryTest extends AbstractExpiryTests {
- static String idpHttpsPort;
- static String rpHttpsPort;
-
- private static Tomcat idpServer;
- private static Tomcat rpServer;
+ private static final String SERVLET_CONTEXT_NAME =
"fedizhelloworld_wfresh";
@BeforeClass
public static void init() throws Exception {
- idpHttpsPort = System.getProperty("idp.https.port");
- Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
- rpHttpsPort = System.getProperty("rp.https.port");
- Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
- idpServer = startServer(true, idpHttpsPort);
- rpServer = startServer(false, rpHttpsPort);
- }
-
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
- Tomcat server = new Tomcat();
- server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
-
- if (idp) {
- server.getHost().setAppBase("tomcat/idp/webapps");
- } else {
- server.getHost().setAppBase("tomcat/rp/webapps");
- }
- server.getHost().setAutoDeploy(true);
- server.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(port));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setAttribute("keyAlias", "mytomidpkey");
- httpsConnector.setAttribute("keystorePass", "tompass");
- httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
- httpsConnector.setAttribute("truststorePass", "tompass");
- httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
- httpsConnector.setAttribute("clientAuth", "want");
- // httpsConnector.setAttribute("clientAuth", "false");
- httpsConnector.setAttribute("sslProtocol", "TLS");
- httpsConnector.setAttribute("SSLEnabled", true);
-
- server.getService().addConnector(httpsConnector);
-
- if (idp) {
- File stsWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
- File idpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
- } else {
- File rpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "simpleWebapp");
- Context cxt = server.addWebapp("/fedizhelloworld_wfresh",
rpWebapp.getAbsolutePath());
-
- // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
- // to work
- File f = new File(currentDir +
"/src/test/resources/fediz_config.xml");
- String content = new String(Files.readAllBytes(f.toPath()),
"UTF-8");
- if (content.contains("idp.https.port")) {
- content = content.replaceAll("\\$\\{idp.https.port\\}", "" +
idpHttpsPort);
-
- File f2 = new File(baseDir +
"/test-classes/fediz_config_exp.xml");
- Files.write(f2.toPath(), content.getBytes());
- }
-
- FederationAuthenticator fa = new FederationAuthenticator();
- fa.setConfigFile(currentDir + File.separator + "target" +
File.separator
- + "test-classes" + File.separator +
"fediz_config_exp.xml");
- cxt.getPipeline().addValve(fa);
- }
-
- server.start();
-
- return server;
+ TomcatLauncher.startServer(SERVLET_CONTEXT_NAME);
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
- }
-
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public static void cleanup() throws Exception {
+ TomcatLauncher.shutdownServer();
}
public String getIdpHttpsPort() {
- return idpHttpsPort;
+ return TomcatLauncher.getIdpHttpsPort();
}
public String getRpHttpsPort() {
- return rpHttpsPort;
+ return TomcatLauncher.getRpHttpsPort();
}
@Override
public String getServletContextName() {
- return "fedizhelloworld_wfresh";
+ return SERVLET_CONTEXT_NAME;
}
+
}
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatLauncher.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatLauncher.java
new file mode 100644
index 0000000..465e5b6
--- /dev/null
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatLauncher.java
@@ -0,0 +1,135 @@
+/**
+ * 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.cxf.fediz.systests.tomcat;
+
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import javax.servlet.ServletException;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.LifecycleState;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.startup.Tomcat;
+import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
+
+public class TomcatLauncher {
+
+ private static final String idpHttpsPort =
System.getProperty("idp.https.port");
+ private static final String rpHttpsPort =
System.getProperty("rp.https.port");
+
+ private static Tomcat idpServer;
+ private static Tomcat rpServer;
+
+ public static void startServer(String servletContextName) throws Exception
{
+ assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
+ assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
+
+ idpServer = startServer(idpHttpsPort, null);
+ rpServer = startServer(rpHttpsPort, servletContextName);
+ }
+
+ private static Tomcat startServer(String port, String servletContextName)
+ throws ServletException, LifecycleException, IOException {
+ Tomcat server = new Tomcat();
+ server.setPort(0);
+ Path targetDir = Paths.get("target").toAbsolutePath();
+ server.setBaseDir(targetDir.toString());
+
+ server.getHost().setAutoDeploy(true);
+ server.getHost().setDeployOnStartup(true);
+
+ Connector httpsConnector = new Connector();
+ httpsConnector.setPort(Integer.parseInt(port));
+ httpsConnector.setSecure(true);
+ httpsConnector.setScheme("https");
+ httpsConnector.setAttribute("sslProtocol", "TLS");
+ httpsConnector.setAttribute("SSLEnabled", true);
+ httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
+ httpsConnector.setAttribute("keystorePass", "tompass");
+ httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
+ httpsConnector.setAttribute("truststorePass", "tompass");
+ httpsConnector.setAttribute("clientAuth", "want");
+ server.getService().addConnector(httpsConnector);
+
+ if (null == servletContextName) { // IDP
+ server.getHost().setAppBase("tomcat/idp/webapps");
+
+ Path stsWebapp =
targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp-sts");
+ server.addWebapp("/fediz-idp-sts", stsWebapp.toString());
+
+ Path idpWebapp =
targetDir.resolve(server.getHost().getAppBase()).resolve("fediz-idp");
+ server.addWebapp("/fediz-idp", idpWebapp.toString());
+ } else { // RP
+ server.getHost().setAppBase("tomcat/rp/webapps");
+
+ Path rpWebapp =
targetDir.resolve(server.getHost().getAppBase()).resolve("simpleWebapp");
+ Context cxt = server.addWebapp(servletContextName,
rpWebapp.toString());
+
+ // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
+ // to work
+ Path fedizConfig =
targetDir.resolve("tomcat").resolve("fediz_config.xml");
+ try (InputStream is =
TomcatLauncher.class.getResourceAsStream("/fediz_config.xml")) {
+ byte[] content = new byte[is.available()];
+ is.read(content);
+ Files.write(fedizConfig, new
String(content).replace("${idp.https.port}", idpHttpsPort).getBytes());
+ }
+
+ FederationAuthenticator fa = new FederationAuthenticator();
+ fa.setConfigFile(fedizConfig.toString());
+ cxt.getPipeline().addValve(fa);
+ }
+
+ server.start();
+
+ return server;
+ }
+
+ public static void shutdownServer() throws Exception {
+ shutdownServer(idpServer);
+ shutdownServer(rpServer);
+ }
+
+ private static void shutdownServer(Tomcat server) throws
LifecycleException {
+ if (server != null && server.getServer() != null
+ && server.getServer().getState() != LifecycleState.DESTROYED) {
+ if (server.getServer().getState() != LifecycleState.STOPPED) {
+ server.stop();
+ }
+ server.destroy();
+ }
+ }
+
+ public static String getIdpHttpsPort() {
+ return idpHttpsPort;
+ }
+
+ public static String getRpHttpsPort() {
+ return rpHttpsPort;
+ }
+
+}
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatTest.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatTest.java
index 4195717..26bd641 100644
---
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatTest.java
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/TomcatTest.java
@@ -20,19 +20,7 @@
package org.apache.cxf.fediz.systests.tomcat;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-
-import javax.servlet.ServletException;
-
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
import org.apache.cxf.fediz.systests.common.AbstractTests;
-import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.junit.AfterClass;
@@ -51,122 +39,33 @@ import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
public class TomcatTest extends AbstractTests {
- static String idpHttpsPort;
- static String rpHttpsPort;
-
- private static Tomcat idpServer;
- private static Tomcat rpServer;
+ private static final String SERVLET_CONTEXT_NAME = "fedizhelloworld";
@BeforeClass
public static void init() throws Exception {
- idpHttpsPort = System.getProperty("idp.https.port");
- Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
- rpHttpsPort = System.getProperty("rp.https.port");
- Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
- idpServer = startServer(true, idpHttpsPort);
- rpServer = startServer(false, rpHttpsPort);
- }
-
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
- Tomcat server = new Tomcat();
- server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
-
- if (idp) {
- server.getHost().setAppBase("tomcat/idp/webapps");
- } else {
- server.getHost().setAppBase("tomcat/rp/webapps");
- }
- server.getHost().setAutoDeploy(true);
- server.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(port));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setAttribute("keyAlias", "mytomidpkey");
- httpsConnector.setAttribute("keystorePass", "tompass");
- httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
- httpsConnector.setAttribute("truststorePass", "tompass");
- httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
- httpsConnector.setAttribute("clientAuth", "want");
- // httpsConnector.setAttribute("clientAuth", "false");
- httpsConnector.setAttribute("sslProtocol", "TLS");
- httpsConnector.setAttribute("SSLEnabled", true);
-
- server.getService().addConnector(httpsConnector);
-
- if (idp) {
- File stsWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
- File idpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
- } else {
- File rpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "simpleWebapp");
- Context cxt = server.addWebapp("/fedizhelloworld",
rpWebapp.getAbsolutePath());
-
- // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
- // to work
- File f = new File(currentDir +
"/src/test/resources/fediz_config.xml");
- String content = new String(Files.readAllBytes(f.toPath()),
"UTF-8");
- if (content.contains("idp.https.port")) {
- content = content.replaceAll("\\$\\{idp.https.port\\}", "" +
idpHttpsPort);
-
- File f2 = new File(baseDir + "/test-classes/fediz_config.xml");
- Files.write(f2.toPath(), content.getBytes());
- }
-
- FederationAuthenticator fa = new FederationAuthenticator();
- fa.setConfigFile(currentDir + File.separator + "target" +
File.separator
- + "test-classes" + File.separator +
"fediz_config.xml");
- cxt.getPipeline().addValve(fa);
- }
-
- server.start();
-
- return server;
+ TomcatLauncher.startServer(SERVLET_CONTEXT_NAME);
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
- }
-
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
+ public static void cleanup() throws Exception {
+ TomcatLauncher.shutdownServer();
}
@Override
public String getIdpHttpsPort() {
- return idpHttpsPort;
+ return TomcatLauncher.getIdpHttpsPort();
}
@Override
public String getRpHttpsPort() {
- return rpHttpsPort;
+ return TomcatLauncher.getRpHttpsPort();
}
@Override
public String getServletContextName() {
- return "fedizhelloworld";
+ return SERVLET_CONTEXT_NAME;
}
-
+
@Test
public void testAliceModifiedContext() throws Exception {
diff --git
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/WReqTest.java
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/WReqTest.java
index 4b2a07e..3d26f45 100644
---
a/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/WReqTest.java
+++
b/systests/tomcat/src/test/java/org/apache/cxf/fediz/systests/tomcat/WReqTest.java
@@ -20,11 +20,14 @@
package org.apache.cxf.fediz.systests.tomcat;
-import java.io.File;
import java.io.IOException;
-import java.nio.file.Files;
-import javax.servlet.ServletException;
+import org.apache.cxf.fediz.core.ClaimTypes;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomElement;
@@ -33,140 +36,31 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleState;
-import org.apache.catalina.connector.Connector;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.cxf.fediz.core.ClaimTypes;
-import org.apache.cxf.fediz.tomcat.FederationAuthenticator;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
/**
* A test for sending a TokenType request to the IdP via the "wreq" parameter.
*/
public class WReqTest {
- static String idpHttpsPort;
- static String rpHttpsPort;
-
- private static Tomcat idpServer;
- private static Tomcat rpServer;
+ private static final String SERVLET_CONTEXT_NAME = "fedizhelloworld_wreq";
@BeforeClass
public static void init() throws Exception {
- idpHttpsPort = System.getProperty("idp.https.port");
- Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
- rpHttpsPort = System.getProperty("rp.https.port");
- Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);
-
- idpServer = startServer(true, idpHttpsPort);
- rpServer = startServer(false, rpHttpsPort);
- }
-
- private static Tomcat startServer(boolean idp, String port)
- throws ServletException, LifecycleException, IOException {
- Tomcat server = new Tomcat();
- server.setPort(0);
- String currentDir = new File(".").getCanonicalPath();
- String baseDir = currentDir + File.separator + "target";
- server.setBaseDir(baseDir);
-
- if (idp) {
- server.getHost().setAppBase("tomcat/idp/webapps");
- } else {
- server.getHost().setAppBase("tomcat/rp/webapps");
- }
- server.getHost().setAutoDeploy(true);
- server.getHost().setDeployOnStartup(true);
-
- Connector httpsConnector = new Connector();
- httpsConnector.setPort(Integer.parseInt(port));
- httpsConnector.setSecure(true);
- httpsConnector.setScheme("https");
- httpsConnector.setAttribute("keyAlias", "mytomidpkey");
- httpsConnector.setAttribute("keystorePass", "tompass");
- httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
- httpsConnector.setAttribute("truststorePass", "tompass");
- httpsConnector.setAttribute("truststoreFile",
"test-classes/server.jks");
- httpsConnector.setAttribute("clientAuth", "want");
- // httpsConnector.setAttribute("clientAuth", "false");
- httpsConnector.setAttribute("sslProtocol", "TLS");
- httpsConnector.setAttribute("SSLEnabled", true);
-
- server.getService().addConnector(httpsConnector);
-
- if (idp) {
- File stsWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp-sts");
- server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());
-
- File idpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "fediz-idp");
- server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
- } else {
- File rpWebapp = new File(baseDir + File.separator +
server.getHost().getAppBase(), "simpleWebapp");
- Context cxt = server.addWebapp("/fedizhelloworld_wreq",
rpWebapp.getAbsolutePath());
-
- // Substitute the IDP port. Necessary if running the test in
eclipse where port filtering doesn't seem
- // to work
- File f = new File(currentDir +
"/src/test/resources/fediz_config.xml");
- String content = new String(Files.readAllBytes(f.toPath()),
"UTF-8");
- if (content.contains("idp.https.port")) {
- content = content.replaceAll("\\$\\{idp.https.port\\}", "" +
idpHttpsPort);
-
- File f2 = new File(baseDir + "/test-classes/fediz_config.xml");
- Files.write(f2.toPath(), content.getBytes());
- }
-
- FederationAuthenticator fa = new FederationAuthenticator();
- fa.setConfigFile(currentDir + File.separator + "target" +
File.separator
- + "test-classes" + File.separator +
"fediz_config.xml");
- cxt.getPipeline().addValve(fa);
- }
-
- server.start();
-
- return server;
+ TomcatLauncher.startServer(SERVLET_CONTEXT_NAME);
}
@AfterClass
- public static void cleanup() {
- shutdownServer(idpServer);
- shutdownServer(rpServer);
- }
-
- private static void shutdownServer(Tomcat server) {
- try {
- if (server != null && server.getServer() != null
- && server.getServer().getState() != LifecycleState.DESTROYED) {
- if (server.getServer().getState() != LifecycleState.STOPPED) {
- server.stop();
- }
- server.destroy();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public String getIdpHttpsPort() {
- return idpHttpsPort;
- }
-
- public String getRpHttpsPort() {
- return rpHttpsPort;
+ public static void cleanup() throws Exception {
+ TomcatLauncher.shutdownServer();
}
@org.junit.Test
public void testSAML1TokenViaWReq() throws Exception {
- String url = "https://localhost:" + getRpHttpsPort() +
"/fedizhelloworld_wreq/secure/fedservlet";
+ String url = "https://localhost:" + TomcatLauncher.getRpHttpsPort() +
'/' + SERVLET_CONTEXT_NAME
+ + "/secure/fedservlet";
String user = "alice";
String password = "ecila";
- final String bodyTextContent = login(url, user, password,
getIdpHttpsPort());
+ final String bodyTextContent = login(url, user, password,
TomcatLauncher.getIdpHttpsPort());
Assert.assertTrue("Principal not " + user,
bodyTextContent.contains("userPrincipal=" + user));
diff --git a/systests/tomcat/src/test/resources/alice.cer
b/systests/tomcat/src/test/resources/alice.cer
deleted file mode 100644
index 9644a0e..0000000
Binary files a/systests/tomcat/src/test/resources/alice.cer and /dev/null differ