Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A4CD3E50D for ; Thu, 7 Mar 2013 13:48:40 +0000 (UTC) Received: (qmail 25574 invoked by uid 500); 7 Mar 2013 13:48:40 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 25462 invoked by uid 500); 7 Mar 2013 13:48:40 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 25449 invoked by uid 99); 7 Mar 2013 13:48:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Mar 2013 13:48:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Mar 2013 13:48:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CFB7B2388B43 for ; Thu, 7 Mar 2013 13:48:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r853477 - in /websites/production/cxf/content: cache/main.pageCache fediz-spring.html Date: Thu, 07 Mar 2013 13:48:14 -0000 To: commits@cxf.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130307134814.CFB7B2388B43@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: buildbot Date: Thu Mar 7 13:48:14 2013 New Revision: 853477 Log: Production update by buildbot for cxf Modified: websites/production/cxf/content/cache/main.pageCache websites/production/cxf/content/fediz-spring.html Modified: websites/production/cxf/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/cxf/content/fediz-spring.html ============================================================================== --- websites/production/cxf/content/fediz-spring.html (original) +++ websites/production/cxf/content/fediz-spring.html Thu Mar 7 13:48:14 2013 @@ -138,7 +138,9 @@ Apache CXF -- Fediz Spring

Spring Security Plugin (1.1 SNAPSHOT)

-

This page describes how to enable Federation for a Spring Security based Web Application. Spring Security provides more authorization capabilities than defined in the Java Servlet specification. Beyond authorizing web requests Spring Security supports authorizing whether methods can be invoked and authorizing access to individual domain object instances. Further, Spring Security supports two deployment options. On the one hand, authentication and authorization is enforced by the underlying Servlet Container or on the other hand by Spring Security embedded with the application. The former ensures that the application is only called if authentication is successful. This can be controlled by an administrator/operator. This option is called Pre-Authentication. The latter gives all the control to the application developer and removes the dependency to security configuration in the Servlet Container. This simplifies deploying an application into different Serlvet Container environments.

+

This page describes how to enable Federation for a Spring Security based Web Application. Spring Security provides more authorization capabilities than defined in the Java Servlet specification. Beyond authorizing web requests Spring Security supports authorizing whether methods can be invoked and authorizing access to individual domain object instances.

+ +

Spring Security supports two deployment options. On the one hand, authentication and authorization is enforced by the underlying Servlet Container or on the other hand by Spring Security embedded with the application. The former ensures that the application is only called if authentication is successful. This can be controlled by an administrator/operator. This option is called Pre-Authentication. The latter gives all the control to the application developer and removes the dependency to security configuration in the Servlet Container. This simplifies deploying an application into different Serlvet Container environments.

Both options are valid and it mainly depends on the policies/requirements within a company which is a better fit. Questions to be answered are: Who should manage the security enforcement (Application developer, Administrator)? Do you have to deploy the application into different Servlet Container environments?

@@ -150,31 +152,148 @@ Apache CXF -- Fediz Spring

It's recommended to use Maven to resolve all the dependencies as illustrated in the two examples springWebapp and springPreAuthWebapp. Each example contains a README with instructions for building and deployment.

-

Configure Web Application (Pre-Authentication)

+

Web Application with Pre-Authentication Spring Security

The role of the Fediz Spring plugin in the case of Servlet Container managed security is to adapt the security context of the Servlet Container to the Spring Security Context. This allows to configure authorization for web requests and method calls based on Spring Security.

+

This deployment option requires to configure Fediz into the Servlet Container which is described here:

+ + +
Fediz Plugin configuration for Your Web Application

The Fediz related configuration is done in a Servlet Container independent configuration file which is described here.

+
Spring Security Configuration
+ +

The following configuration snippets illustrate the Fediz related configuration. The complete configuration file can be found in the example springPreAuthWebapp.

