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.
| Modifier and Type | Class and Description |
|---|---|
static class |
RequestAttributeSourceFilter.ProcessingPosition |
| Constructor and Description |
|---|
RequestAttributeSourceFilter() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addRequestAttributes(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
Add specified request parameters to the attributes map.
|
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 |
addRequestParameters(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
Add specified request parameters 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() |
Set<String> |
getHeadersToIgnoreSemicolons() |
Map<String,Set<String>> |
getParameterAttributeMapping() |
RequestAttributeSourceFilter.ProcessingPosition |
getProcessingPosition() |
String |
getReferringParameterName() |
String |
getRemoteAddrAttribute() |
String |
getRemoteHostAttribute() |
String |
getRemoteUserAttribute() |
Map<String,Set<String>> |
getRequestAttributeMapping() |
String |
getServerNameAttribute() |
String |
getServerPortAttribute() |
String |
getUrlCharacterEncoding() |
String |
getUsernameAttribute() |
boolean |
isClearExistingAttributes() |
void |
setAdditionalDescriptors(IAdditionalDescriptors additionalDescriptors)
The
IAdditionalDescriptors instance to set request attributes on. |
void |
setClearExistingAttributes(boolean 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. |
void |
setCookieAttributeMapping(Map<String,?> cookieAttributeMapping)
|
void |
setHeaderAttributeMapping(Map<String,?> headerAttributeMapping)
|
void |
setHeadersToIgnoreSemicolons(Set<String> headersToIgnoreSemicolons)
Set of header values to ignore splitting on semicolons.
|
void |
setParameterAttributeMapping(Map<String,?> parameterAttributeMapping)
|
void |
setProcessingPosition(RequestAttributeSourceFilter.ProcessingPosition processingPosition)
Sets the pre/post/both position of the processing relative to the doFilter call.
|
void |
setReferringParameterName(String referringParameterName)
Name of a request parameter whose value is decoded and checked for
parameterAttributeMapping matches. |
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 |
setRequestAttributeMapping(Map<String,?> requestAttributeMapping)
|
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 |
setUrlCharacterEncoding(String urlCharacterEncoding)
Sets the URL character encoding to use to decode the value of the
referringParameterName if it
was specified. |
void |
setUsernameAttribute(String usernameAttribute)
The name of the attribute from the request (header or property) to use as the username.
|
public String getUsernameAttribute()
public void setUsernameAttribute(String usernameAttribute)
usernameAttribute - Name of the attribute from the request (header or property) to use as the usernamepublic String getRemoteUserAttribute()
public void setRemoteUserAttribute(String remoteUserAttribute)
HttpServletRequest.getRemoteUser() is added as an attribute under the provided nameremoteUserAttribute - Name of the attribute to add when HttpServletRequest.getRemoteUser() is invokedpublic String getRemoteAddrAttribute()
public void setRemoteAddrAttribute(String remoteAddrAttribute)
ServletRequest.getRemoteAddr() is added as an attribute under the provided nameremoteAddrAttribute - Name of the attribute to add when ServletRequest.getRemoteAddr() is invokedpublic String getRemoteHostAttribute()
public void setRemoteHostAttribute(String remoteHostAttribute)
ServletRequest.getRemoteHost() is added as an attribute under the provided nameremoteHostAttribute - Name of the attribute to add when ServletRequest.getRemoteHost() is invokedpublic String getServerNameAttribute()
public void setServerNameAttribute(String serverNameAttribute)
ServletRequest.getServerName() is added as an attribute under the provided nameserverNameAttribute - Name of the attribute to add when ServletRequest.getServerName() is invokedpublic String getServerPortAttribute()
public void setServerPortAttribute(String serverPortAttribute)
ServletRequest.getServerPort() is added as an attribute under the provided nameserverPortAttribute - Name of the attribute to add when ServletRequest.getServerPort() is invokedpublic IAdditionalDescriptors getAdditionalDescriptors()
public void setAdditionalDescriptors(IAdditionalDescriptors additionalDescriptors)
IAdditionalDescriptors 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.additionalDescriptors - IAdditionalDescriptors instance to set request attributes onpublic boolean isClearExistingAttributes()
public void setClearExistingAttributes(boolean clearExistingAttributes)
IAdditionalDescriptors
object will cleared and replaced with the new attributes. If false (default) the new attributes overwrite existing
attributes of the same name but attributes in IAdditionalDescriptors not found on the current request
are not touched.clearExistingAttributes - If existing all attributes should be cleared when any new attributes are found.public RequestAttributeSourceFilter.ProcessingPosition getProcessingPosition()
public void setProcessingPosition(RequestAttributeSourceFilter.ProcessingPosition processingPosition)
processingPosition - Processing positionpublic void setCookieAttributeMapping(Map<String,?> cookieAttributeMapping)
Map to use for mapping from a cookie name to an attribute name or Set of attribute
names. Cookie names that are not specified as keys in this Map will be ignored.
Map must have keys of type String and values of type String or a Set
of String.cookieAttributeMapping - Map from cookie names to attribute names, may not be null.IllegalArgumentException - If the Map doesn't follow the rules stated above.MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)public void setHeaderAttributeMapping(Map<String,?> headerAttributeMapping)
Map to use for mapping from a header name to an attribute name or Set of attribute
names. Header names that are not specified as keys in this Map will be ignored.
Map must have keys of type String and values of type String or a Set
of String.headerAttributeMapping - Map from header names to attribute names, may not be null.IllegalArgumentException - If the Map doesn't follow the rules stated above.MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)public void setRequestAttributeMapping(Map<String,?> requestAttributeMapping)
Map to use for mapping from a request attributes to an attribute name or Set of attribute
names. Request attributes that are not specified as keys in this Map will be ignored.
Map must have keys of type String and values of type String or a Set
of String.requestAttributeMapping - Map from request attributes to attribute names, may not be null.IllegalArgumentException - If the Map doesn't follow the rules stated above.MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)public void setParameterAttributeMapping(Map<String,?> parameterAttributeMapping)
Map to use for mapping from a parameter name to an attribute name or Set of attribute
names. Parameter names that are not specified as keys in this Map will be ignored.
Map must have keys of type String and values of type String or a Set
of String.parameterAttributeMapping - Map from parameter names to attribute names, may not be null.IllegalArgumentException - If the Map doesn't follow the rules stated above.MultivaluedPersonAttributeUtils.parseAttributeToAttributeMapping(Map)public String getReferringParameterName()
public void setReferringParameterName(String referringParameterName)
parameterAttributeMapping matches.
This is useful when the user's browser follows a redirect path and the request parameters from the user's original
request are encoded in a 'refUrl' or similar parameter. uPortal, for instance, does this. When a user accesses
/uPortal?nativeClient=true, a redirect chain encodes this to '/uPortal/Login?refUrl=%2FuPortal%2F%3FnativeClient%3Dtrue'.
Has no effect if not specified or if parameterAttributeMapping does not have matches to request
parameters in the referringParameterName. If specified, parameterAttributeMapping
matches in first the referringParameterName and then the request parameters (thus would overwrite).referringParameterName - Name of a request parameter to decode and inspect for
parameterAttributeMapping matches.public String getUrlCharacterEncoding()
public void setUrlCharacterEncoding(String urlCharacterEncoding)
referringParameterName if it
was specified. Defaults to UTF-8.urlCharacterEncoding - URL character encoding namepublic void setHeadersToIgnoreSemicolons(Set<String> headersToIgnoreSemicolons)
headersToIgnoreSemicolons - Set of HTTP Header names to not split its value on semicolons into
multiple valuespublic final void doFilter(javax.servlet.ServletRequest servletRequest,
javax.servlet.ServletResponse servletResponse,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
IOExceptionjavax.servlet.ServletExceptionprotected void addRequestProperties(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
httpServletRequest - Http Servlet Requestattributes - Map of attributes to add additional attributes to from the Http Requestprotected void addRequestCookies(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
httpServletRequest - Http Servlet Requestattributes - Map of attributes to add additional attributes to from the Http Requestprotected void addRequestHeaders(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
httpServletRequest - Http Servlet Requestattributes - Map of attributes to add additional attributes to from the Http Requestprotected void addRequestAttributes(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
httpServletRequest - Servlet Requestattributes - Map of attributes to add additional attributes to from the Http Requestprotected void addRequestParameters(javax.servlet.http.HttpServletRequest httpServletRequest,
Map<String,List<Object>> attributes)
httpServletRequest - Servlet Requestattributes - Map of attributes to add additional attributes to from the Http RequestCopyright © 2015 Jasig. All Rights Reserved.