http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/integrationtests/WSFedTest.java ---------------------------------------------------------------------- diff --git a/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/integrationtests/WSFedTest.java b/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/integrationtests/WSFedTest.java deleted file mode 100644 index c16bb01..0000000 --- a/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/integrationtests/WSFedTest.java +++ /dev/null @@ -1,550 +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.net.URLEncoder; -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.DomElement; -import com.gargoylesoftware.htmlunit.html.DomNodeList; -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 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.tomcat8.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; - -/** - * This is a test for federation using a WS-Federation enabled web application. 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) - * - SAML SSO (custom webapp - supports POST binding as well) - * - OIDC (custom webapp) - */ -public class WSFedTest { - - private enum ServerType { - IDP, REALMB, SAMLSSO, 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 idpSamlSSOServer; - 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); - idpSamlSSOServer = startServer(ServerType.SAMLSSO, idpSamlSSOHttpsPort); - 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.SAMLSSO) { - server.getHost().setAppBase("tomcat/idpsamlsso/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.SAMLSSO) { - File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "idpsaml"); - server.addWebapp("/idp", 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(), "simpleWebapp"); - Context cxt = server.addWebapp("/wsfed", rpWebapp.getAbsolutePath()); - - FederationAuthenticator fa = new FederationAuthenticator(); - fa.setConfigFile(currentDir + File.separator + "target" + File.separator - + "test-classes" + File.separator + "fediz_config_wsfed.xml"); - cxt.getPipeline().addValve(fa); - - rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); - cxt = server.addWebapp("/samlsso", rpWebapp.getAbsolutePath()); - cxt.getPipeline().addValve(fa); - - rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); - cxt = server.addWebapp("/samlssocustom", rpWebapp.getAbsolutePath()); - cxt.getPipeline().addValve(fa); - - rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); - cxt = server.addWebapp("/samlssocustompost", rpWebapp.getAbsolutePath()); - cxt.getPipeline().addValve(fa); - - rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); - cxt = server.addWebapp("/oidc", rpWebapp.getAbsolutePath()); - cxt.getPipeline().addValve(fa); - } - - server.start(); - - return server; - } - - @AfterClass - public static void cleanup() { - shutdownServer(idpServer); - shutdownServer(idpRealmbServer); - shutdownServer(idpSamlSSOServer); - 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() + "/wsfed/secure/fedservlet"; - // 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(), 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 '[email protected]'", - bodyTextContent.contains(claim + "[email protected]")); - } - - @org.junit.Test - public void testSAMLSSOFedizIdP() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/secure/fedservlet"; - // 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("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 '[email protected]'", - bodyTextContent.contains(claim + "[email protected]")); - } - - @org.junit.Test - public void testSAMLSSOCustom() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/samlssocustom/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, false); - - 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 '[email protected]'", - bodyTextContent.contains(claim + "[email protected]")); - } - - @org.junit.Test - public void testSAMLSSOCustomPostBinding() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/samlssocustompost/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, true); - - 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 '[email protected]'", - bodyTextContent.contains(claim + "[email protected]")); - } - - @org.junit.Test - public void testOIDC() throws Exception { - String url = "https://localhost:" + getRpHttpsPort() + "/oidc/secure/fedservlet"; - String user = "ALICE"; // realm b credentials - String password = "ECILA"; - - final String bodyTextContent = - loginOIDC(url, user, password, idpOIDCHttpsPort, 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 '[email protected]'", - bodyTextContent.contains(claim + "[email protected]")); - } - - 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); - final HtmlPage idpPage = webClient.getPage(url); - webClient.getOptions().setJavaScriptEnabled(true); - Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); - - // For some reason, redirecting back to the IdP for "realm a" is not working with htmlunit. So extract - // the parameters manually from the form, and access the IdP for "realm a" with them - DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); - - String wresult = null; - String wa = "wsignin1.0"; - String wctx = null; - String wtrealm = null; - for (DomElement result : results) { - if ("wresult".equals(result.getAttributeNS(null, "name"))) { - wresult = result.getAttributeNS(null, "value"); - } else if ("wctx".equals(result.getAttributeNS(null, "name"))) { - wctx = result.getAttributeNS(null, "value"); - } else if ("wtrealm".equals(result.getAttributeNS(null, "name"))) { - wtrealm = result.getAttributeNS(null, "value"); - } - } - Assert.assertTrue(wctx != null && wresult != null && wtrealm != null); - webClient.close(); - - // Invoke on the IdP for "realm a" - final WebClient webClient2 = new WebClient(); - webClient2.setCookieManager(cookieManager); - webClient2.getOptions().setUseInsecureSSL(true); - - String url2 = "https://localhost:" + rpIdpPort + "/fediz-idp/federation?"; - url2 += "wctx=" + wctx + "&"; - url2 += "wa=" + wa + "&"; - url2 += "wtrealm=" + URLEncoder.encode(wtrealm, "UTF8") + "&"; - url2 += "wresult=" + URLEncoder.encode(wresult, "UTF8") + "&"; - - webClient2.getOptions().setJavaScriptEnabled(false); - final HtmlPage idpPage2 = webClient2.getPage(url2); - webClient2.getOptions().setJavaScriptEnabled(true); - Assert.assertEquals("IDP SignIn Response Form", idpPage2.getTitleText()); - - // Now redirect back to the RP - final HtmlForm form2 = idpPage2.getFormByName("signinresponseform"); - - final HtmlSubmitInput button2 = form2.getInputByName("_eventId_submit"); - - final HtmlPage rpPage = button2.click(); - Assert.assertEquals("WS Federation Systests Examples", rpPage.getTitleText()); - - webClient2.close(); - return rpPage.getBody().getTextContent(); - } - - 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("signinresponseform"); - - final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - - final HtmlPage rpPage = button.click(); - Assert.assertEquals("WS Federation Systests Examples", rpPage.getTitleText()); - - webClient.close(); - return rpPage.getBody().getTextContent(); - } - - 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("signinresponseform"); - - final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); - - final HtmlPage rpPage = button.click(); - Assert.assertEquals("WS Federation Systests Examples", rpPage.getTitleText()); - - webClient.close(); - return rpPage.getBody().getTextContent(); - } -}
http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java ---------------------------------------------------------------------- diff --git a/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java b/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java new file mode 100644 index 0000000..3ebd4c0 --- /dev/null +++ b/systests/federation/wsfed/src/test/java/org/apache/cxf/fediz/systests/federation/wsfed/WSFedTest.java @@ -0,0 +1,550 @@ +/** + * 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.wsfed; + + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLEncoder; +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.DomElement; +import com.gargoylesoftware.htmlunit.html.DomNodeList; +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 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.tomcat8.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; + +/** + * This is a test for federation using a WS-Federation enabled web application. 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) + * - SAML SSO (custom webapp - supports POST binding as well) + * - OIDC (custom webapp) + */ +public class WSFedTest { + + private enum ServerType { + IDP, REALMB, SAMLSSO, 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 idpSamlSSOServer; + 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); + idpSamlSSOServer = startServer(ServerType.SAMLSSO, idpSamlSSOHttpsPort); + 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.SAMLSSO) { + server.getHost().setAppBase("tomcat/idpsamlsso/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.SAMLSSO) { + File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "idpsaml"); + server.addWebapp("/idp", 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(), "simpleWebapp"); + Context cxt = server.addWebapp("/wsfed", rpWebapp.getAbsolutePath()); + + FederationAuthenticator fa = new FederationAuthenticator(); + fa.setConfigFile(currentDir + File.separator + "target" + File.separator + + "test-classes" + File.separator + "fediz_config_wsfed.xml"); + cxt.getPipeline().addValve(fa); + + rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); + cxt = server.addWebapp("/samlsso", rpWebapp.getAbsolutePath()); + cxt.getPipeline().addValve(fa); + + rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); + cxt = server.addWebapp("/samlssocustom", rpWebapp.getAbsolutePath()); + cxt.getPipeline().addValve(fa); + + rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); + cxt = server.addWebapp("/samlssocustompost", rpWebapp.getAbsolutePath()); + cxt.getPipeline().addValve(fa); + + rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "simpleWebapp"); + cxt = server.addWebapp("/oidc", rpWebapp.getAbsolutePath()); + cxt.getPipeline().addValve(fa); + } + + server.start(); + + return server; + } + + @AfterClass + public static void cleanup() { + shutdownServer(idpServer); + shutdownServer(idpRealmbServer); + shutdownServer(idpSamlSSOServer); + 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() + "/wsfed/secure/fedservlet"; + // 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(), 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 '[email protected]'", + bodyTextContent.contains(claim + "[email protected]")); + } + + @org.junit.Test + public void testSAMLSSOFedizIdP() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/samlsso/secure/fedservlet"; + // 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("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 '[email protected]'", + bodyTextContent.contains(claim + "[email protected]")); + } + + @org.junit.Test + public void testSAMLSSOCustom() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/samlssocustom/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, false); + + 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 '[email protected]'", + bodyTextContent.contains(claim + "[email protected]")); + } + + @org.junit.Test + public void testSAMLSSOCustomPostBinding() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/samlssocustompost/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, true); + + 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 '[email protected]'", + bodyTextContent.contains(claim + "[email protected]")); + } + + @org.junit.Test + public void testOIDC() throws Exception { + String url = "https://localhost:" + getRpHttpsPort() + "/oidc/secure/fedservlet"; + String user = "ALICE"; // realm b credentials + String password = "ECILA"; + + final String bodyTextContent = + loginOIDC(url, user, password, idpOIDCHttpsPort, 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 '[email protected]'", + bodyTextContent.contains(claim + "[email protected]")); + } + + 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); + final HtmlPage idpPage = webClient.getPage(url); + webClient.getOptions().setJavaScriptEnabled(true); + Assert.assertEquals("IDP SignIn Response Form", idpPage.getTitleText()); + + // For some reason, redirecting back to the IdP for "realm a" is not working with htmlunit. So extract + // the parameters manually from the form, and access the IdP for "realm a" with them + DomNodeList<DomElement> results = idpPage.getElementsByTagName("input"); + + String wresult = null; + String wa = "wsignin1.0"; + String wctx = null; + String wtrealm = null; + for (DomElement result : results) { + if ("wresult".equals(result.getAttributeNS(null, "name"))) { + wresult = result.getAttributeNS(null, "value"); + } else if ("wctx".equals(result.getAttributeNS(null, "name"))) { + wctx = result.getAttributeNS(null, "value"); + } else if ("wtrealm".equals(result.getAttributeNS(null, "name"))) { + wtrealm = result.getAttributeNS(null, "value"); + } + } + Assert.assertTrue(wctx != null && wresult != null && wtrealm != null); + webClient.close(); + + // Invoke on the IdP for "realm a" + final WebClient webClient2 = new WebClient(); + webClient2.setCookieManager(cookieManager); + webClient2.getOptions().setUseInsecureSSL(true); + + String url2 = "https://localhost:" + rpIdpPort + "/fediz-idp/federation?"; + url2 += "wctx=" + wctx + "&"; + url2 += "wa=" + wa + "&"; + url2 += "wtrealm=" + URLEncoder.encode(wtrealm, "UTF8") + "&"; + url2 += "wresult=" + URLEncoder.encode(wresult, "UTF8") + "&"; + + webClient2.getOptions().setJavaScriptEnabled(false); + final HtmlPage idpPage2 = webClient2.getPage(url2); + webClient2.getOptions().setJavaScriptEnabled(true); + Assert.assertEquals("IDP SignIn Response Form", idpPage2.getTitleText()); + + // Now redirect back to the RP + final HtmlForm form2 = idpPage2.getFormByName("signinresponseform"); + + final HtmlSubmitInput button2 = form2.getInputByName("_eventId_submit"); + + final HtmlPage rpPage = button2.click(); + Assert.assertEquals("WS Federation Systests Examples", rpPage.getTitleText()); + + webClient2.close(); + return rpPage.getBody().getTextContent(); + } + + 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("signinresponseform"); + + final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); + + final HtmlPage rpPage = button.click(); + Assert.assertEquals("WS Federation Systests Examples", rpPage.getTitleText()); + + webClient.close(); + return rpPage.getBody().getTextContent(); + } + + 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("signinresponseform"); + + final HtmlSubmitInput button = form.getInputByName("_eventId_submit"); + + final HtmlPage rpPage = button.click(); + Assert.assertEquals("WS Federation Systests Examples", rpPage.getTitleText()); + + webClient.close(); + return rpPage.getBody().getTextContent(); + } +} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/idp/pom.xml ---------------------------------------------------------------------- diff --git a/systests/idp/pom.xml b/systests/idp/pom.xml index 1b7adb5..a9f3db2 100644 --- a/systests/idp/pom.xml +++ b/systests/idp/pom.xml @@ -203,7 +203,7 @@ <java.util.logging.config.file>${basedir}/target/test-classes/logging.properties</java.util.logging.config.file> </systemPropertyVariables> <includes> - <include>**/idp/**</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--> @@ -218,16 +218,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <inherited>true</inherited> - <configuration> - <excludes> - <exclude>**/idp/**</exclude> - </excludes> - </configuration> - </plugin> </plugins> </build> </project> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/jetty9/pom.xml ---------------------------------------------------------------------- diff --git a/systests/jetty9/pom.xml b/systests/jetty9/pom.xml index 0358402..85b9932 100644 --- a/systests/jetty9/pom.xml +++ b/systests/jetty9/pom.xml @@ -246,7 +246,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>-XX:MaxPermSize=512M</argLine> </configuration> @@ -260,16 +260,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> http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificatePreAuthSpringTest.java ---------------------------------------------------------------------- diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificatePreAuthSpringTest.java b/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificatePreAuthSpringTest.java deleted file mode 100644 index 8454775..0000000 --- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificatePreAuthSpringTest.java +++ /dev/null @@ -1,154 +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 org.apache.catalina.LifecycleState; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.xml.XmlConfiguration; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; - -/** - * In this test-case, the IdP is set up to require client authentication, rather than authenticating using a - * username + password, or via Kerberos. - */ -public class ClientCertificatePreAuthSpringTest extends AbstractClientCertTests { - - static String idpHttpsPort; - static String rpHttpsPort; - - private static Server rpServer; - private static Tomcat idpServer; - - @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.springframework.security", "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); - rpHttpsPort = System.getProperty("rp.https.port"); - Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); - - initIdp(); - - try { - Resource testServerConfig = Resource.newSystemResource("rp-client-cert-server.xml"); - XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream()); - rpServer = (Server)configuration.configure(); - rpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void cleanup() { - try { - if (idpServer != null && idpServer.getServer() != null - && idpServer.getServer().getState() != LifecycleState.DESTROYED) { - if (idpServer.getServer().getState() != LifecycleState.STOPPED) { - idpServer.stop(); - } - idpServer.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - if (rpServer != null && rpServer.isStarted()) { - try { - rpServer.stop(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private static void initIdp() { - try { - idpServer = new Tomcat(); - idpServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - String baseDir = currentDir + File.separator + "target"; - idpServer.setBaseDir(baseDir); - - 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); - - File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp-sts"); - idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); - - File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp"); - idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); - - idpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - - @Override - public String getIdpHttpsPort() { - return idpHttpsPort; - } - - @Override - public String getRpHttpsPort() { - return rpHttpsPort; - } - - @Override - public String getServletContextName() { - return "fedizspringhelloworld"; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificateTest.java ---------------------------------------------------------------------- diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificateTest.java b/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificateTest.java deleted file mode 100644 index d4f66b1..0000000 --- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/ClientCertificateTest.java +++ /dev/null @@ -1,154 +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 org.apache.catalina.LifecycleState; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.xml.XmlConfiguration; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; - -/** - * In this test-case, the IdP is set up to require client authentication, rather than authenticating using a - * username + password, or via Kerberos. - */ -public class ClientCertificateTest extends AbstractClientCertTests { - - static String idpHttpsPort; - static String rpHttpsPort; - - private static Server rpServer; - private static Tomcat idpServer; - - @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.springframework.security", "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); - rpHttpsPort = System.getProperty("rp.https.port"); - Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); - - initIdp(); - - try { - Resource testServerConfig = Resource.newSystemResource("rp-client-cert-server.xml"); - XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream()); - rpServer = (Server)configuration.configure(); - rpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @AfterClass - public static void cleanup() { - try { - if (idpServer != null && idpServer.getServer() != null - && idpServer.getServer().getState() != LifecycleState.DESTROYED) { - if (idpServer.getServer().getState() != LifecycleState.STOPPED) { - idpServer.stop(); - } - idpServer.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - if (rpServer != null && rpServer.isStarted()) { - try { - rpServer.stop(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - private static void initIdp() { - try { - idpServer = new Tomcat(); - idpServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - String baseDir = currentDir + File.separator + "target"; - idpServer.setBaseDir(baseDir); - - 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); - - File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp-sts"); - idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); - - File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp"); - idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); - - idpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - - @Override - public String getIdpHttpsPort() { - return idpHttpsPort; - } - - @Override - public String getRpHttpsPort() { - return rpHttpsPort; - } - - @Override - public String getServletContextName() { - return "fedizhelloworld"; - } - -} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/HOKCallbackHandler.java ---------------------------------------------------------------------- diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/HOKCallbackHandler.java b/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/HOKCallbackHandler.java deleted file mode 100644 index a323696..0000000 --- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/HOKCallbackHandler.java +++ /dev/null @@ -1,48 +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.IOException; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.UnsupportedCallbackException; - -import org.apache.cxf.fediz.core.spi.WReqCallback; - -public class HOKCallbackHandler implements CallbackHandler { - - static final String HOK_WREQ = - "<RequestSecurityToken xmlns=\"http://docs.oasis-open.org/ws-sx/ws-trust/200512\">" - + "<KeyType>http://docs.oasis-open.org/ws-sx/ws-trust/200512/PublicKey</KeyType>" - + "</RequestSecurityToken>"; - - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { - for (int i = 0; i < callbacks.length; i++) { - if (callbacks[i] instanceof WReqCallback) { - WReqCallback callback = (WReqCallback) callbacks[i]; - callback.setWreq(HOK_WREQ); - } else { - throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback"); - } - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyPreAuthSpringTest.java ---------------------------------------------------------------------- diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyPreAuthSpringTest.java b/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyPreAuthSpringTest.java deleted file mode 100644 index ab19290..0000000 --- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyPreAuthSpringTest.java +++ /dev/null @@ -1,142 +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 org.apache.catalina.LifecycleState; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; - - -public class JettyPreAuthSpringTest extends AbstractTests { - - static String idpHttpsPort; - static String rpHttpsPort; - - private static Tomcat idpServer; - - @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"); - - 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); - - initIdp(); - - JettyUtils.initRpServer(); - JettyUtils.startRpServer(); - } - - @AfterClass - public static void cleanup() { - try { - if (idpServer != null && idpServer.getServer() != null - && idpServer.getServer().getState() != LifecycleState.DESTROYED) { - if (idpServer.getServer().getState() != LifecycleState.STOPPED) { - idpServer.stop(); - } - idpServer.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - JettyUtils.stopRpServer(); - } - - private static void initIdp() { - try { - idpServer = new Tomcat(); - idpServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - String baseDir = currentDir + File.separator + "target"; - idpServer.setBaseDir(baseDir); - - 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); - - File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp-sts"); - idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); - - File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp"); - idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); - - idpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - - @Override - public String getIdpHttpsPort() { - return idpHttpsPort; - } - - @Override - public String getRpHttpsPort() { - return rpHttpsPort; - } - - @Override - public String getServletContextName() { - return "fedizspringhelloworld"; - } - - @Ignore("This tests is currently failing on Jetty") - @Override - public void testConcurrentRequests() throws Exception { - // super.testConcurrentRequests(); - } - -} http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/cc76fc31/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java ---------------------------------------------------------------------- diff --git a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java b/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java deleted file mode 100644 index 5c7adee..0000000 --- a/systests/jetty9/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java +++ /dev/null @@ -1,141 +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 org.apache.catalina.LifecycleState; -import org.apache.catalina.connector.Connector; -import org.apache.catalina.startup.Tomcat; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; - - -public class JettyTest extends AbstractTests { - - static String idpHttpsPort; - static String rpHttpsPort; - - private static Tomcat idpServer; - - @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", "debug"); - System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); - 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.springframework.security", "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); - rpHttpsPort = System.getProperty("rp.https.port"); - Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort); - - initIdp(); - - JettyUtils.initRpServer(); - JettyUtils.startRpServer(); - } - - @AfterClass - public static void cleanup() { - try { - if (idpServer != null && idpServer.getServer() != null - && idpServer.getServer().getState() != LifecycleState.DESTROYED) { - if (idpServer.getServer().getState() != LifecycleState.STOPPED) { - idpServer.stop(); - } - idpServer.destroy(); - } - } catch (Exception e) { - e.printStackTrace(); - } - - JettyUtils.stopRpServer(); - } - - private static void initIdp() { - try { - idpServer = new Tomcat(); - idpServer.setPort(0); - String currentDir = new File(".").getCanonicalPath(); - String baseDir = currentDir + File.separator + "target"; - idpServer.setBaseDir(baseDir); - - 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); - - File stsWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp-sts"); - idpServer.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath()); - - File idpWebapp = new File(baseDir + File.separator + idpServer.getHost().getAppBase(), "fediz-idp"); - idpServer.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath()); - - idpServer.start(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public String getIdpHttpsPort() { - return idpHttpsPort; - } - - @Override - public String getRpHttpsPort() { - return rpHttpsPort; - } - - @Override - public String getServletContextName() { - return "fedizhelloworld"; - } - - @Ignore("This tests is currently failing on Jetty") - @Override - public void testConcurrentRequests() throws Exception { - // super.testConcurrentRequests(); - } - -}
