cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1432495 - in /cxf/fediz/trunk/systests: ./ idp/ idp/src/main/resources/ idp/src/main/webapp/WEB-INF/ simpleWebapp/src/main/java/org/apache/cxf/fediz/example/ simpleWebapp/src/main/webapp/WEB-INF/ sts/ sts/src/main/java/org/apache/cxf/fediz...
Date Sat, 12 Jan 2013 19:59:55 GMT
Author: owulff
Date: Sat Jan 12 19:59:54 2013
New Revision: 1432495

URL: http://svn.apache.org/viewvc?rev=1432495&view=rev
Log:
[FEDIZ-37] Dynamically assign ports for unit testing to avoid port conflict

Added:
    cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/integrationtests/
    cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java
Removed:
    cxf/fediz/trunk/systests/idp/pom.xml
    cxf/fediz/trunk/systests/idp/src/main/resources/log4j.properties
    cxf/fediz/trunk/systests/idp/src/main/resources/logging.properties
    cxf/fediz/trunk/systests/idp/src/main/webapp/WEB-INF/applicationContext.xml
    cxf/fediz/trunk/systests/idp/src/main/webapp/WEB-INF/web.xml
    cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationFilter.java
    cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/SecurityTokenThreadLocal.java
    cxf/fediz/trunk/systests/sts/pom.xml
    cxf/fediz/trunk/systests/sts/src/main/java/org/apache/cxf/fediz/service/sts/FileClaimsHandler.java
    cxf/fediz/trunk/systests/sts/src/main/java/org/apache/cxf/fediz/service/sts/PasswordCallbackHandler.java
    cxf/fediz/trunk/systests/sts/src/main/java/org/apache/cxf/fediz/service/sts/UsernamePasswordCallbackHandler.java
    cxf/fediz/trunk/systests/sts/src/main/resources/log4j.properties
    cxf/fediz/trunk/systests/sts/src/main/resources/logging.properties
    cxf/fediz/trunk/systests/sts/src/main/resources/stsKeystore.properties
    cxf/fediz/trunk/systests/sts/src/main/resources/stsstore.jks
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/cxf-encrypted-ut.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/cxf-servlet.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/cxf-transport.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/cxf-ut.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/cxf-x509.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/passwords.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/userClaims.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/web.xml
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4-service.wsdl
    cxf/fediz/trunk/systests/sts/src/main/webapp/WEB-INF/wsdl/ws-trust-1.4.wsdl
    cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/JettyTest.java
Modified:
    cxf/fediz/trunk/systests/pom.xml
    cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
    cxf/fediz/trunk/systests/simpleWebapp/src/main/webapp/WEB-INF/web.xml
    cxf/fediz/trunk/systests/tests/pom.xml
    cxf/fediz/trunk/systests/tests/src/test/resources/jetty/idp-server.xml

Modified: cxf/fediz/trunk/systests/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/systests/pom.xml?rev=1432495&r1=1432494&r2=1432495&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/pom.xml (original)
+++ cxf/fediz/trunk/systests/pom.xml Sat Jan 12 19:59:54 2013
@@ -56,8 +56,10 @@
 
 
    <modules>
+<!--
       <module>idp</module>
       <module>sts</module>
+-->
       <module>simpleWebapp</module>
 <!--
       <module>springWebapp</module>

Modified: cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java?rev=1432495&r1=1432494&r2=1432495&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
(original)
+++ cxf/fediz/trunk/systests/simpleWebapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
Sat Jan 12 19:59:54 2013
@@ -21,7 +21,6 @@ package org.apache.cxf.fediz.example;
 
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.security.Principal;
 import java.util.Arrays;
 import java.util.List;
@@ -30,15 +29,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 
-import org.w3c.dom.Element;
-
-import org.apache.commons.lang3.StringEscapeUtils;
 import org.apache.cxf.fediz.core.Claim;
 import org.apache.cxf.fediz.core.ClaimCollection;
 import org.apache.cxf.fediz.core.FederationPrincipal;
@@ -58,57 +49,31 @@ public class FederationServlet extends H
         PrintWriter out = response.getWriter();
 
         out.println("<html>");
-        out.println("<head><title>WS Federation Tomcat Examples</title></head>");
+        out.println("<head><title>WS Federation Systests Examples</title></head>");
         out.println("<body>");
