CAS Client for Java

Example Java Configuration for Applications

The example below is a stripped-down web.xml that is used to demonstrate configuring the basic JASIG CAS Client for Java. This client provides no authorization capabilities. You can retrieve the username of the person who logged in by calling request.getRemoteUser().

For more advanced usage of this CAS client, please see the official documentation.

You can obtain the CAS client by configuring the following in your Maven2 POM file:

  1. <dependency>
  2.     <artifactId>cas-client-core</artifactId>
  3.     <groupId>org.jasig.cas</groupId>
  4.     <version>3.1.3</version>
  5.     <scope>runtime</scope>
  6. </dependency>

Example web.xml

  1. <?xml version=“1.0” encoding=“ISO-8859-1”?>
  2. <web-app xmlns=“http://java.sun.com/xml/ns/j2ee” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd” version=“2.4”>
  3.     <display-name>Sample CASified Application</display-name>
  4.     <description>
  5.         A sample application that demonstrates the CAS client.
  6.     </description>
  7.     <context-param>
  8.         <param-name>serverName</param-name>
  9.         <param-value>https://myserver.rutgers.edu</param-value>
  10.     </context-param>
  11.     <filter>
  12.         <filter-name>CAS Authentication Filter</filter-name>
  13.         <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
  14.         <init-param>
  15.             <param-name>casServerLoginUrl</param-name>
  16.             <param-value>https://test-cas.rutgers.edu/login</param-value>
  17.         </init-param>
  18.     </filter>
  19.     <filter>
  20.         <filter-name>CAS Validation Filter</filter-name>
  21.         <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
  22.         <init-param>
  23.             <param-name>casServerUrlPrefix</param-name>
  24.             <param-value>https://test-cas.rutgers.edu</param-value>
  25.         </init-param>
  26.     </filter>
  27.     <filter>
  28.         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
  29.         <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
  30.     </filter>
  31.     <filter-mapping>
  32.         <filter-name>CAS Authentication Filter</filter-name>
  33.         <url-pattern>/*</url-pattern>
  34.     </filter-mapping>
  35.     <filter-mapping>
  36.         <filter-name>CAS Validation Filter</filter-name>
  37.         <url-pattern>/*</url-pattern>
  38.     </filter-mapping>
  39.     <filter-mapping>
  40.         <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
  41.         <url-pattern>/*</url-pattern>
  42.     </filter-mapping>
  43.     <servlet>
  44.         <servlet-name>Manager</servlet-name>
  45.         <servlet-class>edu.rutgers.my.servlet.Servlet</servlet-class>
  46.     </servlet>
  47.     <servlet-mapping>
  48.         <servlet-name>Manager</servlet-name>
  49.         <url-pattern>/*</url-pattern>
  50.     </servlet-mapping>
  51. </web-app>

Related Articles