CAS FilterThe CAS filter is the simplest way of CAS-protecting your Java Servlets application. Configuring CASFilterJust a few lines of XML need to be added to your web application's deployment descriptor (web.xml): <web-app> ... <filter> <filter-name>CAS Filter</filter-name> <filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name> <param-value>https://secure.its.yale.edu/cas/login</param-value> </init-param> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name> <param-value>https://secure.its.yale.edu/cas/serviceValidate</param-value> </init-param> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name> <param-value>your server name and port (e.g., www.yale.edu:8080)</param-value> </init-param> </filter> <filter-mapping> <filter-name>CAS Filter</filter-name> <url-pattern>/cas-protected/*</url-pattern> </filter-mapping> ... </web-app> In this case, any URL beneath /webapp/cas-protected would require a CAS login. If you want to protect your entire web application, you can simply put /* for the URL pattern: <filter-mapping> <filter-name>CAS Filter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> The serverName initialization parameter does not require a port number if you are using the standard HTTP port (80). You can specify other initialization parameters to configure the behavior of the filter: Required CASFilter init-params
Optional CASFilter init-params
Consuming the results of CASFilterOnce the user has logged into your application through the filter, the application may access the user's name through the session attribute, edu.yale.its.tp.cas.client.filter.user, or if you import edu.yale.its.tp.cas.client.filter.CASFilter in your JSP or servlet, simply CASFilter.CAS_FILTER_USER. Accessing the authenticated username from Java // either of these will work: session.getAttribute(CASFilter.CAS_FILTER_USER); session.getAttribute("edu.yale.its.tp.cas.client.filter.user"); Accessing the authenticated username via JSTL <c:out value="${sessionScope[CAS:'edu.yale.its.tp.cas.client.filter.user']}"/>
Additionally, the client application may access a CASReceipt JavaBean-style object which exposes the username as well as additional information about the successful authentication, in the session attribute edu.yale.its.tp.cas.client.filter.receipt . // either of these will work: session.getAttribute(CASFilter.CAS_FILTER_RECEIPT); session.getAttribute("edu.yale.its.tp.cas.client.filter.receipt"); Session attributes set by CASFilter
Read more about CAS Filter behavior. |

Comments (5)
Jun 13, 2005
Mark McLaren says:
Remember: If you are using JSTL with the CAS filter and need to get hold of the ...Remember: If you are using JSTL with the CAS filter and need to get hold of the user's name through the
session attribute "edu.yale.its.tp.cas.client.filter.user". Then this
is how to do it:
<c:out value="${sessionScope['edu.yale.its.tp.cas.client.filter.user']}"/>
You need to use the above method because the usual way to access
session scope variables won't work because JSTL uses the dot as an
identifier, therefore:
<c:out value="${sessionScope.edu.yale.its.tp.cas.client.filter.user}"/>
wouldn't work.
Oct 25, 2005
Steve Stucki says:
I have just installed CAS and if I use the serviceUrl configuration, then I don'...I have just installed CAS and if I use the serviceUrl configuration, then I don't get back the "edu.yale.its.tp.cas.client.filter.user" session attribute. Also, I don't get back a remote user if I use the wrapRequest init-param. So, right now I can't get back the authenticated user name from the CAS server. What am I doing wrong?
I am not sure how to post this technical question so this may be in the wrong place.
Oct 25, 2005
Andrew Petro says:
this sort of question can be asked on the CAS discussion emial list:this sort of question can be asked on the CAS discussion emial list:
http://tp.its.yale.edu/mailman/listinfo/cas
Feb 06, 2006
Alexandr Sgibnev says:
Standart applications use request.getRemoteUser(), so they cannot use CASFilter ...Standart applications use request.getRemoteUser(), so they cannot use CASFilter directly.
To fix this problem, i has write a small wrapper, that CASFilter use for set RemoteUser:
public class CASWrapper extends javax.servlet.http.HttpServletRequestWrapper {
private String remoteUser=null;
public CASWrapper(HttpServletRequest req)
public void setRemoteUser(String user)
public String getRemoteUser()
}
This wrapper is used when CASFilter continue processing the request to chain:
// -- in CASFilter.doFilter(...) ---
CASWrapper wrapper=new CASWrapper((HttpServletRequest)request);
wrapper.setRemoteUser(receipt.getUserName());
fc.doFilter(wrapper, response);
//------------
Jul 31, 2006
Jason Shao says:
In the table above there is a note about the (optional) parameter: edu.yale.its...In the table above there is a note about the (optional) parameter:
edu.yale.its.tp.cas.client.filter.wrapRequest
if set to the string "true" the CASFilter will wrap the request such that calls to getRemoteUser() return the authenticated username.