Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The interface used by Spring to invoke an action bean is org.springframework.webflow.execution.Action and a single method is used:

SWF Action interface
Code Block
title
languagejavaSWF Action interface
package org.springframework.webflow.execution;

public interface Action {
    public Event execute(RequestContext context) throws Exception;
} 

All action beans ultimately support this interface. However, the vast majority of beans in the IdP will implement an OpenSAML interface, ProfileAction, which is a Spring-independent interface with a similarly simple signature:

OpenSAML ProfileAction interface
Code Block
languagejavatitleOpenSAML ProfileAction interface
package org.opensaml.profile.action;

public interface ProfileAction<InboundMessageType,OutboundMessageType> extends InitializableComponent {

	public void execute(@Nonnull final ProfileRequestContext<InboundMessageType,OutboundMessageType> profileRequestContext)
            throws ProfileException;
} 

...

More often than not, a profile action bean will not need access to the Spring Web Flow context or the Spring container, in which case it will not need to implement the Web Flow interface itself, just the OpenSAML interface. Usually this is done by deriving a bean from the AbstractProfileAction base class and overriding this method:

Implementing an OpenSAML ProfileAction
Code Block
languagejavatitleImplementing an OpenSAML ProfileAction
protected void doExecute(@Nonnull ProfileRequestContext<InboundMessageType,OutboundMessageType> profileRequestContext)
	throws ProfileException;

The action bean interacts with the current request using the ProfileRequestContext, which is the root of an extensible tree of context objects representing the state of a profile execution, the inputs to the action, and the outputs of the action when it completes. If executing in a servlet container, the action can access the servlet objects by requiring their injection as properties on the action bean.

When an action completes, it signals a transition by attaching an EventContext object to the context tree. The "proceed" Event ID is generally used to signal a standard successful transition. Helper methods for attaching events are provided in the ActionSupport helper class. In most cases, actions do nothing on success, but call a helper method to signal a non-proceed event. Exceptions may be, but generally should not be, thrown. Using events provides the best model for control and customization.

...

If an action bean requires access to the Spring Web Flow context object or Spring container, it has a couple of options that are functionally equivalent. Both start by deriving from the AbstractProfileAction base class. It can choose to directly implement the Spring Web Flow Action interface by overriding this method:

...

...

Implementing a Spring Web Flow Action
Code Block
languagejava
protected Event doExecute(@Nonnull final RequestContext springRequestContext,
	@Nonnull final ProfileRequestContext<InboundMessageType,OutboundMessageType> profileRequestContext)
		throws ProfileException;

An alternative approach that is more consistent with the rest of the action beans that don't involve Spring is to override the ProfileAction method shown in the Spring-Independent example above. As in that case, results are signaled by adding an EventContext to the context tree. Access to Spring is via a SpringRequestContext object available as a child of the context tree.

...

This is not an exhaustive discussion as to how web flows can or will be configured, but to illustrate the two cases discussed, here is an example of how a couple of action beans are declared so that they can be referenced by a web flow:

Spring Web Flow Bean Example
Code Block
languagehtml/xmltitleSpring Web Flow Bean Example
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/util
                           http://www.springframework.org/schema/util/spring-util.xsd"
       default-init-method="initialize">

    <!--
    Enables property replacement, auto-wraps OpenSAML actions in a Spring action wrapper, and
    auto-adds a component identifier to each bean based on the Spring bean ID.
    -->
    <bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer"
        p:placeholderPrefix="%{" p:placeholderSuffix="}" />
    <bean class="net.shibboleth.idp.profile.impl.ProfileActionBeanPostProcessor" />
    <bean class="net.shibboleth.ext.spring.config.IdentifiableBeanPostProcessor" />

    <!-- An action that can run without Spring and is adapted. -->
    <bean id="SpringIndependentBean" class="org.example.profile.impl.SpringIndependent" scope="prototype" />

    <!-- An action that is Spring-dependent. -->
    <bean id="SpringAware" class="org.example.profile.impl.SpringAware" scope="prototype" />
        
</beans> 

The ProfileActionBeanPostProcessor bean is a Spring post-processor that detects any OpenSAML ProfileAction beans that do not implement the Spring Action interface, and wraps them in a WebFlowProfileActionAdaptor. This is a simple bean that turns any implementation of the OpenSAML ProfileAction interface into a Spring Web Flow action.

...