-        out.println("<h1>Hello World</h1>");
-        out.println("Hello world<br>");
-        out.println("Request url: " + request.getRequestURL().toString() + "<p>");
-
+        out.println("<p>Request url: " + request.getRequestURL().toString() + "</p>");
 
-        out.println("<br><b>User</b><p>");
+        out.print("<p>userPrincipal=");
         Principal p = request.getUserPrincipal();
         if (p != null) {
-            out.println("Principal: " + p.getName() + "<p>");
+            out.print(p.getName());
         }
-
-        out.println("<br><b>Roles</b><p>");
+        out.println("</p>");
+        
         List<String> roleListToCheck = Arrays.asList("Admin", "Manager", "User", "Authenticated");
         for (String item: roleListToCheck) {
-            out.println("Has role '" + item + "': " + ((request.isUserInRole(item)) ? "<b>yes</b>"
: "no") + "<p>");
+            out.println("<p>role:" + item + "=" + ((request.isUserInRole(item)) ? "true"
: "false") + "</p>");
         }
 
         if (p instanceof FederationPrincipal) {
             FederationPrincipal fp = (FederationPrincipal)p;
-
-            out.println("<br><b>Claims</b><p>");
+            
             ClaimCollection claims = fp.getClaims();
             for (Claim c: claims) {
-                out.println(c.getClaimType().toString() + ": " + c.getValue() + "<p>");
+                out.println("<p>" + c.getClaimType().toString() + "=" + c.getValue()
+ "</p>");
             }
-        } else {
-            out.println("Principal is not instance of FederationPrincipal");
         }
-
-        Element el = SecurityTokenThreadLocal.getToken();
-        if (el != null) {
-            out.println("<p>Bootstrap token...");
-            String token = null;
-            try {
-                TransformerFactory transFactory = TransformerFactory.newInstance();
-                Transformer transformer = transFactory.newTransformer();
-                StringWriter buffer = new StringWriter();
-                transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
-                transformer.transform(new DOMSource(el),
-                                      new StreamResult(buffer));
-                token = buffer.toString();
-                out.println("<p>" + StringEscapeUtils.escapeXml(token));
-            } catch (Exception ex) {
-                out.println("<p>Failed to transform cached element to string: " + ex.toString());
-            }
-        } else {
-            out.println("<p>Bootstrap token not cached in thread local storage");
-        }
-
+        
         out.println("</body>");
     }
 

Modified: cxf/fediz/trunk/systests/simpleWebapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/systests/simpleWebapp/src/main/webapp/WEB-INF/web.xml?rev=1432495&r1=1432494&r2=1432495&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/simpleWebapp/src/main/webapp/WEB-INF/web.xml (original)
+++ cxf/fediz/trunk/systests/simpleWebapp/src/main/webapp/WEB-INF/web.xml Sat Jan 12 19:59:54
2013
@@ -3,27 +3,8 @@
                       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
 	version="3.0" metadata-complete="true">
 
