Refactor of systests
Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/cc76fc31 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/cc76fc31 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/cc76fc31 Branch: refs/heads/master Commit: cc76fc3108946b7747044b98562ec4a384bbc941 Parents: da18e82 Author: Colm O hEigeartaigh <[email protected]> Authored: Wed Jul 12 10:49:11 2017 +0100 Committer: Colm O hEigeartaigh <[email protected]> Committed: Wed Jul 12 10:49:11 2017 +0100 ---------------------------------------------------------------------- plugins/websphere/pom.xml | 2 +- pom.xml | 1 + systests/custom/pom.xml | 12 +- .../systests/custom/CustomParametersTest.java | 2 +- .../custom/SignInQueryCallbackHandler.java | 2 +- systests/cxf/pom.xml | 12 +- .../federation/FederationTest.java | 167 -- .../cxf/fediz/systests/cxf/FederationTest.java | 167 ++ systests/federation/samlsso/pom.xml | 12 +- .../cxf/fediz/integrationtests/RealmMapper.java | 44 - .../cxf/fediz/integrationtests/SAMLSSOTest.java | 376 ----- .../federation/samlsso/RealmMapper.java | 44 + .../federation/samlsso/SAMLSSOTest.java | 376 +++++ .../test/resources/realma/entities-realma.xml | 2 +- systests/federation/wsfed/pom.xml | 12 +- .../cxf/fediz/integrationtests/WSFedTest.java | 550 ------ .../systests/federation/wsfed/WSFedTest.java | 550 ++++++ systests/idp/pom.xml | 12 +- systests/jetty9/pom.xml | 12 +- .../ClientCertificatePreAuthSpringTest.java | 154 -- .../integrationtests/ClientCertificateTest.java | 154 -- .../integrationtests/HOKCallbackHandler.java | 48 - .../JettyPreAuthSpringTest.java | 142 -- .../cxf/fediz/integrationtests/JettyTest.java | 141 -- .../cxf/fediz/integrationtests/JettyUtils.java | 70 - .../ClientCertificatePreAuthSpringTest.java | 155 ++ .../systests/jetty9/ClientCertificateTest.java | 155 ++ .../systests/jetty9/HOKCallbackHandler.java | 48 + .../systests/jetty9/JettyPreAuthSpringTest.java | 143 ++ .../cxf/fediz/systests/jetty9/JettyTest.java | 142 ++ .../cxf/fediz/systests/jetty9/JettyUtils.java | 70 + .../test/resources/fediz_config_client_cert.xml | 4 +- systests/kerberos/pom.xml | 12 +- .../KerberosClientPasswordCallback.java | 48 - .../KerberosServicePasswordCallback.java | 58 - .../fediz/integrationtests/KerberosTest.java | 342 ---- .../KerberosClientPasswordCallback.java | 48 + .../KerberosServicePasswordCallback.java | 58 + .../fediz/systests/kerberos/KerberosTest.java | 342 ++++ .../src/test/resources/sts/kerberos.xml | 2 +- systests/ldap/pom.xml | 12 +- .../cxf/fediz/integrationtests/LDAPTest.java | 283 ---- .../cxf/fediz/systests/ldap/LDAPTest.java | 284 ++++ systests/oidc/pom.xml | 10 - systests/samlsso/pom.xml | 12 +- .../apache/cxf/fediz/systests/idp/IdpTest.java | 1596 ------------------ .../cxf/fediz/systests/samlsso/IdpTest.java | 1596 ++++++++++++++++++ systests/spring/pom.xml | 12 +- .../cxf/fediz/integrationtests/Spring3Test.java | 162 -- .../cxf/fediz/integrationtests/SpringTest.java | 160 -- .../cxf/fediz/systests/spring/Spring3Test.java | 163 ++ .../cxf/fediz/systests/spring/SpringTest.java | 161 ++ .../AbstractClientCertTests.java | 179 -- .../fediz/integrationtests/AbstractTests.java | 802 --------- .../fediz/integrationtests/HTTPTestUtils.java | 155 -- .../common/AbstractClientCertTests.java | 179 ++ .../fediz/systests/common/AbstractTests.java | 802 +++++++++ .../fediz/systests/common/HTTPTestUtils.java | 155 ++ systests/tomcat8/pom.xml | 12 +- .../AudienceRestrictionTest.java | 210 --- .../integrationtests/ClientCertificateTest.java | 172 -- .../integrationtests/HOKCallbackHandler.java | 48 - .../fediz/integrationtests/HolderOfKeyTest.java | 244 --- .../integrationtests/TestCallbackHandler.java | 48 - .../cxf/fediz/integrationtests/TomcatTest.java | 172 -- .../cxf/fediz/integrationtests/WReqTest.java | 246 --- .../tomcat8/AudienceRestrictionTest.java | 210 +++ .../systests/tomcat8/ClientCertificateTest.java | 173 ++ .../systests/tomcat8/HOKCallbackHandler.java | 48 + .../fediz/systests/tomcat8/HolderOfKeyTest.java | 244 +++ .../systests/tomcat8/TestCallbackHandler.java | 48 + .../cxf/fediz/systests/tomcat8/TomcatTest.java | 173 ++ .../cxf/fediz/systests/tomcat8/WReqTest.java | 246 +++ .../test/resources/fediz_config_client_cert.xml | 2 +- .../src/test/resources/fediz_config_hok.xml | 2 +- .../src/test/resources/fediz_config_wreq.xml | 2 +- systests/websphere/pom.xml | 14 +- .../fediz/integrationtests/WebsphereTest.java | 145 -- .../fediz/systests/websphere/WebsphereTest.java | 145 ++ 79 files changed, 6949 insertions(+), 7069 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/plugins/websphere/pom.xml ---------------------------------------------------------------------- diff --git a/plugins/websphere/pom.xml b/plugins/websphere/pom.xml index 05603e5..2554326 100644 --- a/plugins/websphere/pom.xml +++ b/plugins/websphere/pom.xml @@ -22,7 +22,7 @@ <parent> <groupId>org.apache.cxf.fediz</groupId> <artifactId>plugin</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>2.0.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <artifactId>fediz-websphere</artifactId> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 3a44ad6..399d327 100644 --- a/pom.xml +++ b/pom.xml @@ -551,6 +551,7 @@ <!-- do not exclude **/Abstract*Test.java **/Abstract*TestCase.java --> <excludes> <exclude>**/*$*</exclude> + <exclude>**/systests/**</exclude> </excludes> <!--disableXmlReport>true</disableXmlReport--> <runOrder>alphabetical</runOrder> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/custom/pom.xml ---------------------------------------------------------------------- diff --git a/systests/custom/pom.xml b/systests/custom/pom.xml index c7dbd30..ee52b5d 100644 --- a/systests/custom/pom.xml +++ b/systests/custom/pom.xml @@ -314,7 +314,7 @@ <java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file> </systemPropertyVariables> <includes> - <include>**/custom/**</include> + <include>**/systests/**</include> </includes> <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m </argLine> <!--argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y</argLine--> @@ -329,16 +329,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <inherited>true</inherited> - <configuration> - <excludes> - <exclude>**/custom/**</exclude> - </excludes> - </configuration> - </plugin> </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/CustomParametersTest.java ---------------------------------------------------------------------- diff --git a/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/CustomParametersTest.java b/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/CustomParametersTest.java index e428425..fd96823 100644 --- a/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/CustomParametersTest.java +++ b/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/CustomParametersTest.java @@ -40,7 +40,7 @@ import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Tomcat; import org.apache.commons.io.IOUtils; import org.apache.cxf.fediz.core.ClaimTypes; -import org.apache.cxf.fediz.integrationtests.HTTPTestUtils; +import org.apache.cxf.fediz.systests.common.HTTPTestUtils; import org.apache.cxf.fediz.tomcat8.FederationAuthenticator; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/SignInQueryCallbackHandler.java ---------------------------------------------------------------------- diff --git a/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/SignInQueryCallbackHandler.java b/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/SignInQueryCallbackHandler.java index 81bc296..a13851b 100644 --- a/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/SignInQueryCallbackHandler.java +++ b/systests/custom/src/test/java/org/apache/cxf/fediz/systests/custom/SignInQueryCallbackHandler.java @@ -45,4 +45,4 @@ public class SignInQueryCallbackHandler implements CallbackHandler { } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/cxf/pom.xml ---------------------------------------------------------------------- diff --git a/systests/cxf/pom.xml b/systests/cxf/pom.xml index d2611ad..162ef7e 100644 --- a/systests/cxf/pom.xml +++ b/systests/cxf/pom.xml @@ -244,7 +244,7 @@ <java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file> </systemPropertyVariables> <includes> - <include>**/integrationtests/**</include> + <include>**/systests/**</include> </includes> <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m</argLine> @@ -259,16 +259,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <inherited>true</inherited> - <configuration> - <excludes> - <exclude>**/integrationtests/**</exclude> - </excludes> - </configuration> - </plugin> </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java ---------------------------------------------------------------------- diff --git a/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java b/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java deleted file mode 100644 index 3ab3875..0000000 --- a/systests/cxf/src/test/java/org/apache/cxf/fediz/integrationtests/federation/FederationTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * 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.integrationtests.federation; - -import java.io.File; - -import org.apache.catalina.LifecycleState; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; -import org.apache.cxf.fediz.integrationtests.AbstractTests; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; - -/** - * A test for WS-Federation using the CXF plugin (deployed in Tomcat). - */ -public class FederationTest extends AbstractTests { - - static String idpHttpsPort; - static String rpHttpsPort; - - private static Tomcat idpServer; - private static Tomcat rpServer; - - @BeforeClass - public static void init() { - System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); - System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); - System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf", "info"); - - idpHttpsPort = System.getProperty("idp.https.port"); - // idpHttpsPort = "12345"; - Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort); - rpHttpsPort = System.getProperty("rp.https.port"); - Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); - - initIdp(); - initRp(); - } - - private static void initIdp() { - try { - idpServer = new Tomcat(); - idpServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - idpServer.setBaseDir(currentDir + File.separator + "target"); - - idpServer.getHost().setAppBase("tomcat/idp/webapps"); - idpServer.getHost().setAutoDeploy(true); - idpServer.getHost().setDeployOnStartup(true); - - Connector httpsConnector = new Connector(); - httpsConnector.setPort(Integer.parseInt(idpHttpsPort)); - httpsConnector.setSecure(true); - httpsConnector.setScheme("https"); - //httpsConnector.setAttribute("keyAlias", keyAlias); - 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); - - idpServer.getService().addConnector(httpsConnector); - - idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts"); - idpServer.addWebapp("/fediz-idp", "fediz-idp"); - - idpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private static void initRp() { - try { - rpServer = new Tomcat(); - rpServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - rpServer.setBaseDir(currentDir + File.separator + "target"); - - rpServer.getHost().setAppBase("tomcat/rp/webapps"); - rpServer.getHost().setAutoDeploy(true); - rpServer.getHost().setDeployOnStartup(true); - - Connector httpsConnector = new Connector(); - httpsConnector.setPort(Integer.parseInt(rpHttpsPort)); - httpsConnector.setSecure(true); - httpsConnector.setScheme("https"); - //httpsConnector.setAttribute("keyAlias", keyAlias); - 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", "false"); - httpsConnector.setAttribute("clientAuth", "want"); - httpsConnector.setAttribute("sslProtocol", "TLS"); - httpsConnector.setAttribute("SSLEnabled", true); - - rpServer.getService().addConnector(httpsConnector); - - rpServer.addWebapp("/fedizhelloworld", "cxfWebapp"); - - rpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @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 String getServletContextName() { - return "fedizhelloworld"; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java ---------------------------------------------------------------------- diff --git a/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java b/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java new file mode 100644 index 0000000..847850f --- /dev/null +++ b/systests/cxf/src/test/java/org/apache/cxf/fediz/systests/cxf/FederationTest.java @@ -0,0 +1,167 @@ +/** + * 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.cxf; + +import java.io.File; + +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.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; + +/** + * A test for WS-Federation using the CXF plugin (deployed in Tomcat). + */ +public class FederationTest extends AbstractTests { + + static String idpHttpsPort; + static String rpHttpsPort; + + private static Tomcat idpServer; + private static Tomcat rpServer; + + @BeforeClass + public static void init() { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf", "info"); + + idpHttpsPort = System.getProperty("idp.https.port"); + // idpHttpsPort = "12345"; + Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort); + rpHttpsPort = System.getProperty("rp.https.port"); + Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); + + initIdp(); + initRp(); + } + + private static void initIdp() { + try { + idpServer = new Tomcat(); + idpServer.setPort(0); + String currentDir = new File(".").getCanonicalPath(); + idpServer.setBaseDir(currentDir + File.separator + "target"); + + idpServer.getHost().setAppBase("tomcat/idp/webapps"); + idpServer.getHost().setAutoDeploy(true); + idpServer.getHost().setDeployOnStartup(true); + + Connector httpsConnector = new Connector(); + httpsConnector.setPort(Integer.parseInt(idpHttpsPort)); + httpsConnector.setSecure(true); + httpsConnector.setScheme("https"); + //httpsConnector.setAttribute("keyAlias", keyAlias); + 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); + + idpServer.getService().addConnector(httpsConnector); + + idpServer.addWebapp("/fediz-idp-sts", "fediz-idp-sts"); + idpServer.addWebapp("/fediz-idp", "fediz-idp"); + + idpServer.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void initRp() { + try { + rpServer = new Tomcat(); + rpServer.setPort(0); + String currentDir = new File(".").getCanonicalPath(); + rpServer.setBaseDir(currentDir + File.separator + "target"); + + rpServer.getHost().setAppBase("tomcat/rp/webapps"); + rpServer.getHost().setAutoDeploy(true); + rpServer.getHost().setDeployOnStartup(true); + + Connector httpsConnector = new Connector(); + httpsConnector.setPort(Integer.parseInt(rpHttpsPort)); + httpsConnector.setSecure(true); + httpsConnector.setScheme("https"); + //httpsConnector.setAttribute("keyAlias", keyAlias); + 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", "false"); + httpsConnector.setAttribute("clientAuth", "want"); + httpsConnector.setAttribute("sslProtocol", "TLS"); + httpsConnector.setAttribute("SSLEnabled", true); + + rpServer.getService().addConnector(httpsConnector); + + rpServer.addWebapp("/fedizhelloworld", "cxfWebapp"); + + rpServer.start(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @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 String getServletContextName() { + return "fedizhelloworld"; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/samlsso/pom.xml ---------------------------------------------------------------------- diff --git a/systests/federation/samlsso/pom.xml b/systests/federation/samlsso/pom.xml index 9848029..587a5a9 100644 --- a/systests/federation/samlsso/pom.xml +++ b/systests/federation/samlsso/pom.xml @@ -322,7 +322,7 @@ <java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file> </systemPropertyVariables> <includes> - <include>**/integrationtests/**</include> + <include>**/systests/**</include> </includes> <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m</argLine> @@ -337,16 +337,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <inherited>true</inherited> - <configuration> - <excludes> - <exclude>**/integrationtests/**</exclude> - </excludes> - </configuration> - </plugin> </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/RealmMapper.java ---------------------------------------------------------------------- diff --git a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/RealmMapper.java b/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/RealmMapper.java deleted file mode 100644 index a2a6e64..0000000 --- a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/RealmMapper.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.integrationtests; - - -import java.util.HashMap; -import java.util.Map; - -/** - * Returns a static map of application realms to home realms - */ -public final class RealmMapper { - - private RealmMapper() { - // - } - - public static Map<String, String> realms() { - Map<String, String> realms = new HashMap<>(); - realms.put("urn:org:apache:cxf:fediz:fedizhelloworld:realm-B", "urn:org:apache:cxf:fediz:idp:realm-B"); - realms.put("urn:org:apache:cxf:fediz:fedizhelloworld:realm-C", "urn:org:apache:cxf:fediz:idp:realm-C"); - realms.put("urn:org:apache:cxf:fediz:fedizhelloworld:realm-D", "urn:org:apache:cxf:fediz:idp:realm-D"); - - return realms; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/SAMLSSOTest.java ---------------------------------------------------------------------- diff --git a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/SAMLSSOTest.java b/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/SAMLSSOTest.java deleted file mode 100644 index a34b2fc..0000000 --- a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/SAMLSSOTest.java +++ /dev/null @@ -1,376 +0,0 @@ -/** - * 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.integrationtests; - - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; - -import javax.servlet.ServletException; - -import com.gargoylesoftware.htmlunit.CookieManager; -import com.gargoylesoftware.htmlunit.HttpMethod; -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.WebRequest; -import com.gargoylesoftware.htmlunit.html.HtmlForm; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; -import com.gargoylesoftware.htmlunit.util.NameValuePair; -import com.gargoylesoftware.htmlunit.xml.XmlPage; - -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.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; - -/** - * This is a test for federation using a SAML SSO enabled web application (using CXF interceptors). The web - * application is configured to use a different realm to that of the IdP. The IdP then redirects to a third party - * IdP for authentication. The third party IdPs that are tested are as follows: - * - WS-Federation (Fediz) - * - SAML SSO (Fediz) - * - OIDC (custom webapp) - */ -public class SAMLSSOTest { - - private enum ServerType { - IDP, REALMB, OIDC, RP - } - - static String idpHttpsPort; - static String idpRealmbHttpsPort; - static String idpSamlSSOHttpsPort; - static String idpOIDCHttpsPort; - static String rpHttpsPort; - - private static Tomcat idpServer; - private static Tomcat idpRealmbServer; - private static Tomcat idpOIDCServer; - private static Tomcat rpServer; - - @BeforeClass - public static void init() throws Exception { - System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); - System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); - System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf", "info"); - - idpHttpsPort = System.getProperty("idp.https.port"); - Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort); - idpRealmbHttpsPort = System.getProperty("idp.realmb.https.port"); - Assert.assertNotNull("Property 'idp.realmb.https.port' null", idpRealmbHttpsPort); - idpSamlSSOHttpsPort = System.getProperty("idp.samlsso.https.port"); - Assert.assertNotNull("Property 'idp.samlsso.https.port' null", idpSamlSSOHttpsPort); - idpOIDCHttpsPort = System.getProperty("idp.oidc.https.port"); - Assert.assertNotNull("Property 'idp.oidc.https.port' null", idpOIDCHttpsPort); - rpHttpsPort = System.getProperty("rp.https.port"); - Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); - - idpServer = startServer(ServerType.IDP, idpHttpsPort); - idpRealmbServer = startServer(ServerType.REALMB, idpRealmbHttpsPort); - idpOIDCServer = startServer(ServerType.OIDC, idpOIDCHttpsPort); - rpServer = startServer(ServerType.RP, rpHttpsPort); - } - - private static Tomcat startServer(ServerType serverType, 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 (serverType == ServerType.IDP) { - server.getHost().setAppBase("tomcat/idp/webapps"); - } else if (serverType == ServerType.REALMB) { - server.getHost().setAppBase("tomcat/idprealmb/webapps"); - } else if (serverType == ServerType.OIDC) { - server.getHost().setAppBase("tomcat/idpoidc/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", keyAlias); - 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 (serverType == ServerType.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 if (serverType == ServerType.REALMB) { - File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts-realmb"); - server.addWebapp("/fediz-idp-sts-realmb", stsWebapp.getAbsolutePath()); - - File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-realmb"); - server.addWebapp("/fediz-idp-realmb", idpWebapp.getAbsolutePath()); - } else if (serverType == ServerType.OIDC) { - File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "idpoidc"); - server.addWebapp("/idpoidc", idpWebapp.getAbsolutePath()); - } else { - File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "samlssoWebapp"); - server.addWebapp("/samlsso", rpWebapp.getAbsolutePath()); - } - - server.start(); - - return server; - } - - @AfterClass - public static void cleanup() { - shutdownServer(idpServer); - shutdownServer(idpRealmbServer); - shutdownServer(idpOIDCServer); - 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 getIdpRealmbHttpsPort() { - return idpRealmbHttpsPort; - } - - public String getRpHttpsPort() { - return rpHttpsPort; - } - - public String getServletContextName() { - return "fedizhelloworld"; - } - - @org.junit.Test - public void testWSFederation() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/app1/services/25"; - //System.out.println(url); - //Thread.sleep(60 * 2 * 1000); - - String user = "ALICE"; // realm b credentials - String password = "ECILA"; - - final String bodyTextContent = - login(url, user, password, getIdpRealmbHttpsPort(), getIdpHttpsPort()); - - Assert.assertTrue(bodyTextContent.contains("This is the double number response")); - - } - - @org.junit.Test - public void testSAMLSSOFedizIdP() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/app2/services/25"; - // System.out.println(url); - // Thread.sleep(60 * 2 * 1000); - String user = "ALICE"; // realm b credentials - String password = "ECILA"; - - final String bodyTextContent = - login(url, user, password, getIdpRealmbHttpsPort(), getIdpHttpsPort(), true); - - Assert.assertTrue(bodyTextContent.contains("This is the double number response")); - } - - @org.junit.Test - public void testOIDC() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/app3/services/25"; - String user = "ALICE"; // realm b credentials - String password = "ECILA"; - - final String bodyTextContent = - loginOIDC(url, user, password, idpOIDCHttpsPort, idpHttpsPort); - - Assert.assertTrue(bodyTextContent.contains("This is the double number response")); - } - - - private static String login(String url, String user, String password, - String idpPort, String rpIdpPort) throws IOException { - // - // Access the RP + get redirected to the IdP for "realm a". Then get redirected to the IdP for - // "realm b". - // - final WebClient webClient = new WebClient(); - CookieManager cookieManager = new CookieManager(); - webClient.setCookieManager(cookieManager); - webClient.getOptions().setUseInsecureSSL(true); - webClient.getCredentialsProvider().setCredentials( - new AuthScope("localhost", Integer.parseInt(idpPort)), - new UsernamePasswordCredentials(user, password)); - - webClient.getOptions().setJavaScriptEnabled(false); - HtmlPage idpPage = webClient.getPage(url); - - Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); - - // Now redirect back to the IdP for Realm A - HtmlForm form = idpPage.getFormByName("signinresponseform"); - - HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - - HtmlPage idpPageRealmA = button.click(); - - Assert.assertTrue("SAML IDP Response Form".equals(idpPage.getTitleText()) - || "IDP SignIn Response Form".equals(idpPage.getTitleText())); - form = idpPageRealmA.getFormByName("samlsigninresponseform"); - - // Now redirect back to the SAML SSO web app - button = form.getInputByName("_eventId_submit"); - - XmlPage rpPage = button.click(); - - webClient.close(); - return rpPage.asXml(); - } - - private static String login(String url, String user, String password, - String idpPort, String rpIdpPort, boolean postBinding) throws IOException { - // - // Access the RP + get redirected to the IdP for "realm a". Then get redirected to the IdP for - // "realm b". - // - final WebClient webClient = new WebClient(); - CookieManager cookieManager = new CookieManager(); - webClient.setCookieManager(cookieManager); - webClient.getOptions().setUseInsecureSSL(true); - webClient.getCredentialsProvider().setCredentials( - new AuthScope("localhost", Integer.parseInt(idpPort)), - new UsernamePasswordCredentials(user, password)); - - webClient.getOptions().setJavaScriptEnabled(false); - HtmlPage idpPage = webClient.getPage(url); - - if (postBinding) { - Assert.assertTrue("SAML IDP Response Form".equals(idpPage.getTitleText()) - || "IDP SignIn Response Form".equals(idpPage.getTitleText())); - for (HtmlForm form : idpPage.getForms()) { - String name = form.getAttributeNS(null, "name"); - if ("signinresponseform".equals(name) || "samlsigninresponseform".equals(name)) { - final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - idpPage = button.click(); - } - } - } - - Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); - - // Now redirect back to the RP - final HtmlForm form = idpPage.getFormByName("samlsigninresponseform"); - - final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - - final XmlPage rpPage = button.click(); - - webClient.close(); - return rpPage.asXml(); - } - - private static String loginOIDC(String url, String user, String password, - String idpPort, String rpIdpPort) throws IOException { - // - // Access the RP + get redirected to the IdP for "realm a". Then get redirected to the IdP for - // "realm b". - // - final WebClient webClient = new WebClient(); - CookieManager cookieManager = new CookieManager(); - webClient.setCookieManager(cookieManager); - webClient.getOptions().setUseInsecureSSL(true); - webClient.getCredentialsProvider().setCredentials( - new AuthScope("localhost", Integer.parseInt(idpPort)), - new UsernamePasswordCredentials(user, password)); - - webClient.getOptions().setJavaScriptEnabled(false); - - // The decision page is returned as XML for some reason. So parse it and send a form response back. - HtmlPage oidcIdpConfirmationPage = webClient.getPage(url); - final HtmlForm oidcForm = oidcIdpConfirmationPage.getForms().get(0); - - WebRequest request = new WebRequest(new URL(oidcForm.getActionAttribute()), HttpMethod.POST); - - request.setRequestParameters(new ArrayList<NameValuePair>()); - String clientId = oidcForm.getInputByName("client_id").getValueAttribute(); - request.getRequestParameters().add(new NameValuePair("client_id", clientId)); - String redirectUri = oidcForm.getInputByName("redirect_uri").getValueAttribute(); - request.getRequestParameters().add(new NameValuePair("redirect_uri", redirectUri)); - String scope = oidcForm.getInputByName("scope").getValueAttribute(); - request.getRequestParameters().add(new NameValuePair("scope", scope)); - String state = oidcForm.getInputByName("state").getValueAttribute(); - request.getRequestParameters().add(new NameValuePair("state", state)); - String authToken = oidcForm.getInputByName("session_authenticity_token").getValueAttribute(); - request.getRequestParameters().add(new NameValuePair("session_authenticity_token", authToken)); - request.getRequestParameters().add(new NameValuePair("oauthDecision", "allow")); - - HtmlPage idpPage = webClient.getPage(request); - - Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); - - // Now redirect back to the RP - final HtmlForm form = idpPage.getFormByName("samlsigninresponseform"); - - final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - - final XmlPage rpPage = button.click(); - - webClient.close(); - return rpPage.asXml(); - } - -} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/RealmMapper.java ---------------------------------------------------------------------- diff --git a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/RealmMapper.java b/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/RealmMapper.java new file mode 100644 index 0000000..4f46e20 --- /dev/null +++ b/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/RealmMapper.java @@ -0,0 +1,44 @@ +/** + * 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.federation.samlsso; + + +import java.util.HashMap; +import java.util.Map; + +/** + * Returns a static map of application realms to home realms + */ +public final class RealmMapper { + + private RealmMapper() { + // + } + + public static Map<String, String> realms() { + Map<String, String> realms = new HashMap<>(); + realms.put("urn:org:apache:cxf:fediz:fedizhelloworld:realm-B", "urn:org:apache:cxf:fediz:idp:realm-B"); + realms.put("urn:org:apache:cxf:fediz:fedizhelloworld:realm-C", "urn:org:apache:cxf:fediz:idp:realm-C"); + realms.put("urn:org:apache:cxf:fediz:fedizhelloworld:realm-D", "urn:org:apache:cxf:fediz:idp:realm-D"); + + return realms; + } + +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/SAMLSSOTest.java ---------------------------------------------------------------------- diff --git a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/SAMLSSOTest.java b/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/SAMLSSOTest.java new file mode 100644 index 0000000..f14eb53 --- /dev/null +++ b/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/systests/federation/samlsso/SAMLSSOTest.java @@ -0,0 +1,376 @@ +/** + * 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.federation.samlsso; + + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; + +import javax.servlet.ServletException; + +import com.gargoylesoftware.htmlunit.CookieManager; +import com.gargoylesoftware.htmlunit.HttpMethod; +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.WebRequest; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import com.gargoylesoftware.htmlunit.html.HtmlPage; +import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; +import com.gargoylesoftware.htmlunit.util.NameValuePair; +import com.gargoylesoftware.htmlunit.xml.XmlPage; + +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.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; + +/** + * This is a test for federation using a SAML SSO enabled web application (using CXF interceptors). The web + * application is configured to use a different realm to that of the IdP. The IdP then redirects to a third party + * IdP for authentication. The third party IdPs that are tested are as follows: + * - WS-Federation (Fediz) + * - SAML SSO (Fediz) + * - OIDC (custom webapp) + */ +public class SAMLSSOTest { + + private enum ServerType { + IDP, REALMB, OIDC, RP + } + + static String idpHttpsPort; + static String idpRealmbHttpsPort; + static String idpSamlSSOHttpsPort; + static String idpOIDCHttpsPort; + static String rpHttpsPort; + + private static Tomcat idpServer; + private static Tomcat idpRealmbServer; + private static Tomcat idpOIDCServer; + private static Tomcat rpServer; + + @BeforeClass + public static void init() throws Exception { + System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); + System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); + System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.webflow", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.springframework.security.web", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf.fediz", "info"); + System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.cxf", "info"); + + idpHttpsPort = System.getProperty("idp.https.port"); + Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort); + idpRealmbHttpsPort = System.getProperty("idp.realmb.https.port"); + Assert.assertNotNull("Property 'idp.realmb.https.port' null", idpRealmbHttpsPort); + idpSamlSSOHttpsPort = System.getProperty("idp.samlsso.https.port"); + Assert.assertNotNull("Property 'idp.samlsso.https.port' null", idpSamlSSOHttpsPort); + idpOIDCHttpsPort = System.getProperty("idp.oidc.https.port"); + Assert.assertNotNull("Property 'idp.oidc.https.port' null", idpOIDCHttpsPort); + rpHttpsPort = System.getProperty("rp.https.port"); + Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); + + idpServer = startServer(ServerType.IDP, idpHttpsPort); + idpRealmbServer = startServer(ServerType.REALMB, idpRealmbHttpsPort); + idpOIDCServer = startServer(ServerType.OIDC, idpOIDCHttpsPort); + rpServer = startServer(ServerType.RP, rpHttpsPort); + } + + private static Tomcat startServer(ServerType serverType, 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 (serverType == ServerType.IDP) { + server.getHost().setAppBase("tomcat/idp/webapps"); + } else if (serverType == ServerType.REALMB) { + server.getHost().setAppBase("tomcat/idprealmb/webapps"); + } else if (serverType == ServerType.OIDC) { + server.getHost().setAppBase("tomcat/idpoidc/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", keyAlias); + 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 (serverType == ServerType.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 if (serverType == ServerType.REALMB) { + File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts-realmb"); + server.addWebapp("/fediz-idp-sts-realmb", stsWebapp.getAbsolutePath()); + + File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-realmb"); + server.addWebapp("/fediz-idp-realmb", idpWebapp.getAbsolutePath()); + } else if (serverType == ServerType.OIDC) { + File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "idpoidc"); + server.addWebapp("/idpoidc", idpWebapp.getAbsolutePath()); + } else { + File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "samlssoWebapp"); + server.addWebapp("/samlsso", rpWebapp.getAbsolutePath()); + } + + server.start(); + + return server; + } + + @AfterClass + public static void cleanup() { + shutdownServer(idpServer); + shutdownServer(idpRealmbServer); + shutdownServer(idpOIDCServer); + 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 getIdpRealmbHttpsPort() { + return idpRealmbHttpsPort; + } + + public String getRpHttpsPort() { + return rpHttpsPort; + } + + public String getServletContextName() { + return "fedizhelloworld"; + } + + @org.junit.Test + public void testWSFederation() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/app1/services/25"; + //System.out.println(url); + //Thread.sleep(60 * 2 * 1000); + + String user = "ALICE"; // realm b credentials + String password = "ECILA"; + + final String bodyTextContent = + login(url, user, password, getIdpRealmbHttpsPort(), getIdpHttpsPort()); + + Assert.assertTrue(bodyTextContent.contains("This is the double number response")); + + } + + @org.junit.Test + public void testSAMLSSOFedizIdP() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/app2/services/25"; + // System.out.println(url); + // Thread.sleep(60 * 2 * 1000); + String user = "ALICE"; // realm b credentials + String password = "ECILA"; + + final String bodyTextContent = + login(url, user, password, getIdpRealmbHttpsPort(), getIdpHttpsPort(), true); + + Assert.assertTrue(bodyTextContent.contains("This is the double number response")); + } + + @org.junit.Test + public void testOIDC() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/app3/services/25"; + String user = "ALICE"; // realm b credentials + String password = "ECILA"; + + final String bodyTextContent = + loginOIDC(url, user, password, idpOIDCHttpsPort, idpHttpsPort); + + Assert.assertTrue(bodyTextContent.contains("This is the double number response")); + } + + + private static String login(String url, String user, String password, + String idpPort, String rpIdpPort) throws IOException { + // + // Access the RP + get redirected to the IdP for "realm a". Then get redirected to the IdP for + // "realm b". + // + final WebClient webClient = new WebClient(); + CookieManager cookieManager = new CookieManager(); + webClient.setCookieManager(cookieManager); + webClient.getOptions().setUseInsecureSSL(true); + webClient.getCredentialsProvider().setCredentials( + new AuthScope("localhost", Integer.parseInt(idpPort)), + new UsernamePasswordCredentials(user, password)); + + webClient.getOptions().setJavaScriptEnabled(false); + HtmlPage idpPage = webClient.getPage(url); + + Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); + + // Now redirect back to the IdP for Realm A + HtmlForm form = idpPage.getFormByName("signinresponseform"); + + HtmlSubmitInput button = form.getInputByName("_eventId_submit"); + + HtmlPage idpPageRealmA = button.click(); + + Assert.assertTrue("SAML IDP Response Form".equals(idpPage.getTitleText()) + || "IDP SignIn Response Form".equals(idpPage.getTitleText())); + form = idpPageRealmA.getFormByName("samlsigninresponseform"); + + // Now redirect back to the SAML SSO web app + button = form.getInputByName("_eventId_submit"); + + XmlPage rpPage = button.click(); + + webClient.close(); + return rpPage.asXml(); + } + + private static String login(String url, String user, String password, + String idpPort, String rpIdpPort, boolean postBinding) throws IOException { + // + // Access the RP + get redirected to the IdP for "realm a". Then get redirected to the IdP for + // "realm b". + // + final WebClient webClient = new WebClient(); + CookieManager cookieManager = new CookieManager(); + webClient.setCookieManager(cookieManager); + webClient.getOptions().setUseInsecureSSL(true); + webClient.getCredentialsProvider().setCredentials( + new AuthScope("localhost", Integer.parseInt(idpPort)), + new UsernamePasswordCredentials(user, password)); + + webClient.getOptions().setJavaScriptEnabled(false); + HtmlPage idpPage = webClient.getPage(url); + + if (postBinding) { + Assert.assertTrue("SAML IDP Response Form".equals(idpPage.getTitleText()) + || "IDP SignIn Response Form".equals(idpPage.getTitleText())); + for (HtmlForm form : idpPage.getForms()) { + String name = form.getAttributeNS(null, "name"); + if ("signinresponseform".equals(name) || "samlsigninresponseform".equals(name)) { + final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); + idpPage = button.click(); + } + } + } + + Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); + + // Now redirect back to the RP + final HtmlForm form = idpPage.getFormByName("samlsigninresponseform"); + + final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); + + final XmlPage rpPage = button.click(); + + webClient.close(); + return rpPage.asXml(); + } + + private static String loginOIDC(String url, String user, String password, + String idpPort, String rpIdpPort) throws IOException { + // + // Access the RP + get redirected to the IdP for "realm a". Then get redirected to the IdP for + // "realm b". + // + final WebClient webClient = new WebClient(); + CookieManager cookieManager = new CookieManager(); + webClient.setCookieManager(cookieManager); + webClient.getOptions().setUseInsecureSSL(true); + webClient.getCredentialsProvider().setCredentials( + new AuthScope("localhost", Integer.parseInt(idpPort)), + new UsernamePasswordCredentials(user, password)); + + webClient.getOptions().setJavaScriptEnabled(false); + + // The decision page is returned as XML for some reason. So parse it and send a form response back. + HtmlPage oidcIdpConfirmationPage = webClient.getPage(url); + final HtmlForm oidcForm = oidcIdpConfirmationPage.getForms().get(0); + + WebRequest request = new WebRequest(new URL(oidcForm.getActionAttribute()), HttpMethod.POST); + + request.setRequestParameters(new ArrayList<NameValuePair>()); + String clientId = oidcForm.getInputByName("client_id").getValueAttribute(); + request.getRequestParameters().add(new NameValuePair("client_id", clientId)); + String redirectUri = oidcForm.getInputByName("redirect_uri").getValueAttribute(); + request.getRequestParameters().add(new NameValuePair("redirect_uri", redirectUri)); + String scope = oidcForm.getInputByName("scope").getValueAttribute(); + request.getRequestParameters().add(new NameValuePair("scope", scope)); + String state = oidcForm.getInputByName("state").getValueAttribute(); + request.getRequestParameters().add(new NameValuePair("state", state)); + String authToken = oidcForm.getInputByName("session_authenticity_token").getValueAttribute(); + request.getRequestParameters().add(new NameValuePair("session_authenticity_token", authToken)); + request.getRequestParameters().add(new NameValuePair("oauthDecision", "allow")); + + HtmlPage idpPage = webClient.getPage(request); + + Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); + + // Now redirect back to the RP + final HtmlForm form = idpPage.getFormByName("samlsigninresponseform"); + + final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); + + final XmlPage rpPage = button.click(); + + webClient.close(); + return rpPage.asXml(); + } + +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/samlsso/src/test/resources/realma/entities-realma.xml ---------------------------------------------------------------------- diff --git a/systests/federation/samlsso/src/test/resources/realma/entities-realma.xml b/systests/federation/samlsso/src/test/resources/realma/entities-realma.xml index 714dbd4..3d9cc0c 100644 --- a/systests/federation/samlsso/src/test/resources/realma/entities-realma.xml +++ b/systests/federation/samlsso/src/test/resources/realma/entities-realma.xml @@ -79,7 +79,7 @@ <ref bean="claim_email" /> </util:list> </property> - <property name="hrds" value="T(org.apache.cxf.fediz.integrationtests.RealmMapper).realms() + <property name="hrds" value="T(org.apache.cxf.fediz.systests.federation.samlsso.RealmMapper).realms() .get(getFlowScope().get('saml_authn_request').issuer)" /> </bean> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/wsfed/pom.xml ---------------------------------------------------------------------- diff --git a/systests/federation/wsfed/pom.xml b/systests/federation/wsfed/pom.xml index 955eec4..0a40f20 100644 --- a/systests/federation/wsfed/pom.xml +++ b/systests/federation/wsfed/pom.xml @@ -312,7 +312,7 @@ <java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file> </systemPropertyVariables> <includes> - <include>**/integrationtests/**</include> + <include>**/systests/**</include> </includes> <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m</argLine> @@ -327,16 +327,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <inherited>true</inherited> - <configuration> - <excludes> - <exclude>**/integrationtests/**</exclude> - </excludes> - </configuration> - </plugin> </plugins> </build> </project>