+ +
applicationContext-security.xml
+
+
+    <bean id="preAuthenticatedUserDetailsService"
+            class="org.apache.cxf.fediz.spring.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsFederationService"/>    
+    
+    <bean id="j2eePreAuthFilter" class="org.apache.cxf.fediz.spring.preauth.FederationPreAuthenticatedProcessingFilter">
+        <property name="authenticationManager" ref="authenticationManager"/>
+        <property name="authenticationDetailsSource">
+            <bean class="org.springframework.security.web.authentication.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource">
+                <property name="mappableRolesRetriever">
+                    <bean class="org.springframework.security.web.authentication.preauth.j2ee.WebXmlMappableAttributesRetriever" />
+                </property>
+                <property name="userRoles2GrantedAuthoritiesMapper">
+                    <bean class="org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper">
+                        <property name="convertAttributeToUpperCase" value="true"/>
+                    </bean>
+                </property>
+            </bean>
+        </property>
+    </bean>
+
+    <bean id="fsi" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
+        <property name="authenticationManager" ref="authenticationManager"/>
+        <property name="accessDecisionManager" ref="httpRequestAccessDecisionManager"/>
+        <property name="securityMetadataSource">
+            <sec:filter-invocation-definition-source>
+                <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:intercept-url pattern="/secure/fedservlet" access="ROLE_USER,ROLE_ADMIN,ROLE_MANAGER,ROLE_AUTHENTICATED"/>
+            </sec:filter-invocation-definition-source>
+        </property>
+    </bean>
+
+
+ +

The beans preAuthenticatedUserDetailsService and j2eePreAuthFilter are required to provide the Fediz related security information (claims, login token) to the Spring Security Context. The bean fsi defines the authorization for the web requests which looks similar to security constraints definition in web.xml.

+ +

The following code snippet of the FederationServlet example illustrates how to get access to the Spring Security Context of the current user.

+ +
FederationServlet.java
+
+    Authentication obj = SecurityContextHolder.getContext().getAuthentication();
+
+
+ +

The Authentication object can be casted to the FederationAuthentiationToken which provides access to Claims, login token, etc.

+

Web Application with "native" Spring Security

+

In this case, authentication and authorization are managed by Spring Security only. The Fediz Spring Plugin provides the implementation of WS-Federation by implementing certain Spring Security interfaces. Finally, this results into the creation of the Spring Security Context. You can use Spring's authorization capabilities for web requests and method calls. The example springWebapp only illustrates authorizing web requests. Method based authorization is described here.

-
-
 
+
Fediz Plugin configuration for Your Web Application
+ +

The Fediz related configuration is done in a Servlet Container independent configuration file which is described here.

+ +
Spring Security Configuration
+ +

The following configuration snippets illustrate the Fediz related configuration. The complete configuration file can be found in the example springWebapp.

+ +
applicationContext-security.xml
+
+    <sec:http entry-point-ref="federationEntryPoint" use-expressions="true">
+        <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/manager/**" access="hasRole('ROLE_MANAGER')"/>
+        <sec:intercept-url pattern="/secure/admin/**" access="hasRole('ROLE_ADMIN')"/>
+        <sec:intercept-url pattern="/secure/user/**" access="hasAnyRole('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">
+        <sec:authentication-provider ref="federationAuthProvider" />
+    </sec:authentication-manager>
+
+    <bean id="fedizConfig" class="org.apache.cxf.fediz.spring.FederationConfigImpl" init-method="init"
+        p:configFile="WEB-INF/fediz_config.xml" />
+
+    <bean id="federationEntryPoint"
+        class="org.apache.cxf.fediz.spring.web.FederationAuthenticationEntryPoint"
+        p:federationConfig-ref="fedizConfig" />
+ 
+    <bean id="federationFilter"
+        class="org.apache.cxf.fediz.spring.web.FederationAuthenticationFilter"
+        p:authenticationManager-ref="authManager">
+        <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">
+        <property name="authenticationUserDetailsService">
+            <bean class="org.apache.cxf.fediz.spring.authentication.GrantedAuthoritiesUserDetailsFederationService"/>
+        </property>
+    </bean>
 
+

The http element is the key element which depends on the other bean definitions like federationFilter and the federationAuthProvider. Web request authorizing is configured in the http element as well which looks similar to security constraints definition in web.xml.

+

The following code snippet of the FederationServlet example illustrates how to get access to the Spring Security Context of the current user and to the Federation releated information like claims and login token.

-

Web Application deployment

+
FederationServlet.java
+
+    Authentication obj = SecurityContextHolder.getContext().getAuthentication();
+    FederationAuthenticationToken fedAuthToken = (FederationAuthenticationToken)auth;
+    for (GrantedAuthority item : fedAuthToken.getAuthorities()) {
+        ...
+    }
+    
+    ClaimCollection claims = ((FederationUser)fedAuthToken.getUserDetails()).getClaims();
+    for (Claim c: claims) {
+        ...
+    }
+
+
-

Deploy your Web Application to your Jetty installation (<jetty.home>/webapps). If you're running the Fediz examples, their README files will have instructions on how to do this.

Federation Metadata document

-

The Jetty Fediz plugin supports publishing the WS-Federation Metadata document which is described here.

+

The Spring Security Fediz plugin supports publishing the WS-Federation Metadata document which is described here.