-	<description>
-    WS Federation Tomcat Example
-    </description>
-	<display-name>WS Federation Tomcat Example</display-name>
-
-	<filter>
-		<filter-name>FederationFilter</filter-name>
-		<filter-class>org.apache.cxf.fediz.example.FederationFilter</filter-class>
-		<!--
-		<init-param>
-			<param-name>security.token.attribute</param-name>
-			<param-value>org.apache.fediz.SECURITY_TOKEN</param-value>
-		</init-param>
-		-->
-	</filter>
-
-	<!-- now map this filter to a URL-pattern -->
-	<filter-mapping>
-		<filter-name>FederationFilter</filter-name>
-		<url-pattern>/*</url-pattern>
-	</filter-mapping>
+	<description>WS Federation Systests Example</description>
+	<display-name>WS Federation Systests Example</display-name>
 
 	<servlet>
 		<servlet-name>FederationServlet</servlet-name>
@@ -34,6 +15,21 @@
 		<servlet-name>FederationServlet</servlet-name>
 		<url-pattern>/secure/fedservlet</url-pattern>
 	</servlet-mapping>
+	
+	<servlet-mapping>
+		<servlet-name>FederationServlet</servlet-name>
+		<url-pattern>/secure/admin/fedservlet</url-pattern>
+	</servlet-mapping>
+	
+	<servlet-mapping>
+		<servlet-name>FederationServlet</servlet-name>
+		<url-pattern>/secure/user/fedservlet</url-pattern>
+	</servlet-mapping>
+	
+	<servlet-mapping>
+		<servlet-name>FederationServlet</servlet-name>
+		<url-pattern>/secure/manager/fedservlet</url-pattern>
+	</servlet-mapping>
 
 	<security-role>
 		<role-name>Manager</role-name>
@@ -57,7 +53,39 @@
 			<role-name>*</role-name>
 		</auth-constraint>
 	</security-constraint>
+	
+	<security-constraint>
+		<web-resource-collection>
+			<web-resource-name>Protected Admin Area</web-resource-name>
+			<url-pattern>/secure/admin/*</url-pattern>
+		</web-resource-collection>
+		<auth-constraint>
+			<role-name>Admin</role-name>
+		</auth-constraint>
+	</security-constraint>
 
+	<security-constraint>
+		<web-resource-collection>
+			<web-resource-name>Protected Manager Area</web-resource-name>
+			<url-pattern>/secure/manager/*</url-pattern>
+		</web-resource-collection>
+		<auth-constraint>
+			<role-name>Manager</role-name>
+		</auth-constraint>
+	</security-constraint>
+	
+	<security-constraint>
+		<web-resource-collection>
+			<web-resource-name>Protected User Area</web-resource-name>
+			<url-pattern>/secure/user/*</url-pattern>
+		</web-resource-collection>
+		<auth-constraint>
+			<role-name>User</role-name>
+			<role-name>Admin</role-name>
+			<role-name>Manager</role-name>
+		</auth-constraint>
+	</security-constraint>	
+	
 	<login-config>
 		<auth-method>WSFED</auth-method>
 		<realm-name>WSFED</realm-name>

Modified: cxf/fediz/trunk/systests/tests/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/systests/tests/pom.xml?rev=1432495&r1=1432494&r2=1432495&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/tests/pom.xml (original)
+++ cxf/fediz/trunk/systests/tests/pom.xml Sat Jan 12 19:59:54 2013
@@ -31,6 +31,7 @@
     <packaging>jar</packaging>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
     </properties>
     <dependencies>
         <dependency>
@@ -69,28 +70,20 @@
         </dependency>
         <dependency>
             <groupId>org.apache.cxf.fediz</groupId>
-            <artifactId>fediz-core</artifactId>
-            <version>${project.version}</version>
-            <type>jar</type>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf.fediz</groupId>
             <artifactId>fediz-jetty</artifactId>
             <version>${project.version}</version>
-            <type>jar</type>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>
             <artifactId>httpclient</artifactId>
-            <version>${httpclient.version}</version>
+            <version>4.2.2</version>
             <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>net.htmlparser.jericho</groupId>
             <artifactId>jericho-html</artifactId>
-            <version>${jericho.version}</version>
+            <version>3.2</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
@@ -130,15 +123,15 @@
                         <configuration>
                             <artifactItems>
                                 <artifactItem>
-                                    <groupId>org.apache.cxf.fediz.systests</groupId>
-                                    <artifactId>systests-fediz-idp</artifactId>
+                                    <groupId>org.apache.cxf.fediz</groupId>
+                                    <artifactId>fediz-idp</artifactId>
                                     <version>${project.version}</version>
                                     <type>war</type>
                                     <overWrite>true</overWrite>
                                 </artifactItem>
                                 <artifactItem>
-                                    <groupId>org.apache.cxf.fediz.systests</groupId>
-                                    <artifactId>systests-fediz-idp-sts</artifactId>
+                                    <groupId>org.apache.cxf.fediz</groupId>
+                                    <artifactId>fediz-idp-sts</artifactId>
                                     <version>${project.version}</version>
                                     <type>war</type>
                                     <overWrite>true</overWrite>
@@ -161,13 +154,46 @@
                 </executions>
             </plugin>
             <plugin>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <version>2.12.2</version>
+                <inherited>true</inherited>
+                <executions>
+                    <execution>
+                        <id>integration-test</id>
+                        <phase>integration-test</phase>
+                        <goals>
+                            <goal>integration-test</goal>
+                        </goals>
+                        <configuration>
+                            <skip>false</skip>
+                            <systemPropertyVariables>
+                                <wt.headless>true</wt.headless>
+                                <idp.https.port>${idp.https.port}</idp.https.port>
+                                <rp.https.port>${rp.https.port}</rp.https.port>
+                            </systemPropertyVariables>
+                            <includes>
+                                <include>**/integrationtests/**</include>
+                            </includes>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <id>verify</id>
+                        <phase>verify</phase>
+                        <goals>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.12</version>
+                <inherited>true</inherited>
                 <configuration>
-                    <systemPropertyVariables>
-                        <idp.https.port>${idp.https.port}</idp.https.port>
-                        <rp.https.port>${rp.https.port}</rp.https.port>
-                    </systemPropertyVariables>
+                    <excludes>
+                        <exclude>**/integrationtests/**</exclude>
+                    </excludes>
                 </configuration>
             </plugin>
         </plugins>

Added: cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java?rev=1432495&view=auto
==============================================================================
--- cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java
(added)
+++ cxf/fediz/trunk/systests/tests/src/test/java/org/apache/cxf/fediz/integrationtests/JettyTest.java
Sat Jan 12 19:59:54 2013
@@ -0,0 +1,323 @@
+/**
+ * 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.FileInputStream;
+import java.security.KeyStore;
+import java.util.ArrayList;
+import java.util.List;
+
+import net.htmlparser.jericho.FormField;
+import net.htmlparser.jericho.FormFields;
+import net.htmlparser.jericho.Source;
+
+
+import org.apache.cxf.fediz.core.ClaimTypes;
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.LaxRedirectStrategy;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+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;
+
+
+public class JettyTest {
+
+    private static String idpHttpsPort;
+    private static String rpHttpsPort;
+    
+    private static Server idpServer;
+    private static Server 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", "debug");
+
+        System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
"debug");
+
+        idpHttpsPort = System.getProperty("idp.https.port");
+        Assert.assertNotNull(idpHttpsPort);
+        rpHttpsPort = System.getProperty("rp.https.port");
+        Assert.assertNotNull(rpHttpsPort);
+
+        initIdp();
+        Assert.assertTrue("IDP server not running", idpServer.isRunning());
+        initRp();
+        Assert.assertTrue("RP server not running", rpServer.isRunning());
+    }
+    
+    private static void initIdp() {
+        try {
+            Resource testServerConfig = Resource.newSystemResource("jetty/rp-server.xml");
+            XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
+            idpServer = (Server)configuration.configure();   
+            idpServer.start();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    private static void initRp() {
+        try {
+            Resource testServerConfig = Resource.newSystemResource("jetty/idp-server.xml");
+            XmlConfiguration configuration = new XmlConfiguration(testServerConfig.getInputStream());
+            rpServer = (Server)configuration.configure();
+            rpServer.start();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    /*
+    @org.junit.Test
+    @Ignore
+    public void testStart() throws Exception {
+        System.out.println(System.getProperty("jetty.home"));
+        System.out.println(Server.getVersion());
+        System.out.println(server.isRunning());
+    }
+    */
+
+    @org.junit.Test
+    public void testUserAlice() throws Exception {
+        String url = "https://localhost:" + rpHttpsPort + "/fedizhelloworld/secure/fedservlet";
+        String user = "alice";
+        String password = "ecila";
+        String response = sendHttpGet(url, user, password);
+        
+        Assert.assertTrue("Principal not " + user, response.indexOf("userPrincipal=" + user)
> 0);
+        Assert.assertTrue("User " + user + " does not have role Admin", response.indexOf("role:Admin=false")
> 0);
+        Assert.assertTrue("User " + user + " does not have role Manager", response.indexOf("role:Manager=false")
> 0);
+        Assert.assertTrue("User " + user + " must have role User", response.indexOf("role:User=true")
> 0);
+        
+        String claim = ClaimTypes.FIRSTNAME.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'Alice'",
+                          response.indexOf(claim + "=Alice") > 0);
+        claim = ClaimTypes.LASTNAME.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'Smith'",
+                          response.indexOf(claim + "=Smith") > 0);
+        claim = ClaimTypes.EMAILADDRESS.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'alice@mycompany.org'",
+                          response.indexOf(claim + "=alice@mycompany.org") > 0);
+        
+    }
+    
+    @org.junit.Test
+    public void testUserBob() throws Exception {
+        String url = "https://localhost:" + rpHttpsPort + "/fedizhelloworld/secure/fedservlet";
+        String user = "bob";
+        String password = "bob";
+        String response = sendHttpGet(url, user, password);
+        
+        Assert.assertTrue("Principal not " + user, response.indexOf("userPrincipal=" + user)
> 0);
+        Assert.assertTrue("User " + user + " does not have role Admin", response.indexOf("role:Admin=true")
> 0);
+        Assert.assertTrue("User " + user + " does not have role Manager", response.indexOf("role:Manager=true")
> 0);
+        Assert.assertTrue("User " + user + " must have role User", response.indexOf("role:User=true")
> 0);
+        
+        String claim = ClaimTypes.FIRSTNAME.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'Bob'",
+                          response.indexOf(claim + "=Bob") > 0);
+        claim = ClaimTypes.LASTNAME.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'Windsor'",
+                          response.indexOf(claim + "=Windsor") > 0);
+        claim = ClaimTypes.EMAILADDRESS.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'bobwindsor@idp.org'",
+                          response.indexOf(claim + "=bobwindsor@idp.org") > 0);
+    }
+    
+    @org.junit.Test
+    public void testUserTed() throws Exception {
+        String url = "https://localhost:" + rpHttpsPort + "/fedizhelloworld/secure/fedservlet";
+        String user = "ted";
+        String password = "det";
+        String response = sendHttpGet(url, user, password);
+        
+        Assert.assertTrue("Principal not " + user, response.indexOf("userPrincipal=" + user)
> 0);
+        Assert.assertTrue("User " + user + " does not have role Admin", response.indexOf("role:Admin=false")
> 0);
+        Assert.assertTrue("User " + user + " does not have role Manager", response.indexOf("role:Manager=false")
> 0);
+        Assert.assertTrue("User " + user + " must have role User", response.indexOf("role:User=false")
> 0);
+        
+        String claim = ClaimTypes.FIRSTNAME.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'Ted'",
+                          response.indexOf(claim + "=Ted") > 0);
+        claim = ClaimTypes.LASTNAME.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'Cooper'",
+                          response.indexOf(claim + "=Cooper") > 0);
+        claim = ClaimTypes.EMAILADDRESS.toString();
+        Assert.assertTrue("User " + user + " claim " + claim + " is not 'tcooper@hereiam.org'",
+                          response.indexOf(claim + "=tcooper@hereiam.org") > 0);
+    }
+    
+    @org.junit.Test
+    public void testUserAliceNoAccess() throws Exception {
+        String url = "https://localhost:" + rpHttpsPort + "/fedizhelloworld/secure/admin/fedservlet";
+        String user = "alice";
+        String password = "ecila";
+        sendHttpGet(url, user, password, 200, 403);        
+    }
+    
+    @org.junit.Ignore
+    @org.junit.Test
+    public void testUserAliceWrongPassword() throws Exception {
+        String url = "https://localhost:" + rpHttpsPort + "/fedizhelloworld/secure/fedservlet";
+        String user = "alice";
+        String password = "alice";
+        //[TODO] Fix IDP return code from 500 to 401
+        sendHttpGet(url, user, password, 500, 0);        
+    }
+    
+    @org.junit.Test
+    public void testUserTedNoAccess() throws Exception {
+        String url = "https://localhost:" + rpHttpsPort + "/fedizhelloworld/secure/admin/fedservlet";
+        String user = "ted";
+        String password = "det";
+        sendHttpGet(url, user, password, 200, 403);        
+    }
+    
+    private String sendHttpGet(String url, String user, String password) throws Exception
{
+        return sendHttpGet(url, user, password, 200, 200);
+    }
+    
+    private String sendHttpGet(String url, String user, String password, 
+                               int returnCodeIDP, int returnCodeRP) throws Exception {
+        DefaultHttpClient httpclient = new DefaultHttpClient();
+        try {
+            httpclient.getCredentialsProvider().setCredentials(
+                    new AuthScope("localhost", Integer.parseInt(idpHttpsPort)),
+                    new UsernamePasswordCredentials(user, password));
+
+            KeyStore trustStore  = KeyStore.getInstance(KeyStore.getDefaultType());
+            FileInputStream instream = new FileInputStream(new File("./target/test-classes/server.jks"));
+            try {
+                trustStore.load(instream, "tompass".toCharArray());
+            } finally {
+                try {
+                    instream.close();
+                } catch (Exception ex) {
+                    ex.printStackTrace();
+                }
+            }
+
+            SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
+            Scheme schIdp = new Scheme("https", Integer.parseInt(idpHttpsPort), socketFactory);
+            httpclient.getConnectionManager().getSchemeRegistry().register(schIdp);
+            Scheme schRp = new Scheme("https", Integer.parseInt(rpHttpsPort), socketFactory);
+            httpclient.getConnectionManager().getSchemeRegistry().register(schRp);
+
+            HttpGet httpget = new HttpGet(url);
+
+            HttpResponse response = httpclient.execute(httpget);
+            HttpEntity entity = response.getEntity();
+            
+            System.out.println(response.getStatusLine());
+            if (entity != null) {
+                System.out.println("Response content length: " + entity.getContentLength());
+            }
+            Assert.assertTrue("IDP HTTP Response code: " + response.getStatusLine().getStatusCode()
+                              + " [Expected: " + returnCodeIDP + "]",
+                              returnCodeIDP == response.getStatusLine().getStatusCode());
+            
+            if (response.getStatusLine().getStatusCode() != 200) {
+                return null;
+            }
+            
+//            Redirect to a POST is not supported without user interaction
+//            http://www.ietf.org/rfc/rfc2616.txt
+//            If the 301 status code is received in response to a request other
+//            than GET or HEAD, the user agent MUST NOT automatically redirect the
+//            request unless it can be confirmed by the user, since this might
+//            change the conditions under which the request was issued.
+            
+            httpclient.setRedirectStrategy(new LaxRedirectStrategy());
+            HttpPost httppost = new HttpPost(url);
+ 
+            Source source = new Source(EntityUtils.toString(entity));
+            List <NameValuePair> nvps = new ArrayList <NameValuePair>();
+            FormFields formFields = source.getFormFields();
+            Assert.assertNotNull("Form field 'wa' not found", formFields.get("wa"));
+            Assert.assertNotNull("Form field 'wresult' not found", formFields.get("wresult"));
+            for (FormField formField : formFields) {
+                nvps.add(new BasicNameValuePair(formField.getName(), formField.getValues().get(0)));
+            }
+            httppost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
+
+            response = httpclient.execute(httppost);
+            
+            entity = response.getEntity();
+            System.out.println(response.getStatusLine());
+            Assert.assertTrue("RP HTTP Response code: " + response.getStatusLine().getStatusCode()
+                              + " [Expected: " + returnCodeRP + "]",
+                              returnCodeRP == response.getStatusLine().getStatusCode());
+            
+            if (entity != null) {
+                System.out.println("Response content length: " + entity.getContentLength());
+            }
+            
+            return EntityUtils.toString(entity);
+        } finally {
+            // When HttpClient instance is no longer needed,
+            // shut down the connection manager to ensure
+            // immediate deallocation of all system resources
+            httpclient.getConnectionManager().shutdown();
+        }
+        
+    }
+    
+    
+    @AfterClass
+    public static void cleanup() {
+        if (idpServer != null && idpServer.isStarted()) {
+            try {
+                idpServer.stop();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        if (rpServer != null && rpServer.isStarted()) {
+            try {
+                rpServer.stop();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    
+    
+}

Modified: cxf/fediz/trunk/systests/tests/src/test/resources/jetty/idp-server.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/systests/tests/src/test/resources/jetty/idp-server.xml?rev=1432495&r1=1432494&r2=1432495&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/tests/src/test/resources/jetty/idp-server.xml (original)
+++ cxf/fediz/trunk/systests/tests/src/test/resources/jetty/idp-server.xml Sat Jan 12 19:59:54
2013
@@ -32,14 +32,14 @@
 		    <Item>
 		      <New class="org.eclipse.jetty.webapp.WebAppContext">
 	            <Set name="contextPath">/fedizidp</Set>
-	            <Set name="war">./target/systests-fediz-idp.war</Set>
+	            <Set name="war">./target/fediz-idp.war</Set>
 	            <Set name="throwUnavailableOnStartupException">true</Set>
 	          </New>
 	        </Item>
 	        <Item>
 		      <New class="org.eclipse.jetty.webapp.WebAppContext">
 	            <Set name="contextPath">/fedizidpsts</Set>
-	            <Set name="war">./target/systests-fediz-idp-sts.war</Set>
+	            <Set name="war">./target/fediz-idp-sts.war</Set>
 	            <Set name="throwUnavailableOnStartupException">true</Set>
 	          </New>	          
 		    </Item>



Mime
View raw message