Class OpenIDAuthenticationFilter

  extended by org.springframework.web.filter.GenericFilterBean
      extended by
          extended by
All Implemented Interfaces:
javax.servlet.Filter, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.MessageSourceAware, org.springframework.web.context.ServletContextAware

public class OpenIDAuthenticationFilter
extends AbstractAuthenticationProcessingFilter

Filter which processes OpenID authentication requests.

The OpenID authentication involves two stages.

Submission of OpenID identity

The user's OpenID identity is submitted via a login form, just as it would be for a normal form login. At this stage the filter will extract the identity from the submitted request (by default, the parameter is called openid_identifier, as recommended by the OpenID 2.0 Specification). It then passes the identity to the configured OpenIDConsumer, which returns the URL to which the request should be redirected for authentication. A "return_to" URL is also supplied, which matches the URL processed by this filter, to allow the filter to handle the request once the user has been successfully authenticated. The OpenID server will then authenticate the user and redirect back to the application.

Processing the Redirect from the OpenID Server

Once the user has been authenticated externally, the redirected request will be passed to the OpenIDConsumer again for validation. The returned OpenIDAuthentication will be passed to the AuthenticationManager where it should (normally) be processed by an OpenIDAuthenticationProvider in order to load the authorities for the user.

See Also:

Field Summary
Fields inherited from class
authenticationDetailsSource, eventPublisher, messages, SPRING_SECURITY_LAST_EXCEPTION_KEY
Fields inherited from class org.springframework.web.filter.GenericFilterBean
Constructor Summary
Method Summary
 void afterPropertiesSet()
 Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Authentication has two phases.
protected  java.lang.String buildReturnToUrl(javax.servlet.http.HttpServletRequest request)
          Builds the return_to URL that will be sent to the OpenID service provider.
protected  java.lang.String lookupRealm(java.lang.String returnToUrl)
protected  java.lang.String obtainUsername(javax.servlet.http.HttpServletRequest req)
          Reads the claimedIdentityFieldName from the submitted request.
 void setClaimedIdentityFieldName(java.lang.String claimedIdentityFieldName)
          The name of the request parameter containing the OpenID identity, as submitted from the initial login form.
 void setConsumer(OpenIDConsumer consumer)
 void setRealmMapping(java.util.Map<java.lang.String,java.lang.String> realmMapping)
          Maps the return_to url to a realm, for example:
 void setReturnToUrlParameters(java.util.Set<java.lang.String> returnToUrlParameters)
          Specifies any extra parameters submitted along with the identity field which should be appended to the return_to URL which is assembled by buildReturnToUrl(javax.servlet.http.HttpServletRequest).
Methods inherited from class
doFilter, getAllowSessionCreation, getAuthenticationDetailsSource, getAuthenticationManager, getFilterProcessesUrl, getRememberMeServices, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setSessionAuthenticationStrategy, successfulAuthentication, unsuccessfulAuthentication
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setServletContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final java.lang.String DEFAULT_CLAIMED_IDENTITY_FIELD
See Also:
Constant Field Values
Constructor Detail


public OpenIDAuthenticationFilter()
Method Detail


public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet in class AbstractAuthenticationProcessingFilter


public Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request,
                                            javax.servlet.http.HttpServletResponse response)
                                     throws AuthenticationException,
Authentication has two phases.
  1. The initial submission of the claimed OpenID. A redirect to the URL returned from the consumer will be performed and null will be returned.
  2. The redirection from the OpenID server to the return_to URL, once it has authenticated the user

Specified by:
attemptAuthentication in class AbstractAuthenticationProcessingFilter
request - from which to extract parameters and perform the authentication
response - the response, which may be needed if the implementation has to do a redirect as part of a multi-stage authentication process (such as OpenID).
the authenticated user token, or null if authentication is incomplete.
AuthenticationException - if authentication fails.


protected java.lang.String lookupRealm(java.lang.String returnToUrl)


protected java.lang.String buildReturnToUrl(javax.servlet.http.HttpServletRequest request)
Builds the return_to URL that will be sent to the OpenID service provider. By default returns the URL of the current request.

request - the current request which is being processed by this filter
The return_to URL.


protected java.lang.String obtainUsername(javax.servlet.http.HttpServletRequest req)
Reads the claimedIdentityFieldName from the submitted request.


public void setRealmMapping(java.util.Map<java.lang.String,java.lang.String> realmMapping)
Maps the return_to url to a realm, for example: ->
If no mapping is provided then the returnToUrl will be parsed to extract the protocol, hostname and port followed by a trailing slash. This means that will automatically become

realmMapping - containing returnToUrl -> realm mappings


public void setClaimedIdentityFieldName(java.lang.String claimedIdentityFieldName)
The name of the request parameter containing the OpenID identity, as submitted from the initial login form.

claimedIdentityFieldName - defaults to "openid_identifier"


public void setConsumer(OpenIDConsumer consumer)


public void setReturnToUrlParameters(java.util.Set<java.lang.String> returnToUrlParameters)
Specifies any extra parameters submitted along with the identity field which should be appended to the return_to URL which is assembled by buildReturnToUrl(javax.servlet.http.HttpServletRequest).

returnToUrlParameters - the set of parameter names. If not set, it will default to the parameter name used by the RememberMeServices obtained from the parent class (if one is set).