Skip to content

Commit

Permalink
FEDIZ-211 - Local IdP redirection (after token expiry) is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
coheigea committed Oct 5, 2017
1 parent a4b989c commit c5d3cae
Show file tree
Hide file tree
Showing 8 changed files with 1,480 additions and 2 deletions.
24 changes: 24 additions & 0 deletions systests/spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,30 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-entities-to-idp</id>
<phase>generate-test-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/tomcat/idp/webapps/fediz-idp/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/test/resources/realma</directory>
<includes>
<include>entities-realma.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<inherited>true</inherited>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* 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 javax.servlet.ServletException;

import com.gargoylesoftware.htmlunit.CookieManager;
import com.gargoylesoftware.htmlunit.WebClient;

import org.apache.catalina.LifecycleException;
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;

/**
* Test what happens when the IdP token expires. This is "mocked" by setting wfresh to "0" in the plugin configuration.
*/
public class TokenExpiryTest {

static String idpHttpsPort;
static String rpHttpsPort;

private static Tomcat idpServer;
private static Tomcat rpServer;

@BeforeClass
public static void init() throws Exception {
idpHttpsPort = System.getProperty("idp.https.port");
Assert.assertNotNull("Property 'idp.https.port' null", idpHttpsPort);
rpHttpsPort = System.getProperty("rp.https.port");
Assert.assertNotNull("Property 'rp.https.port' null", rpHttpsPort);

idpServer = startServer(true, idpHttpsPort);
rpServer = startServer(false, rpHttpsPort);
}

private static Tomcat startServer(boolean idp, String port)
throws ServletException, LifecycleException, IOException {
Tomcat server = new Tomcat();
server.setPort(0);
String currentDir = new File(".").getCanonicalPath();
String baseDir = currentDir + File.separator + "target";
server.setBaseDir(baseDir);

if (idp) {
server.getHost().setAppBase("tomcat/idp/webapps");
} else {
server.getHost().setAppBase("tomcat/rp/webapps");
}
server.getHost().setAutoDeploy(true);
server.getHost().setDeployOnStartup(true);

Connector httpsConnector = new Connector();
httpsConnector.setPort(Integer.parseInt(port));
httpsConnector.setSecure(true);
httpsConnector.setScheme("https");
httpsConnector.setAttribute("keyAlias", "mytomidpkey");
httpsConnector.setAttribute("keystorePass", "tompass");
httpsConnector.setAttribute("keystoreFile", "test-classes/server.jks");
httpsConnector.setAttribute("truststorePass", "tompass");
httpsConnector.setAttribute("truststoreFile", "test-classes/server.jks");
httpsConnector.setAttribute("clientAuth", "want");
// httpsConnector.setAttribute("clientAuth", "false");
httpsConnector.setAttribute("sslProtocol", "TLS");
httpsConnector.setAttribute("SSLEnabled", true);

server.getService().addConnector(httpsConnector);

if (idp) {
File stsWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp-sts");
server.addWebapp("/fediz-idp-sts", stsWebapp.getAbsolutePath());

File idpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(), "fediz-idp");
server.addWebapp("/fediz-idp", idpWebapp.getAbsolutePath());
} else {
File rpWebapp = new File(baseDir + File.separator + server.getHost().getAppBase(),
"fediz-systests-webapps-spring");
server.addWebapp("/fedizhelloworld_wfresh", rpWebapp.getAbsolutePath());
}

server.start();

return server;
}

@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;
}


@org.junit.Test
public void testTokenExpiry() throws Exception {
// 1. Login
String url = "https://localhost:" + getRpHttpsPort() + "/fedizhelloworld_wfresh"
+ "/secure/fedservlet";
String user = "alice";
String password = "ecila";

CookieManager cookieManager = new CookieManager();

// 1. Login
HTTPTestUtils.loginWithCookieManager(url, user, password, getIdpHttpsPort(), cookieManager);

// 2. Sign out of the service (but not the Idp)
final WebClient webClient = new WebClient();
webClient.setCookieManager(cookieManager);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getPage(url + "?wa=wsignoutcleanup1.0");
webClient.close();

// 3. Sign back in to the service provider. This time it will get a new IdP token due to wfresh=0.
HTTPTestUtils.loginWithCookieManager(url, user, password, getIdpHttpsPort(), cookieManager);
}
}
39 changes: 37 additions & 2 deletions systests/spring/src/test/resources/fediz_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<issuer>https://localhost:${idp.https.port}/fediz-idp/federation</issuer>
<roleDelimiter>,</roleDelimiter>
<roleURI>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role</roleURI>
<reply>/j_spring_fediz_security_check</reply>
<reply>/j_spring_fediz_security_check</reply>
<!--<authenticationType type="String">some auth type</authenticationType>-->
<!--<homeRealm type="Class">org.apache.fediz.realm.MyHomeRealm</homeRealm>-->
<!--<freshness>0</freshness>-->
Expand Down Expand Up @@ -99,6 +99,41 @@
</protocol>
<logoutURL>/secure/logout</logoutURL>
<logoutRedirectTo>/index.html</logoutRedirectTo>
</contextConfig>
</contextConfig>
<contextConfig name="/fedizhelloworld_wfresh">
<audienceUris>
<audienceItem>urn:org:apache:cxf:fediz:fedizhelloworld</audienceItem>
</audienceUris>
<certificateStores>
<trustManager>
<keyStore file="clienttrust.jks" password="storepass" type="JKS" />
</trustManager>
</certificateStores>
<trustedIssuers>
<issuer certificateValidation="PeerTrust" />
</trustedIssuers>
<maximumClockSkew>1000</maximumClockSkew>
<signingKey keyAlias="mytomidpkey" keyPassword="tompass">
<keyStore file="server.jks" password="tompass" type="JKS" />
</signingKey>
<protocol xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="federationProtocolType" version="1.0.0">
<realm>urn:org:apache:cxf:fediz:fedizhelloworld</realm>
<issuer>https://localhost:${idp.https.port}/fediz-idp/federation</issuer>
<roleDelimiter>,</roleDelimiter>
<roleURI>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role</roleURI>
<reply>/j_spring_fediz_security_check</reply>
<freshness>0</freshness>
<homeRealm type="String">urn:org:apache:cxf:fediz:idp:realm-A</homeRealm>
<claimTypesRequested>
<claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role" optional="false" />
<claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname" optional="true" />
<claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname" optional="true" />
<claimType type="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" optional="true" />
</claimTypesRequested>
</protocol>
<logoutURL>/secure/logout</logoutURL>
<logoutRedirectTo>/index.html</logoutRedirectTo>
</contextConfig>
</FedizConfig>

Loading

0 comments on commit c5d3cae

Please sign in to comment.