Spring Security 2.0 Plugin (1.1)

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?

Prior to doing this configuration, make sure you've first deployed the Fediz IDP and STS on the Tomcat IDP instance as discussed here, and can view the STS WSDL at the URL given on that page.

Installation

You can either build the Fediz plugin on your own, download the package here or add the dependency to your Maven project. If you have built the plugin on your own you'll find the required libraries in plugins/spring2/target/...zip-with-dependencies.zip

It's recommended to use Maven to resolve all the dependencies as illustrated in the example spring2Webapp. The README provides instructions for building and deployment.

Web Application with "native" Spring Security

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 spring2Webapp 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 spring2Webapp.

applicationContext-security.xml
    <sec:http entry-point-ref="federationEntryPoint">
        <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: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" />
 
    <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"/>
    </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>

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.

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) {
        ...
    }

Federation Metadata document

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