Class CasAuthenticationFilter
- java.lang.Object
-
- org.springframework.web.filter.GenericFilterBean
-
- org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
-
- org.springframework.security.cas.web.CasAuthenticationFilter
-
- All Implemented Interfaces:
javax.servlet.Filter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.EnvironmentAware,org.springframework.context.MessageSourceAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class CasAuthenticationFilter extends org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilterProcesses a CAS service ticket, obtains proxy granting tickets, and processes proxy tickets.Service Tickets
A service ticket consists of an opaque ticket string. It arrives at this filter by the user's browser successfully authenticating using CAS, and then receiving a HTTP redirect to a
service. The opaque ticket string is presented in theticketrequest parameter.This filter monitors the
serviceURL so it can receive the service ticket and process it. By default this filter processes the URL /login/cas. When processing this URL, the value ofServiceProperties.getService()is used as the service when validating theticket. This means that it is important thatServiceProperties.getService()specifies the same value as the filterProcessesUrl.Processing the service ticket involves creating a
UsernamePasswordAuthenticationTokenwhich usesCAS_STATEFUL_IDENTIFIERfor theprincipaland the opaque ticket string as thecredentials.Obtaining Proxy Granting Tickets
If specified, the filter can also monitor the
proxyReceptorUrl. The filter will respond to requests matching this url so that the CAS Server can provide a PGT to the filter. Note that in addition to theproxyReceptorUrla non-nullproxyGrantingTicketStoragemust be provided in order for the filter to respond to proxy receptor requests. By configuring a sharedProxyGrantingTicketStoragebetween theTicketValidatorand the CasAuthenticationFilter one can have the CasAuthenticationFilter handle the proxying requirements for CAS.Proxy Tickets
The filter can process tickets present on any url. This is useful when wanting to process proxy tickets. In order for proxy tickets to get processed
ServiceProperties.isAuthenticateAllArtifacts()must returntrue. Additionally, if the request is already authenticated, authentication will not occur. Last,AuthenticationDetailsSource.buildDetails(Object)must return aServiceAuthenticationDetails. This can be accomplished using theServiceAuthenticationDetailsSource. In this caseServiceAuthenticationDetails.getServiceUrl()will be used for the service url.Processing the proxy ticket involves creating a
UsernamePasswordAuthenticationTokenwhich usesCAS_STATELESS_IDENTIFIERfor theprincipaland the opaque ticket string as thecredentials. When a proxy ticket is successfully authenticated, the FilterChain continues and theauthenticationSuccessHandleris not used.Notes about the
AuthenticationManagerThe configured
AuthenticationManageris expected to provide a provider that can recogniseUsernamePasswordAuthenticationTokens containing this specialprincipalname, and process them accordingly by validation with the CAS server. Additionally, it should be capable of using the result ofServiceAuthenticationDetails.getServiceUrl()as the service when validating the ticket.Example Configuration
An example configuration that supports service tickets, obtaining proxy granting tickets, and proxy tickets is illustrated below:
<b:bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties" p:service="https://service.example.com/cas-sample/login/cas" p:authenticateAllArtifacts="true"/> <b:bean id="casEntryPoint" class="org.springframework.security.cas.web.CasAuthenticationEntryPoint" p:serviceProperties-ref="serviceProperties" p:loginUrl="https://login.example.org/cas/login" /> <b:bean id="casFilter" class="org.springframework.security.cas.web.CasAuthenticationFilter" p:authenticationManager-ref="authManager" p:serviceProperties-ref="serviceProperties" p:proxyGrantingTicketStorage-ref="pgtStorage" p:proxyReceptorUrl="/login/cas/proxyreceptor"> <b:property name="authenticationDetailsSource"> <b:bean class="org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource"/> </b:property> <b:property name="authenticationFailureHandler"> <b:bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler" p:defaultFailureUrl="/casfailed.jsp"/> </b:property> </b:bean> <!-- NOTE: In a real application you should not use an in memory implementation. You will also want to ensure to clean up expired tickets by calling ProxyGrantingTicketStorage.cleanup() --> <b:bean id="pgtStorage" class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl"/> <b:bean id="casAuthProvider" class="org.springframework.security.cas.authentication.CasAuthenticationProvider" p:serviceProperties-ref="serviceProperties" p:key="casAuthProviderKey"> <b:property name="authenticationUserDetailsService"> <b:bean class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper"> <b:constructor-arg ref="userService" /> </b:bean> </b:property> <b:property name="ticketValidator"> <b:bean class="org.jasig.cas.client.validation.Cas20ProxyTicketValidator" p:acceptAnyProxy="true" p:proxyCallbackUrl="https://service.example.com/cas-sample/login/cas/proxyreceptor" p:proxyGrantingTicketStorage-ref="pgtStorage"> <b:constructor-arg value="https://login.example.org/cas" /> </b:bean> </b:property> <b:property name="statelessTicketCache"> <b:bean class="org.springframework.security.cas.authentication.EhCacheBasedTicketCache"> <b:property name="cache"> <b:bean class="net.sf.ehcache.Cache" init-method="initialise" destroy-method="dispose"> <b:constructor-arg value="casTickets"/> <b:constructor-arg value="50"/> <b:constructor-arg value="true"/> <b:constructor-arg value="false"/> <b:constructor-arg value="3600"/> <b:constructor-arg value="900"/> </b:bean> </b:property> </b:bean> </b:property> </b:bean>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCAS_STATEFUL_IDENTIFIERUsed to identify a CAS request for a stateful user agent, such as a web browser.static java.lang.StringCAS_STATELESS_IDENTIFIERUsed to identify a CAS request for a stateless user agent, such as a remoting protocol client (e.g.
-
Constructor Summary
Constructors Constructor Description CasAuthenticationFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.security.core.AuthenticationattemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)protected java.lang.StringobtainArtifact(javax.servlet.http.HttpServletRequest request)If present, gets the artifact (CAS ticket) from theHttpServletRequest.protected booleanrequiresAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Overridden to provide proxying capabilities.voidsetAuthenticationFailureHandler(org.springframework.security.web.authentication.AuthenticationFailureHandler failureHandler)Wraps theAuthenticationFailureHandlerto distinguish between handling proxy ticket authentication failures and service ticket failures.voidsetProxyAuthenticationFailureHandler(org.springframework.security.web.authentication.AuthenticationFailureHandler proxyFailureHandler)Sets theAuthenticationFailureHandlerfor proxy requests.voidsetProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage proxyGrantingTicketStorage)voidsetProxyReceptorUrl(java.lang.String proxyReceptorUrl)voidsetServiceProperties(ServiceProperties serviceProperties)protected voidsuccessfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.Authentication authResult)-
Methods inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategy, unsuccessfulAuthentication
-
-
-
-
Field Detail
-
CAS_STATEFUL_IDENTIFIER
public static final java.lang.String CAS_STATEFUL_IDENTIFIER
Used to identify a CAS request for a stateful user agent, such as a web browser.- See Also:
- Constant Field Values
-
CAS_STATELESS_IDENTIFIER
public static final java.lang.String CAS_STATELESS_IDENTIFIER
Used to identify a CAS request for a stateless user agent, such as a remoting protocol client (e.g. Hessian, Burlap, SOAP etc). Results in a more aggressive caching strategy being used, as the absence of aHttpSessionwill result in a new authentication attempt on every request.- See Also:
- Constant Field Values
-
-
Method Detail
-
successfulAuthentication
protected final void successfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.FilterChain chain, org.springframework.security.core.Authentication authResult) throws java.io.IOException, javax.servlet.ServletException- Overrides:
successfulAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
attemptAuthentication
public org.springframework.security.core.Authentication attemptAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws org.springframework.security.core.AuthenticationException, java.io.IOException- Specified by:
attemptAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter- Throws:
org.springframework.security.core.AuthenticationExceptionjava.io.IOException
-
obtainArtifact
protected java.lang.String obtainArtifact(javax.servlet.http.HttpServletRequest request)
If present, gets the artifact (CAS ticket) from theHttpServletRequest.- Parameters:
request-- Returns:
- if present the artifact from the
HttpServletRequest, else null
-
requiresAuthentication
protected boolean requiresAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)Overridden to provide proxying capabilities.- Overrides:
requiresAuthenticationin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
-
setProxyAuthenticationFailureHandler
public final void setProxyAuthenticationFailureHandler(org.springframework.security.web.authentication.AuthenticationFailureHandler proxyFailureHandler)
Sets theAuthenticationFailureHandlerfor proxy requests.- Parameters:
proxyFailureHandler-
-
setAuthenticationFailureHandler
public final void setAuthenticationFailureHandler(org.springframework.security.web.authentication.AuthenticationFailureHandler failureHandler)
Wraps theAuthenticationFailureHandlerto distinguish between handling proxy ticket authentication failures and service ticket failures.- Overrides:
setAuthenticationFailureHandlerin classorg.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
-
setProxyReceptorUrl
public final void setProxyReceptorUrl(java.lang.String proxyReceptorUrl)
-
setProxyGrantingTicketStorage
public final void setProxyGrantingTicketStorage(org.jasig.cas.client.proxy.ProxyGrantingTicketStorage proxyGrantingTicketStorage)
-
setServiceProperties
public final void setServiceProperties(ServiceProperties serviceProperties)
-
-