Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B32A8195F3 for ; Thu, 7 Apr 2016 16:04:42 +0000 (UTC) Received: (qmail 13581 invoked by uid 500); 7 Apr 2016 16:04:42 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 13508 invoked by uid 500); 7 Apr 2016 16:04:42 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 13375 invoked by uid 99); 7 Apr 2016 16:04:42 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Apr 2016 16:04:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 09CCDE00B4; Thu, 7 Apr 2016 16:04:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Thu, 07 Apr 2016 16:04:42 -0000 Message-Id: <4c3f163a9bfb49f2a37f6ace310edefe@git.apache.org> In-Reply-To: <2bb5482065e84f348cd88d23cfcef48b@git.apache.org> References: <2bb5482065e84f348cd88d23cfcef48b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] cxf-fediz git commit: Consolidate test launch code and avoid stacktraces when launching Tomcat servers Consolidate test launch code and avoid stacktraces when launching Tomcat servers Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/dffcc9e0 Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/dffcc9e0 Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/dffcc9e0 Branch: refs/heads/1.2.x-fixes Commit: dffcc9e03ede3fa13d8c671f4cbc641264cff9b6 Parents: 0c2deab Author: Colm O hEigeartaigh Authored: Thu Apr 7 17:02:40 2016 +0100 Committer: Colm O hEigeartaigh Committed: Thu Apr 7 17:04:34 2016 +0100 ---------------------------------------------------------------------- .../cxf/fediz/integrationtests/SAMLSSOTest.java | 329 ------------------- .../cxf/fediz/integrationtests/WSFedTest.java | 162 ++++----- .../fediz/integrationtests/KerberosTest.java | 119 +++---- .../cxf/fediz/integrationtests/Spring2Test.java | 121 +++---- .../cxf/fediz/integrationtests/SpringTest.java | 120 +++---- .../integrationtests/ClientCertificateTest.java | 116 +++---- .../fediz/integrationtests/HolderOfKeyTest.java | 118 +++---- .../cxf/fediz/integrationtests/TomcatTest.java | 120 +++---- .../cxf/fediz/integrationtests/WReqTest.java | 119 +++---- .../src/main/webapp/META-INF/context.xml | 22 -- .../src/main/webapp/META-INF/context.xml | 22 -- 11 files changed, 406 insertions(+), 962 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/dffcc9e0/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 b42d4b5..0000000 --- a/systests/federation/samlsso/src/test/java/org/apache/cxf/fediz/integrationtests/SAMLSSOTest.java +++ /dev/null @@ -1,329 +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 org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import com.gargoylesoftware.htmlunit.CookieManager; -import com.gargoylesoftware.htmlunit.WebClient; -import com.gargoylesoftware.htmlunit.html.HtmlForm; -import com.gargoylesoftware.htmlunit.html.HtmlPage; -import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; -import com.gargoylesoftware.htmlunit.xml.XmlPage; - -import org.apache.catalina.Context; -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.core.util.DOMUtils; -import org.apache.cxf.fediz.tomcat.FederationAuthenticator; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.xml.security.keys.KeyInfo; -import org.apache.xml.security.signature.XMLSignature; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * This is a test for federation in the IdP. The RP application is configured to use a home realm of "realm b". The - * client gets redirected to the IdP for "realm a", which in turn redirects to the IdP for "realm b", which is a - * SAML SSO IdP. The IdP for "realm a" will convert the signin request to a SAML SSO sign in request. The IdP for - * realm b authenticates the user, who is then redirected back to the IdP for "realm a" to get a SAML token from - * the STS + then back to the application. - */ -public class SAMLSSOTest { - - static String idpHttpsPort; - static String idpSamlSSOHttpsPort; - static String rpHttpsPort; - - private static Tomcat idpServer; - private static Tomcat idpSamlSSOServer; - 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"); - Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort); - idpSamlSSOHttpsPort = System.getProperty("idp.samlsso.https.port"); - Assert.assertNotNull("Property 'idp.samlsso.https.port' null", idpSamlSSOHttpsPort); - rpHttpsPort = System.getProperty("rp.https.port"); - Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); - - initIdp(); - initSamlSSOIdp(); - 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 initSamlSSOIdp() { - try { - idpSamlSSOServer = new Tomcat(); - idpSamlSSOServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - idpSamlSSOServer.setBaseDir(currentDir + File.separator + "target"); - - idpSamlSSOServer.getHost().setAppBase("tomcat/idpsamlsso/webapps"); - idpSamlSSOServer.getHost().setAutoDeploy(true); - idpSamlSSOServer.getHost().setDeployOnStartup(true); - - Connector httpsConnector = new Connector(); - httpsConnector.setPort(Integer.parseInt(idpSamlSSOHttpsPort)); - 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); - - idpSamlSSOServer.getService().addConnector(httpsConnector); - - idpSamlSSOServer.addWebapp("/idp", "idpsaml"); - - idpSamlSSOServer.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); - - //Context ctx = - Context cxt = rpServer.addWebapp("/fedizhelloworld", "simpleWebapp"); - FederationAuthenticator fa = new FederationAuthenticator(); - fa.setConfigFile(currentDir + File.separator + "target" + File.separator - + "test-classes" + File.separator + "fediz_config_saml_sso.xml"); - cxt.getPipeline().addValve(fa); - - - 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"; - } - - @org.junit.Test - public void testSAMLSSO() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/fedizhelloworld/secure/fedservlet"; - // System.out.println("URL: " + url); - // Thread.sleep(60 * 2 * 1000); - String user = "ALICE"; // realm b credentials - String password = "ECILA"; - - final String bodyTextContent = - login(url, user, password, idpSamlSSOHttpsPort, idpHttpsPort); - - Assert.assertTrue("Principal not alice", - bodyTextContent.contains("userPrincipal=alice")); - Assert.assertTrue("User " + user + " does not have role Admin", - bodyTextContent.contains("role:Admin=false")); - Assert.assertTrue("User " + user + " does not have role Manager", - bodyTextContent.contains("role:Manager=false")); - Assert.assertTrue("User " + user + " must have role User", - bodyTextContent.contains("role:User=true")); - - String claim = ClaimTypes.FIRSTNAME.toString(); - Assert.assertTrue("User " + user + " claim " + claim + " is not 'Alice'", - bodyTextContent.contains(claim + "=Alice")); - claim = ClaimTypes.LASTNAME.toString(); - Assert.assertTrue("User " + user + " claim " + claim + " is not 'Smith'", - bodyTextContent.contains(claim + "=Smith")); - claim = ClaimTypes.EMAILADDRESS.toString(); - Assert.assertTrue("User " + user + " claim " + claim + " is not 'alice@realma.org'", - bodyTextContent.contains(claim + "=alice@realma.org")); - } - - @Test - public void testIdPServiceMetadata() throws Exception { - String url = "https://localhost:" + getIdpHttpsPort() - + "/fediz-idp/metadata/urn:org:apache:cxf:fediz:idp:realm-B"; - - final WebClient webClient = new WebClient(); - webClient.getOptions().setUseInsecureSSL(true); - webClient.getOptions().setSSLClientCertificate( - this.getClass().getClassLoader().getResource("client.jks"), "storepass", "jks"); - - final XmlPage rpPage = webClient.getPage(url); - final String xmlContent = rpPage.asXml(); - Assert.assertTrue(xmlContent.startsWith(" - - - - http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/dffcc9e0/systests/webapps/springPreauthWebapp/src/main/webapp/META-INF/context.xml ---------------------------------------------------------------------- diff --git a/systests/webapps/springPreauthWebapp/src/main/webapp/META-INF/context.xml b/systests/webapps/springPreauthWebapp/src/main/webapp/META-INF/context.xml deleted file mode 100644 index 838f156..0000000 --- a/systests/webapps/springPreauthWebapp/src/main/webapp/META-INF/context.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - -