org.jasig.services.persondir.support.web
Class RequestAttributeSourceFilter

java.lang.Object
  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.jasig.services.persondir.support.web.RequestAttributeSourceFilter
All Implemented Interfaces:
javax.servlet.Filter, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.web.context.ServletContextAware

public class RequestAttributeSourceFilter
extends org.springframework.web.filter.GenericFilterBean

Filter that can provide HttpServletRequest headers and other properties on the request as person attributes. The filter sets attributes on a IAdditionalDescriptors which it is configured with. To work correctly the IAdditionalDescriptors object needs to be a session scoped Spring bean so that each user gets only their own attributes correctly.

Configuration:

Property Description Required Default
usernameAttribute The name of the attribute from the request (header or property) to use as the username. This is required so that Person Directory can later associate these attributes with the user correctly during queries. Yes null
cookieAttributeMapping Set the Map to use for mapping from a cookie name to an attribute name or Set of attribute names. Cookie names that are specified but have null mappings will use the column name for the attribute name. Cookie names that are not specified as keys in this Map will be ignored.
The passed Map must have keys of type String and values of type String or a Set of String.
Yes null
headerAttributeMapping Set the Map to use for mapping from a header name to an attribute name or Set of attribute names. Header names that are specified but have null mappings will use the column name for the attribute name. Header names that are not specified as keys in this Map will be ignored.
The passed Map must have keys of type String and values of type String or a Set of String.
Yes null
additionalDescriptors The IAdditionalDescriptors object to set attributes found on the request into. The provided object should be a Spring session scoped bean which will allow each user to have their own version attached to their session. Yes null
remoteUserAttribute If specified HttpServletRequest.getRemoteUser() is called and the returned value is stored as an attribute using the value specified for this property. No null
remoteAddrAttribute If specified ServletRequest.getRemoteAddr() is called and the returned value is stored as an attribute using the value specified for this property. No null
serverNameAttribute If specified ServletRequest.getServerName() is called and the returned value is stored as an attribute using the value specified for this property. No null
serverPortAttribute If specified ServletRequest.getServerPort() is called and the returned value is stored as an attribute using the value specified for this property. No null
clearExistingAttributes If true when attributes are found on the request any existing attributes in the provided IAdditionalDescriptors object will cleared and replaced with the new attributes. If false the new attributes overwrite existing attributes of the same name but attributes in IAdditionalDescriptors not found on the current request are not touched. No false

Version:
$Revision$
Author:
Eric Dalquist

Nested Class Summary
static class RequestAttributeSourceFilter.ProcessingPosition
           
 
Field Summary
 
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
 
Constructor Summary
RequestAttributeSourceFilter()
           
 
Method Summary
protected  void addRequestCookies(javax.servlet.http.HttpServletRequest httpServletRequest, Map<String,List<Object>> attributes)
          Add request cookies to the attributes map
protected  void addRequestHeaders(javax.servlet.http.HttpServletRequest httpServletRequest, Map<String,List<Object>> attributes)
          Add request headers to the attributes map
protected  void addRequestProperties(javax.servlet.http.HttpServletRequest httpServletRequest, Map<String,List<Object>> attributes)
          Add other properties from the request to the attributes map
 void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain chain)
           
 IAdditionalDescriptors getAdditionalDescriptors()
           
 Map<String,Set<String>> getCookieAttributeMapping()
           
 Map<String,Set<String>> getHeaderAttributeMapping()
           
 RequestAttributeSourceFilter.ProcessingPosition getProcessingPosition()
           
 String getRemoteAddrAttribute()
           
 String getRemoteHostAttribute()
           
 String getRemoteUserAttribute()
           
 String getServerNameAttribute()
           
 String getServerPortAttribute()
           
 String getUsernameAttribute()
           
 boolean isClearExistingAttributes()
           
 void setAdditionalDescriptors(IAdditionalDescriptors additionalDescriptors)
          The AdditionalDescriptors instance to set request attributes on.
 void setClearExistingAttributes(boolean clearExistingAttributes)
           
 void setCookieAttributeMapping(Map<String,?> cookieAttributeMapping)
          Set the Map to use for mapping from a cookie name to an attribute name or Set of attribute names.
 void setHeaderAttributeMapping(Map<String,?> headerAttributeMapping)
          Set the Map to use for mapping from a header name to an attribute name or Set of attribute names.
 void setProcessingPosition(RequestAttributeSourceFilter.ProcessingPosition processingPosition)
          Sets the pre/post/both position of the processing relative to the doFilter call.
 void setRemoteAddrAttribute(String remoteAddrAttribute)
          If specified ServletRequest.getRemoteAddr() is added as an attribute under the provided name
 void setRemoteHostAttribute(String remoteHostAttribute)
          If specified ServletRequest.getRemoteHost() is added as an attribute under the provided name
 void setRemoteUserAttribute(String remoteUserAttribute)
          If specified HttpServletRequest.getRemoteUser() is added as an attribute under the provided name
 void setServerNameAttribute(String serverNameAttribute)
          If specified ServletRequest.getServerName() is added as an attribute under the provided name
 void setServerPortAttribute(String serverPortAttribute)
          If specified ServletRequest.getServerPort() is added as an attribute under the provided name
 void setUsernameAttribute(String usernameAttribute)
          The name of the attribute from the request to use as the username
 
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, 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
 

