You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ow...@apache.org on 2013/03/12 22:07:23 UTC
svn commit: r1455711 [1/2] - in /cxf/fediz/trunk: examples/spring2Webapp/
examples/spring2Webapp/src/ examples/spring2Webapp/src/main/
examples/spring2Webapp/src/main/config/ examples/spring2Webapp/src/main/java/
examples/spring2Webapp/src/main/java/or...
Author: owulff
Date: Tue Mar 12 21:07:21 2013
New Revision: 1455711
URL: http://svn.apache.org/r1455711
Log:
Spring Security 2 support added
Added:
cxf/fediz/trunk/examples/spring2Webapp/
cxf/fediz/trunk/examples/spring2Webapp/README.txt
cxf/fediz/trunk/examples/spring2Webapp/pom.xml
cxf/fediz/trunk/examples/spring2Webapp/src/
cxf/fediz/trunk/examples/spring2Webapp/src/main/
cxf/fediz/trunk/examples/spring2Webapp/src/main/config/
cxf/fediz/trunk/examples/spring2Webapp/src/main/config/fediz_config.xml
- copied, changed from r1454493, cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/
cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/
cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/log4j.properties
cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/stsstore.jks (with props)
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.form.xml
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.xml
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/fediz_config.xml
- copied, changed from r1454493, cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/web.xml
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/index.html
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/secure/
cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/secure/test.html
cxf/fediz/trunk/plugins/spring2/
cxf/fediz/trunk/plugins/spring2/README.txt
cxf/fediz/trunk/plugins/spring2/pom.xml
cxf/fediz/trunk/plugins/spring2/src/
cxf/fediz/trunk/plugins/spring2/src/main/
cxf/fediz/trunk/plugins/spring2/src/main/assembly/
cxf/fediz/trunk/plugins/spring2/src/main/assembly/assembly.xml
cxf/fediz/trunk/plugins/spring2/src/main/java/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfig.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfigImpl.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationUser.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/SpringFedizMessageSource.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/AbstractFederationUserDetailsService.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationProvider.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationToken.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationResponseAuthenticationToken.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/GrantedAuthoritiesUserDetailsFederationService.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationEntryPoint.java
cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/web/FederationAuthenticationFilter.java
cxf/fediz/trunk/plugins/spring2/src/main/resources/
cxf/fediz/trunk/plugins/spring2/src/main/resources/org/
cxf/fediz/trunk/plugins/spring2/src/main/resources/org/apache/
cxf/fediz/trunk/plugins/spring2/src/main/resources/org/apache/cxf/
cxf/fediz/trunk/plugins/spring2/src/main/resources/org/apache/cxf/fediz/
cxf/fediz/trunk/plugins/spring2/src/main/resources/org/apache/cxf/fediz/spring/
cxf/fediz/trunk/plugins/spring2/src/main/resources/org/apache/cxf/fediz/spring/messages.properties
cxf/fediz/trunk/systests/spring/src/test/java/org/apache/cxf/fediz/integrationtests/Spring2Test.java
cxf/fediz/trunk/systests/spring2Webapp/
cxf/fediz/trunk/systests/spring2Webapp/pom.xml
cxf/fediz/trunk/systests/spring2Webapp/src/
cxf/fediz/trunk/systests/spring2Webapp/src/main/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/org/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/org/apache/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/org/apache/cxf/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/org/apache/cxf/fediz/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/
cxf/fediz/trunk/systests/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
cxf/fediz/trunk/systests/spring2Webapp/src/main/resources/
cxf/fediz/trunk/systests/spring2Webapp/src/main/resources/log4j.properties
cxf/fediz/trunk/systests/spring2Webapp/src/main/resources/logging.properties
cxf/fediz/trunk/systests/spring2Webapp/src/main/resources/stsstore.jks (with props)
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/WEB-INF/
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.xml
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/WEB-INF/web.xml
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/index.html
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/secure/
cxf/fediz/trunk/systests/spring2Webapp/src/main/webapp/secure/test.html
Removed:
cxf/fediz/trunk/systests/springWebapp/src/main/webapp/META-INF/context.xml
Modified:
cxf/fediz/trunk/plugins/pom.xml
cxf/fediz/trunk/systests/pom.xml
cxf/fediz/trunk/systests/spring/pom.xml
cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml
cxf/fediz/trunk/systests/spring/src/test/resources/rp-server.xml
Added: cxf/fediz/trunk/examples/spring2Webapp/README.txt
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/README.txt?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/README.txt (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/README.txt Tue Mar 12 21:07:21 2013
@@ -0,0 +1,76 @@
+Simple Spring Web Application Demo
+==================================
+
+This demo shows how to build and deploy an SSO protected using Apache CXF Fediz
+for a spring security based web application.
+
+Running this sample consists of four steps:
+
+- Configure the Tomcat-IDP and Servlet Container for RP instances
+- Building the demo using Maven
+- Deploying the demo to the RP instance
+- Testing the demo
+
+Please review the README in the samples main directory before continuing.
+
+Configure the Tomcat-IDP and Servlet Container for RP instances
+---------------------------------------------------------------
+First, make sure the separate Tomcat instance hosting the Fediz IDP and IDP
+STS has been configured and is running as described here:
+http://cxf.apache.org/fediz-idp.html. Confirm the STS is active by
+checking that the WSDL is viewable from the browser using the URL given
+on that page--don't proceed further unless it is.
+
+The benefit of using Spring Security which is packaged with the demo application
+there are no plugin deployments required for the RP Servlet Container.
+See this wiki page for instructions:
+http://cxf.apache.org/fediz-spring.html -- the "HTTPS Configuration" sections
+are the only parts that need configuration for this sample.
+
+
+Demo Web Application
+--------------------
+The main code lives in the class FederationServlet. This Servlet is protected
+and can be accessed only if the browser user is authenticated. The purpose of
+the FederationServlet is to illustrate the usage of the Spring Security API and
+Configuration to get the authenticated user and to check the roles he has. Further,
+the FederationServlet shows how to access claims data (user data) which were
+stored in the SAML token by using the Fediz interface FederationPrincipal.
+Beyond that, the FederationServlet illustrates how to access the SAML token
+if required. The classes SecurityTokenThreadLocal.java and FederationFilter.java
+can be used to achieve that. You could get this information directly from the
+HTTP session.
+
+
+Building the demo using Maven
+-----------------------------
+From the base directory of this sample (i.e., where this README file is
+located), the pom.xml file is used to build and run the demo. From a
+command prompt, enter:
+
+ mvn clean install (builds the demo and creates a WAR file for Servlet deployment)
+
+
+Deploying the demo to Tomcat
+----------------------------
+Either manually copy this sample's generated WAR file to the Tomcat-RP's
+webapps folder, or use the Tomcat Maven Plugin as described in the README file
+in the example folder root.
+It's recommended to not deploy this WAR into Servlet Container where Fediz is
+integrated into the Security Layer of the Container itself.
+
+
+Test the demo
+-------------
+Enter the following URL into the browser (TCP port depends on your HTTP settings):
+
+https://localhost:10443/fedizhelloworld/secure/fedservlet
+
+The browser is redirected to the IDP and prompts for username and password. As described
+in the IDP installation, the following users are already set up:
+
+User: alice Password: ecila
+User: bob Password: bob
+User: ted Password: det
+
+
Added: cxf/fediz/trunk/examples/spring2Webapp/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/pom.xml?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/pom.xml (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/pom.xml Tue Mar 12 21:07:21 2013
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>examples</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </parent>
+ <groupId>org.apache.cxf.fediz.examples</groupId>
+ <artifactId>spring2Webapp</artifactId>
+ <name>Fediz Example: Spring2Webapp</name>
+ <packaging>war</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring.version>2.0.8.RELEASE</spring.version>
+ </properties>
+ <dependencies>
+<!--
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>${commons.logging.version}</version>
+ <scope>provided</scope>
+ </dependency>
+-->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>fediz-cxf</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>fediz-spring2</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons.lang.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>${log4j.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.jms</groupId>
+ <artifactId>jms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jdmk</groupId>
+ <artifactId>jmxtools</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.sun.jmx</groupId>
+ <artifactId>jmxri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <!--for mvn tomcat:deploy/:undeploy/:redeploy -->
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>tomcat-maven-plugin</artifactId>
+ <version>1.1</version>
+ <configuration>
+ <server>myTomcat</server>
+ <url>http://localhost:10080/manager/text</url>
+ <path>/${project.build.finalName}</path>
+ </configuration>
+ </plugin>
+ </plugins>
+ <!-- Name of the generated WAR file -->
+ <finalName>fedizhelloworld</finalName>
+ </build>
+</project>
Copied: cxf/fediz/trunk/examples/spring2Webapp/src/main/config/fediz_config.xml (from r1454493, cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/config/fediz_config.xml?p2=cxf/fediz/trunk/examples/spring2Webapp/src/main/config/fediz_config.xml&p1=cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml&r1=1454493&r2=1455711&rev=1455711&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml (original)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/config/fediz_config.xml Tue Mar 12 21:07:21 2013
@@ -10,7 +10,7 @@
</audienceUris>
<certificateStores>
<trustManager>
- <keyStore file="stsstore.jks" password="stsspass" type="JKS" />
+ <keyStore file="tomcat-rp.jks" password="tompass" type="JKS" />
</trustManager>
</certificateStores>
<trustedIssuers>
@@ -21,10 +21,9 @@
<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/</issuer>
+ <issuer>https://localhost:9443/fediz-idp/</issuer>
<roleDelimiter>,</roleDelimiter>
<roleURI>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role</roleURI>
- <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>-->
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/java/org/apache/cxf/fediz/example/FederationServlet.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,125 @@
+/**
+ * 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.example;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.security.Principal;
+
+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.cxf.web.SecurityTokenThreadLocal;
+import org.apache.cxf.fediz.spring.FederationUser;
+import org.apache.cxf.fediz.spring.authentication.FederationAuthenticationToken;
+
+import org.springframework.security.Authentication;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.context.SecurityContextHolder;
+
+
+public class FederationServlet extends HttpServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9019993850246851112L;
+
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ response.setContentType("text/html");
+ PrintWriter out = response.getWriter();
+
+ out.println("<html>");
+ out.println("<head><title>WS Federation Spring Security Example</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("<br><b>User</b><p>");
+ Principal p = request.getUserPrincipal();
+ if (p != null) {
+ out.println("Principal: " + p.getName() + "<p>");
+ }
+
+ // Access Spring security context
+ Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+ if (auth instanceof FederationAuthenticationToken) {
+ out.println("Roles of user:<p><ul>");
+ FederationAuthenticationToken fedAuthToken = (FederationAuthenticationToken)auth;
+ for (GrantedAuthority item : fedAuthToken.getAuthorities()) {
+ out.println("<li>" + item.getAuthority() + "</li>");
+ }
+ out.println("</ul>");
+
+ if (fedAuthToken.getUserDetails() instanceof FederationUser) {
+ out.println("<br><b>Claims</b><p>");
+ ClaimCollection claims = ((FederationUser)fedAuthToken.getUserDetails()).getClaims();
+ for (Claim c: claims) {
+ out.println(c.getClaimType().toString() + ": " + c.getValue() + "<p>");
+ }
+ } else {
+ out.println("FederationAuthenticationToken found but not FederationUser");
+ }
+
+ } else {
+ out.println("No FederationAuthenticationToken found in Spring Security Context.");
+ }
+
+ 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>");
+ }
+
+}
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/log4j.properties?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/log4j.properties (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/log4j.properties Tue Mar 12 21:07:21 2013
@@ -0,0 +1,22 @@
+# Set root category priority to INFO and its only appender to CONSOLE.
+log4j.rootLogger=INFO, CONSOLE
+log4j.logger.org.springframework=INFO, CONSOLE
+log4j.additivity.org.springframework=false
+log4j.logger.org.springframework.security=DEBUG, CONSOLE
+log4j.additivity.org.springframework.security=false
+log4j.logger.org.apache.cxf.fediz=DEBUG, CONSOLE
+log4j.additivity.org.apache.cxf.fediz=false
+
+# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.Threshold=DEBUG
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
+
+# LOGFILE is set to be a File appender using a PatternLayout.
+log4j.appender.LOGFILE=org.apache.log4j.FileAppender
+log4j.appender.LOGFILE.File=fedizhelloworld.log
+log4j.appender.LOGFILE.Append=false
+log4j.appender.LOGFILE.Threshold=DEBUG
+log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
+log4j.appender.LOGFILE.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/stsstore.jks
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/stsstore.jks?rev=1455711&view=auto
==============================================================================
Files cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/stsstore.jks (added) and cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/stsstore.jks Tue Mar 12 21:07:21 2013 differ
Propchange: cxf/fediz/trunk/examples/spring2Webapp/src/main/resources/stsstore.jks
------------------------------------------------------------------------------
svn:executable = *
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.form.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.form.xml?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.form.xml (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.form.xml Tue Mar 12 21:07:21 2013
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:sec="http://www.springframework.org/schema/security"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
+http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <sec:debug />
+
+ <sec:http auto-config='true'>
+ <sec:intercept-url pattern="/**" access="ROLE_USER" />
+ </sec:http>
+
+
+
+ <sec:authentication-manager>
+ <sec:authentication-provider>
+ <sec:user-service>
+ <sec:user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
+ <sec:user name="bob" password="bobspassword" authorities="ROLE_USER" />
+ </sec:user-service>
+ </sec:authentication-provider>
+ </sec:authentication-manager>
+
+
+</beans>
+
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.xml?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.xml (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/applicationContext-security.xml Tue Mar 12 21:07:21 2013
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:sec="http://www.springframework.org/schema/security"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
+
+
+ <sec:http entry-point-ref="federationEntryPoint">
+<!--
+ <sec:intercept-url pattern="/" access="permitAll"/>
+ <sec:intercept-url pattern="/fediz" access="permitAll"/>
+ <sec:intercept-url pattern="/index.html" access="permitAll"/>
+ <sec:intercept-url pattern="/secure/fedservlet" access="isAuthenticated()"/>
+-->
+ <sec:intercept-url pattern="/secure/fedservlet" access="IS_AUTHENTICATED_FULLY"/>
+ <sec:intercept-url pattern="/secure/manager/**" access="ROLE_MANAGER"/>
+ <sec:intercept-url pattern="/secure/admin/**" access="ROLE_ADMIN"/>
+ <sec:intercept-url pattern="/secure/user/**" access="ROLE_USER,ROLE_ADMIN,ROLE_MANAGER"/>
+ <!--<sec:custom-filter ref="federationFilter" after="BASIC_AUTH_FILTER" />-->
+ <!--<sec:session-management session-authentication-strategy-ref="sas"/>-->
+ </sec:http>
+
+
+ <sec:authentication-manager alias="authManager"/>
+
+ <bean id="fedizConfig" class="org.apache.cxf.fediz.spring.FederationConfigImpl" init-method="init"
+ p:configFile="WEB-INF/fediz_config.xml" p:contextName="/fedizhelloworld" />
+
+ <bean id="federationEntryPoint"
+ class="org.apache.cxf.fediz.spring.web.FederationAuthenticationEntryPoint"
+ p:federationConfig-ref="fedizConfig" />
+
+<!-- Works without org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy as well -->
+<!--
+ <bean id="federationFilter"
+ class="org.apache.cxf.fediz.spring.web.FederationAuthenticationFilter"
+ p:authenticationManager-ref="authManager" p:sessionAuthenticationStrategy-ref="sas">
+
+ <property name="authenticationFailureHandler">
+ <bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler" />
+ </property>
+ </bean>
+ -->
+
+ <bean id="federationFilter"
+ class="org.apache.cxf.fediz.spring.web.FederationAuthenticationFilter"
+ p:authenticationManager-ref="authManager" p:defaultTargetUrl="/whatever">
+ <sec:custom-filter after="BASIC_PROCESSING_FILTER"/>
+ <!--
+ <property name="authenticationFailureHandler">
+ <bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler" />
+ </property>
+ -->
+ </bean>
+
+ <bean id="federationAuthProvider" class="org.apache.cxf.fediz.spring.authentication.FederationAuthenticationProvider"
+ p:federationConfig-ref="fedizConfig">
+ <sec:custom-authentication-provider />
+ <property name="authenticationUserDetailsService">
+ <bean class="org.apache.cxf.fediz.spring.authentication.GrantedAuthoritiesUserDetailsFederationService"/>
+ </property>
+ </bean>
+<!--
+ <bean id="sas" class="org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy" />
+-->
+</beans>
+
Copied: cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/fediz_config.xml (from r1454493, cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml)
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/fediz_config.xml?p2=cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/fediz_config.xml&p1=cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml&r1=1454493&r2=1455711&rev=1455711&view=diff
==============================================================================
--- cxf/fediz/trunk/systests/spring/src/test/resources/fediz_config.xml (original)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/fediz_config.xml Tue Mar 12 21:07:21 2013
@@ -21,7 +21,7 @@
<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/</issuer>
+ <issuer>https://localhost:9443/fediz-idp/</issuer>
<roleDelimiter>,</roleDelimiter>
<roleURI>http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role</roleURI>
<reply>/j_spring_fediz_security_check</reply>
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/web.xml?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/web.xml (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/WEB-INF/web.xml Tue Mar 12 21:07:21 2013
@@ -0,0 +1,76 @@
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0" metadata-complete="true">
+
+ <description>WS Federation Spring Example</description>
+ <display-name>WS Federation Spring Example</display-name>
+
+ <filter>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
+ </filter>
+
+ <!-- Optional: Cache the security token in Thread Local Storage -->
+ <filter>
+ <filter-name>FederationFilter</filter-name>
+ <filter-class>org.apache.cxf.fediz.cxf.web.FederationFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>springSecurityFilterChain</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+<!--
+ <filter-mapping>
+ <filter-name>FederationFilter</filter-name>
+ <url-pattern>/secure/*</url-pattern>
+ </filter-mapping>
+-->
+
+ <!--
+ - Location of the XML file that defines the root application context
+ - Applied by ContextLoaderListener.
+ -->
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>
+ /WEB-INF/applicationContext-security.xml
+ </param-value>
+ </context-param>
+
+ <!--
+ - Loads the root application context of this web app at startup.
+ - The application context is then available via
+ - WebApplicationContextUtils.getWebApplicationContext(servletContext).
+ -->
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <servlet>
+ <servlet-name>FederationServlet</servlet-name>
+ <servlet-class>org.apache.cxf.fediz.example.FederationServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <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>
+
+</web-app>
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/index.html?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/index.html (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/index.html Tue Mar 12 21:07:21 2013
@@ -0,0 +1,25 @@
+<!--
+ 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.
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<HTML><HEAD><TITLE>WS Federation Tomcat Examples</TITLE>
+<META http-equiv=Content-Type content="text/html">
+</HEAD>
+<BODY>
+<P>
+<H3>Hello World</H3>
+<P></P>
+</BODY></HTML>
Added: cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/secure/test.html
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/secure/test.html?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/secure/test.html (added)
+++ cxf/fediz/trunk/examples/spring2Webapp/src/main/webapp/secure/test.html Tue Mar 12 21:07:21 2013
@@ -0,0 +1,25 @@
+<!--
+ 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.
+-->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<HTML><HEAD><TITLE>WS Federation Tomcat Examples</TITLE>
+<META http-equiv=Content-Type content="text/html">
+</HEAD>
+<BODY>
+<P>
+<H3>Secure Test</H3>
+<P></P>
+</BODY></HTML>
Modified: cxf/fediz/trunk/plugins/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/pom.xml?rev=1455711&r1=1455710&r2=1455711&view=diff
==============================================================================
--- cxf/fediz/trunk/plugins/pom.xml (original)
+++ cxf/fediz/trunk/plugins/pom.xml Tue Mar 12 21:07:21 2013
@@ -34,6 +34,7 @@
<module>tomcat</module>
<module>jetty</module>
<module>spring</module>
+ <module>spring2</module>
<module>cxf</module>
</modules>
</project>
Added: cxf/fediz/trunk/plugins/spring2/README.txt
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/README.txt?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/README.txt (added)
+++ cxf/fediz/trunk/plugins/spring2/README.txt Tue Mar 12 21:07:21 2013
@@ -0,0 +1,13 @@
+Fediz configuration for Spring Security
+---------------------------------------
+
+The Servlet Container installation doesn't have to be updated before a Web Application can be deployed.
+
+It's recommended to use HTTPS to avoid sending tokens/cookies in clear text on the network.
+Please check your Servlet Container documentation how to set it up.
+
+Please check the Spring Security example to get more information how to deploy a web application
+using Spring Security.
+
+The following wiki page explains the fediz configuration which is Container independent:
+http://cxf.apache.org/fediz-configuration.html
Added: cxf/fediz/trunk/plugins/spring2/pom.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/pom.xml?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/pom.xml (added)
+++ cxf/fediz/trunk/plugins/spring2/pom.xml Tue Mar 12 21:07:21 2013
@@ -0,0 +1,119 @@
+<?xml version="1.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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>fediz</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <artifactId>fediz-spring2</artifactId>
+ <name>Apache Fediz Plugin Spring2</name>
+ <packaging>bundle</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <spring.version>2.0.8.RELEASE</spring.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>2.0.8</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf.fediz</groupId>
+ <artifactId>fediz-core</artifactId>
+ <version>${project.version}</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>${servlet.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2.1</version>
+ <executions>
+ <execution>
+ <id>zip-file</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/assembly.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>2.3.4</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Implementation-Title>Apache CXF Fediz</Implementation-Title>
+ <Implementation-Vendor>The Apache Software Foundation</Implementation-Vendor>
+ <Implementation-Vendor-Id>org.apache</Implementation-Vendor-Id>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Specification-Title>Apache CXF Fediz</Specification-Title>
+ <Specification-Vendor>The Apache Software Foundation</Specification-Vendor>
+ <Specification-Version>${project.version}</Specification-Version>
+ <Export-Package>
+ org.apache.cxf.fediz.spring.*;version="${project.version}"
+ </Export-Package>
+ <Import-Package>
+ !org.apache.cxf.fediz.spring*,
+ org.apache.cxf.fediz.core.*,
+ *;resolution:=optional
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: cxf/fediz/trunk/plugins/spring2/src/main/assembly/assembly.xml
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/assembly/assembly.xml?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/assembly/assembly.xml (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/assembly/assembly.xml Tue Mar 12 21:07:21 2013
@@ -0,0 +1,18 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
+http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>zip-with-dependencies</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/</outputDirectory>
+ <useProjectArtifact>true</useProjectArtifact>
+ <unpack>false</unpack>
+ <scope>runtime</scope>
+ </dependencySet>
+ </dependencySets>
+</assembly>
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfig.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfig.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfig.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfig.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,32 @@
+/**
+ * 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.spring;
+
+import java.util.List;
+import org.apache.cxf.fediz.core.config.FederationContext;
+
+public interface FederationConfig {
+
+ List<FederationContext> getFederationContextList();
+
+ FederationContext getFederationContext(String contextName);
+
+ FederationContext getFederationContext();
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfigImpl.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfigImpl.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfigImpl.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationConfigImpl.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,111 @@
+/**
+ * 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.spring;
+
+import java.util.List;
+
+import org.apache.cxf.fediz.core.config.FederationConfigurator;
+import org.apache.cxf.fediz.core.config.FederationContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.beans.factory.BeanCreationException;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+//import org.springframework.web.context.ServletContextAware;
+
+//public class FederationConfigImpl implements FederationConfig, ServletContextAware {
+public class FederationConfigImpl implements FederationConfig {
+
+ private static final Logger LOG = LoggerFactory.getLogger(FederationConfigImpl.class);
+
+ private Resource configFile;
+ private String contextName;
+
+ //private ServletContext servletContext;
+ private FederationConfigurator configurator = new FederationConfigurator();
+
+
+ public Resource getConfigFile() {
+ return configFile;
+ }
+
+ public void setConfigFile(Resource configFile) {
+ this.configFile = configFile;
+ }
+
+ public String getContextName() {
+ return contextName;
+ }
+
+ public void setContextName(String contextName) {
+ this.contextName = contextName;
+ }
+
+ public void init() {
+ Assert.notNull(this.configFile, "property 'configFile' mandatory");
+ try {
+ configurator.loadConfig(this.configFile.getFile());
+ } catch (Exception e) {
+ LOG.error("Failed to parse '" + configFile.getDescription() + "'", e);
+ throw new BeanCreationException("Failed to parse '" + configFile.getDescription() + "'");
+ }
+ }
+
+ @Override
+ public List<FederationContext> getFederationContextList() {
+ return configurator.getFederationContextList();
+ }
+
+ @Override
+ public FederationContext getFederationContext(String context) {
+ FederationContext ctx = configurator.getFederationContext(context);
+ if (ctx == null) {
+ LOG.error("Federation context '" + context + "' not found.");
+ throw new IllegalStateException("Federation context '" + context + "' not found.");
+ }
+ return ctx;
+ }
+
+
+ @Override
+ public FederationContext getFederationContext() {
+ if (contextName != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Reading federation configuration for context '"
+ + contextName + "'");
+ }
+ return getFederationContext(contextName);
+ } else {
+ Assert.notNull(contextName, "Property 'contextName' must be configured because ServletContext null");
+ return getFederationContext(contextName);
+ }
+ }
+
+
+ /*
+ @Override
+ public void setServletContext(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+ */
+
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationUser.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationUser.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationUser.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/FederationUser.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,53 @@
+/**
+ * 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.spring;
+
+import org.apache.cxf.fediz.core.ClaimCollection;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.userdetails.User;
+
+public class FederationUser extends User {
+
+ private static final long serialVersionUID = -2231762973730849416L;
+
+ private ClaimCollection claims;
+
+ public FederationUser(String username, String password, boolean enabled, boolean accountNonExpired,
+ boolean credentialsNonExpired, boolean accountNonLocked,
+ //Collection<? extends GrantedAuthority> authorities) {
+ GrantedAuthority[] authorities) {
+ super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
+ }
+
+ public FederationUser(String username, String password,
+// Collection<? extends GrantedAuthority> authorities, ClaimCollection claims) {
+ GrantedAuthority[] authorities, ClaimCollection claims) {
+ super(username, password, true, true, true, true, authorities);
+ this.claims = claims;
+ }
+
+ public ClaimCollection getClaims() {
+ return this.claims;
+ }
+
+
+
+
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/SpringFedizMessageSource.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/SpringFedizMessageSource.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/SpringFedizMessageSource.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/SpringFedizMessageSource.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,45 @@
+/**
+ * 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.spring;
+
+import org.springframework.context.support.MessageSourceAccessor;
+import org.springframework.context.support.ResourceBundleMessageSource;
+
+
+/**
+ * The default <code>MessageSource</code> used by Spring Security.
+ * <p>All Spring Security classes requiring messge localization will by default use this class.
+ * However, all such classes will also implement <code>MessageSourceAware</code> so that the application context can
+ * inject an alternative message source. Therefore this class is only used when the deployment environment has not
+ * specified an alternative message source.</p>
+ *
+ * @author Ben Alex
+ */
+public class SpringFedizMessageSource extends ResourceBundleMessageSource {
+
+ public SpringFedizMessageSource() {
+ setBasename("org.apache.cxf.fediz.spring.messages");
+ }
+
+
+ public static MessageSourceAccessor getAccessor() {
+ return new MessageSourceAccessor(new SpringFedizMessageSource());
+ }
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/AbstractFederationUserDetailsService.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/AbstractFederationUserDetailsService.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/AbstractFederationUserDetailsService.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/AbstractFederationUserDetailsService.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,55 @@
+/**
+ * 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.spring.authentication;
+
+import org.apache.cxf.fediz.core.FederationResponse;
+import org.springframework.security.Authentication;
+import org.springframework.security.userdetails.AuthenticationUserDetailsService;
+import org.springframework.security.userdetails.UserDetails;
+import org.springframework.security.userdetails.UsernameNotFoundException;
+
+/**
+ * Abstract class to construct a new User object based on the provided FederationResponseAuthenticationToken.
+ */
+public abstract class AbstractFederationUserDetailsService
+ implements AuthenticationUserDetailsService {
+
+ /*
+ public final UserDetails loadUserDetails(final Authentication token) {
+
+ }*/
+ @Override
+ public final UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException {
+ if (!(token instanceof FederationResponseAuthenticationToken)) {
+ return null;
+ }
+ FederationResponseAuthenticationToken fedToken = (FederationResponseAuthenticationToken)token;
+ return loadUserDetails(fedToken.getResponse());
+ }
+
+ /**
+ * Protected template method for construct a {@link org.springframework.security.core.userdetails.UserDetails}
+ * via the supplied FederationResponse
+ *
+ * @return the newly created UserDetails object.
+ */
+ protected abstract UserDetails loadUserDetails(FederationResponse response);
+
+
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationProvider.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationProvider.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationProvider.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,170 @@
+/**
+ * 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.spring.authentication;
+
+import org.apache.cxf.fediz.core.FederationProcessor;
+import org.apache.cxf.fediz.core.FederationProcessorImpl;
+import org.apache.cxf.fediz.core.FederationRequest;
+import org.apache.cxf.fediz.core.FederationResponse;
+import org.apache.cxf.fediz.spring.FederationConfig;
+import org.apache.cxf.fediz.spring.SpringFedizMessageSource;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.MessageSource;
+import org.springframework.context.MessageSourceAware;
+import org.springframework.context.support.MessageSourceAccessor;
+
+
+import org.springframework.security.Authentication;
+import org.springframework.security.AuthenticationException;
+import org.springframework.security.BadCredentialsException;
+//import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
+//import org.springframework.security.core.authority.mapping.NullAuthoritiesMapper;
+import org.springframework.security.providers.AuthenticationProvider;
+import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
+import org.springframework.security.userdetails.AuthenticationUserDetailsService;
+import org.springframework.security.userdetails.UserDetails;
+import org.springframework.security.userdetails.UserDetailsChecker;
+import org.springframework.security.userdetails.checker.AccountStatusUserDetailsChecker;
+import org.springframework.util.Assert;
+
+
+/**
+ * This {@link AuthenticationProvider} implements the integration with the Identity Provider
+ * based on the WS-Federation Passive Requestor Profile.
+ */
+public class FederationAuthenticationProvider implements AuthenticationProvider, InitializingBean, MessageSourceAware {
+ private static final Logger LOG = LoggerFactory.getLogger(FederationAuthenticationProvider.class);
+
+ protected MessageSourceAccessor messages = SpringFedizMessageSource.getAccessor();
+
+ private AuthenticationUserDetailsService authenticationUserDetailsService;
+ private FederationConfig federationConfig;
+
+ private final UserDetailsChecker userDetailsChecker = new AccountStatusUserDetailsChecker();
+ //private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
+
+ public AuthenticationUserDetailsService getAuthenticationUserDetailsService() {
+ return authenticationUserDetailsService;
+ }
+
+ public void setAuthenticationUserDetailsService(
+ AuthenticationUserDetailsService authenticationUserDetailsService) {
+ this.authenticationUserDetailsService = authenticationUserDetailsService;
+ }
+
+ public FederationConfig getFederationConfig() {
+ return federationConfig;
+ }
+
+ public void setFederationConfig(FederationConfig federationConfig) {
+ this.federationConfig = federationConfig;
+ }
+
+
+
+ public void afterPropertiesSet() throws Exception {
+ Assert.notNull(this.authenticationUserDetailsService, "An authenticationUserDetailsService must be set");
+ Assert.notNull(this.messages, "A message source must be set");
+ Assert.notNull(this.federationConfig, "FederationConfig cannot be null.");
+ }
+
+ public Authentication authenticate(Authentication authentication) throws AuthenticationException {
+ if (!supports(authentication.getClass())) {
+ return null;
+ }
+
+ if (!(authentication instanceof UsernamePasswordAuthenticationToken)) {
+ return null;
+ }
+
+ // Ensure credentials are provided
+ if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) {
+ throw new BadCredentialsException(messages.getMessage("FederationAuthenticationProvider.noSignInRequest",
+ "Failed to get SignIn request"));
+ }
+
+ FederationAuthenticationToken result = null;
+
+ if (result == null) {
+ result = this.authenticateNow(authentication);
+ result.setDetails(authentication.getDetails());
+ }
+
+ return result;
+ }
+
+ private FederationAuthenticationToken authenticateNow(final Authentication authentication)
+ throws AuthenticationException {
+ try {
+ FederationRequest wfReq = (FederationRequest)authentication.getCredentials();
+ FederationProcessor wfProc = new FederationProcessorImpl();
+ FederationResponse wfRes = wfProc.processRequest(wfReq, federationConfig.getFederationContext());
+
+ final UserDetails userDetails = loadUserByFederationResponse(wfRes);
+ userDetailsChecker.check(userDetails);
+ return new FederationAuthenticationToken(userDetails, authentication.getCredentials(),
+ userDetails.getAuthorities(), userDetails, wfRes);
+ } catch (Exception e) {
+ LOG.error("Failed to validate SignIn request", e);
+ throw new BadCredentialsException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Template method for retrieving the UserDetails based on the federation response (wresult parameter).
+ *
+ * @param response The WS Federation response
+ * @return the UserDetails.
+ */
+ protected UserDetails loadUserByFederationResponse(final FederationResponse response) {
+ final FederationResponseAuthenticationToken token = new FederationResponseAuthenticationToken(response);
+ return this.authenticationUserDetailsService.loadUserDetails(token);
+ }
+
+ public void setMessageSource(final MessageSource messageSource) {
+ this.messages = new MessageSourceAccessor(messageSource);
+ }
+
+ @Override
+ public boolean supports(Class authentication) {
+ if (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)) {
+ return true;
+ } else {
+ return FederationAuthenticationToken.class.isAssignableFrom(authentication);
+ }
+ }
+
+ /*
+ public void setAuthoritiesMapper(GrantedAuthoritiesMapper authoritiesMapper) {
+ this.authoritiesMapper = authoritiesMapper;
+ }
+ */
+
+ /*
+ public boolean supports(final Class<?> authentication) {
+ return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication))
+ || (FederationAuthenticationToken.class.isAssignableFrom(authentication));
+ }
+ */
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationToken.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationToken.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationToken.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationAuthenticationToken.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,99 @@
+/**
+ * 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.spring.authentication;
+
+import java.io.Serializable;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.fediz.core.ClaimCollection;
+import org.apache.cxf.fediz.core.FederationPrincipal;
+import org.apache.cxf.fediz.core.FederationResponse;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.providers.AbstractAuthenticationToken;
+import org.springframework.security.userdetails.UserDetails;
+
+/**
+ * Represents a successful WS-Federation based authentication.
+ */
+public class FederationAuthenticationToken extends AbstractAuthenticationToken
+ implements Serializable, FederationPrincipal {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Object credentials;
+ private final Object principal;
+ private final UserDetails userDetails;
+ private final FederationResponse response;
+
+
+ public FederationAuthenticationToken(final Object principal, final Object credentials,
+ final GrantedAuthority[] authorities, final UserDetails userDetails,
+ final FederationResponse response) {
+ super(authorities);
+
+ if ((principal == null) || "".equals(principal) || (credentials == null)
+ || "".equals(credentials) || (authorities == null) || (userDetails == null) || (response == null)) {
+ throw new IllegalArgumentException("Cannot pass null or empty values to constructor");
+ }
+
+ this.principal = principal;
+ this.credentials = credentials;
+ this.userDetails = userDetails;
+ this.response = response;
+ setAuthenticated(true);
+ }
+
+ public Object getCredentials() {
+ return this.credentials;
+ }
+
+ public Object getPrincipal() {
+ return this.principal;
+ }
+
+ public FederationResponse getResponse() {
+ return this.response;
+ }
+
+ public UserDetails getUserDetails() {
+ return userDetails;
+ }
+
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(super.toString());
+ sb.append(" Response: ").append(this.response);
+ sb.append(" Credentials: ").append(this.credentials);
+
+ return sb.toString();
+ }
+
+ @Override
+ public ClaimCollection getClaims() {
+ return new ClaimCollection(response.getClaims());
+ }
+
+ @Override
+ public Element getLoginToken() {
+ return response.getToken();
+ }
+
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationResponseAuthenticationToken.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationResponseAuthenticationToken.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationResponseAuthenticationToken.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/FederationResponseAuthenticationToken.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,50 @@
+/**
+ * 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.spring.authentication;
+
+import org.apache.cxf.fediz.core.FederationResponse;
+import org.springframework.security.providers.AbstractAuthenticationToken;
+
+public final class FederationResponseAuthenticationToken extends AbstractAuthenticationToken {
+
+ private static final long serialVersionUID = 1L;
+
+ private final FederationResponse response;
+
+
+ public FederationResponseAuthenticationToken(final FederationResponse response) {
+ super(null);
+
+ this.response = response;
+ }
+
+ public Object getPrincipal() {
+ return this.response.getUsername();
+ }
+
+ public Object getCredentials() {
+ return this.response;
+ }
+
+ public FederationResponse getResponse() {
+ return this.response;
+ }
+
+}
\ No newline at end of file
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/GrantedAuthoritiesUserDetailsFederationService.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/GrantedAuthoritiesUserDetailsFederationService.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/GrantedAuthoritiesUserDetailsFederationService.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/authentication/GrantedAuthoritiesUserDetailsFederationService.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,67 @@
+/**
+ * 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.spring.authentication;
+
+import java.util.*;
+
+import org.apache.cxf.fediz.core.ClaimCollection;
+import org.apache.cxf.fediz.core.FederationResponse;
+import org.apache.cxf.fediz.spring.FederationUser;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.GrantedAuthorityImpl;
+import org.springframework.security.userdetails.UserDetails;
+
+/**
+ * This AuthenticationUserDetailsService implementation creates a FederationUser
+ * object based on the data in the provided FederationResponseAuthenticationToken.
+ */
+public class GrantedAuthoritiesUserDetailsFederationService
+ extends AbstractFederationUserDetailsService {
+
+ private boolean convertToUpperCase = true;
+
+ @Override
+ protected UserDetails loadUserDetails(FederationResponse response) {
+
+ List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
+
+ if (response.getRoles() != null) {
+ for (final String role : response.getRoles()) {
+
+ grantedAuthorities.add(new GrantedAuthorityImpl("ROLE_"
+ + (this.convertToUpperCase ? role.toUpperCase() : role)));
+ }
+ }
+ return new FederationUser(response.getUsername(), "N/A",
+ (GrantedAuthority[]) grantedAuthorities.toArray(
+ new GrantedAuthority[grantedAuthorities.size()]),
+ new ClaimCollection(response.getClaims()));
+
+ }
+
+
+ /**
+ * Converts the role value to uppercase value.
+ *
+ * @param convertToUpperCase true if it should convert, false otherwise.
+ */
+ public void setConvertToUpperCase(final boolean convertToUpperCase) {
+ this.convertToUpperCase = convertToUpperCase;
+ }
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/FederationPreAuthenticatedProcessingFilter.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,78 @@
+/**
+ * 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.spring.preauth;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cxf.fediz.core.FederationPrincipal;
+import org.springframework.security.ui.FilterChainOrder;
+import org.springframework.security.ui.preauth.AbstractPreAuthenticatedProcessingFilter;
+
+/**
+ * This AbstractPreAuthenticatedProcessingFilter implementation is based on the
+ * J2EE container-based authentication mechanism. It will use the J2EE user
+ * principal name as the pre-authenticated principal and the WS-Federation signin request
+ * as the credentials.
+ */
+public class FederationPreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter {
+
+ private static final String SECURITY_TOKEN_ATTR = "org.apache.fediz.SECURITY_TOKEN";
+
+ /**
+ * Return the J2EE user name.
+ */
+ protected Object getPreAuthenticatedPrincipal(HttpServletRequest httpRequest) {
+ Object principal = httpRequest.getUserPrincipal();
+ if (logger.isDebugEnabled()) {
+ logger.debug("PreAuthenticated J2EE principal: "
+ + httpRequest.getUserPrincipal() == null ? null : httpRequest.getUserPrincipal().getName());
+ }
+ return principal;
+ }
+
+ /**
+ * For J2EE container-based authentication there is no generic way to
+ * retrieve the credentials, as such this method returns a fixed dummy
+ * value.
+ */
+ protected Object getPreAuthenticatedCredentials(HttpServletRequest httpRequest) {
+ Object principal = httpRequest.getUserPrincipal() == null ? null : httpRequest.getUserPrincipal();
+ if (principal instanceof FederationPrincipal) {
+ Object obj = httpRequest.getSession(false).getAttribute(SECURITY_TOKEN_ATTR);
+ if (obj != null) {
+ return obj;
+ } else {
+ logger.error("Session must contain Federation response");
+ throw new IllegalStateException("Session must contain Federation response");
+ }
+ } else {
+ logger.error("Principal must be instance of FederationPrincipal: " + principal.toString());
+ throw new IllegalStateException("Principal must be instance of FederationPrincipal");
+ }
+ //return "N/A";
+ }
+
+ @Override
+ public int getOrder() {
+ return FilterChainOrder.BASIC_PROCESSING_FILTER;
+ }
+
+
+}
Added: cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService.java?rev=1455711&view=auto
==============================================================================
--- cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService.java (added)
+++ cxf/fediz/trunk/plugins/spring2/src/main/java/org/apache/cxf/fediz/spring/preauth/PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService.java Tue Mar 12 21:07:21 2013
@@ -0,0 +1,93 @@
+/**
+ * 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.spring.preauth;
+
+import java.util.*;
+
+import org.apache.cxf.fediz.core.ClaimCollection;
+import org.apache.cxf.fediz.core.FederationPrincipal;
+import org.apache.cxf.fediz.spring.FederationUser;
+import org.springframework.security.Authentication;
+import org.springframework.security.AuthenticationException;
+import org.springframework.security.GrantedAuthoritiesContainer;
+import org.springframework.security.GrantedAuthority;
+import org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationToken;
+import org.springframework.security.userdetails.AuthenticationUserDetailsService;
+import org.springframework.security.userdetails.UserDetails;
+import org.springframework.security.userdetails.UsernameNotFoundException;
+
+import org.springframework.util.Assert;
+
+/**
+ * <p>
+ * This AuthenticationUserDetailsService implementation creates a UserDetails
+ * object based solely on the information contained in the given
+ * PreAuthenticatedAuthenticationToken. The user name is set to the name as
+ * returned by PreAuthenticatedAuthenticationToken.getName(), the password is
+ * set to a fixed dummy value (it will not be used by the
+ * PreAuthenticatedAuthenticationProvider anyway), and the Granted Authorities
+ * are retrieved from the details object as returned by
+ * PreAuthenticatedAuthenticationToken.getDetails().
+ *
+ * <p>
+ * The details object as returned by PreAuthenticatedAuthenticationToken.getDetails() must implement the
+ * {@link GrantedAuthoritiesContainer} interface for this implementation to work.
+ *l
+ */
+public class PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService
+ implements AuthenticationUserDetailsService {
+ /**
+ * Get a UserDetails object based on the user name contained in the given
+ * token, and the GrantedAuthorities as returned by the
+ * GrantedAuthoritiesContainer implementation as returned by
+ * the token.getDetails() method.
+ */
+ public final UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException {
+ Assert.notNull(token.getDetails());
+ Assert.isInstanceOf(GrantedAuthoritiesContainer.class, token.getDetails());
+ Assert.isInstanceOf(FederationPrincipal.class, token.getPrincipal());
+ GrantedAuthority[] authorities =
+ ((GrantedAuthoritiesContainer) token.getDetails()).getGrantedAuthorities();
+
+ return createuserDetails(token, authorities, ((FederationPrincipal)token.getPrincipal()).getClaims());
+ }
+
+ /**
+ * Creates the final <tt>UserDetails</tt> object. Can be overridden to customize the contents.
+ *
+ * @param token the authentication request token
+ * @param authorities the pre-authenticated authorities.
+ */
+ protected UserDetails createuserDetails(Authentication token,
+ GrantedAuthority[] authorities, ClaimCollection claims) {
+ return new FederationUser(token.getName(), "N/A", authorities, claims);
+ }
+
+ @Override
+ public UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException {
+ Assert.notNull(token.getDetails());
+ Assert.isInstanceOf(PreAuthenticatedAuthenticationToken.class, token);
+ Assert.isInstanceOf(GrantedAuthoritiesContainer.class, token.getDetails());
+ Assert.isInstanceOf(FederationPrincipal.class, token.getPrincipal());
+ GrantedAuthority[] authorities =
+ ((GrantedAuthoritiesContainer) token.getDetails()).getGrantedAuthorities();
+
+ return createuserDetails(token, authorities, ((FederationPrincipal)token.getPrincipal()).getClaims());
+ }
+}