Constructor Detail

RequestAttributeSourceFilter

public RequestAttributeSourceFilter()
Method Detail

getUsernameAttribute

public String getUsernameAttribute()

setUsernameAttribute

public void setUsernameAttribute(String usernameAttribute)
The name of the attribute from the request to use as the username


getRemoteUserAttribute

public String getRemoteUserAttribute()

setRemoteUserAttribute

public void setRemoteUserAttribute(String remoteUserAttribute)
If specified HttpServletRequest.getRemoteUser() is added as an attribute under the provided name


getRemoteAddrAttribute

public String getRemoteAddrAttribute()

setRemoteAddrAttribute

public void setRemoteAddrAttribute(String remoteAddrAttribute)
If specified ServletRequest.getRemoteAddr() is added as an attribute under the provided name


getRemoteHostAttribute

public String getRemoteHostAttribute()

setRemoteHostAttribute

public void setRemoteHostAttribute(String remoteHostAttribute)
If specified ServletRequest.getRemoteHost() is added as an attribute under the provided name


getServerNameAttribute

public String getServerNameAttribute()

setServerNameAttribute

public void setServerNameAttribute(String serverNameAttribute)
If specified ServletRequest.getServerName() is added as an attribute under the provided name


getServerPortAttribute

public String getServerPortAttribute()

setServerPortAttribute

public void setServerPortAttribute(String serverPortAttribute)
If specified ServletRequest.getServerPort() is added as an attribute under the provided name


getAdditionalDescriptors

public IAdditionalDescriptors getAdditionalDescriptors()

setAdditionalDescriptors

public void setAdditionalDescriptors(IAdditionalDescriptors additionalDescriptors)
The AdditionalDescriptors instance to set request attributes on. This should be a Spring session-scoped proxy to allow each session to have its own set of request-populated attributes.


isClearExistingAttributes

public boolean isClearExistingAttributes()

setClearExistingAttributes

public void setClearExistingAttributes(boolean clearExistingAttributes)
Parameters:
clearExistingAttributes - If existing all attributes should be cleared when any new attributes are found. Defaults to false.

getProcessingPosition

public RequestAttributeSourceFilter.ProcessingPosition getProcessingPosition()

setProcessingPosition

public void setProcessingPosition(RequestAttributeSourceFilter.ProcessingPosition processingPosition)
Sets the pre/post/both position of the processing relative to the doFilter call. PRE means the attribute processing happens before the doFilter call POST means the attribute processing happens after the doFilter call BOTH means the attribute processing happens before and after the doFilter call


getCookieAttributeMapping

public Map<String,Set<String>> getCookieAttributeMapping()

setCookieAttributeMapping

public void setCookieAttributeMapping(Map<String,?> cookieAttributeMapping)
Set the Map to use for mapping from a cookie name to an attribute name or Set of attribute names. Cookie names that are specified but have null mappings will use the column name for the attribute name. Cookie names that are not specified as keys in this Map will be ignored.
The passed Map must have keys of type String and values of type String or a Set of String.

Parameters:
cookieAttributeMapping - Map from cookie names to attribute names, may not be null.
Throws:
IllegalArgumentException - If the Map doesn't follow the rules stated above.
See Also:
MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)

getHeaderAttributeMapping

public Map<String,Set<String>> getHeaderAttributeMapping()

setHeaderAttributeMapping

public void setHeaderAttributeMapping(Map<String,?> headerAttributeMapping)
Set the Map to use for mapping from a header name to an attribute name or Set of attribute names. Header names that are specified but have null mappings will use the column name for the attribute name. Header names that are not specified as keys in this Map will be ignored.
The passed Map must have keys of type String and values of type String or a Set of String.

Parameters:
headerAttributeMapping - Map from column names to attribute names, may not be null.
Throws:
IllegalArgumentException - If the Map doesn't follow the rules stated above.
See Also:
MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)

doFilter

public final void doFilter(javax.servlet.ServletRequest servletRequest,
                           javax.servlet.ServletResponse servletResponse,
                           javax.servlet.FilterChain chain)
                    throws IOException,
                           javax.servlet.ServletException
Throws:
IOException
javax.servlet.ServletException

addRequestProperties

protected void addRequestProperties(javax.servlet.http.HttpServletRequest httpServletRequest,
                                    Map<String,List<Object>> attributes)
Add other properties from the request to the attributes map


addRequestCookies

protected void addRequestCookies(javax.servlet.http.HttpServletRequest httpServletRequest,
                                 Map<String,List<Object>> attributes)
Add request cookies to the attributes map


addRequestHeaders

protected void addRequestHeaders(javax.servlet.http.HttpServletRequest httpServletRequest,
                                 Map<String,List<Object>> attributes)
Add request headers to the attributes map



Copyright © 2012 Jasig. All Rights Reserved.