Connect to the Purdue Home Page

Purdue University

Identity and Access Management

Purdue Java CAS Client configuration

Get the Java CAS client

We've been using version 3.1.12, downloads can be found here.

web.xml

    <filter>
        <filter-name>CAS Authentication Filter</filter-name>
        <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
        <init-param>
            <param-name>casServerLoginUrl</param-name>
            <param-value>https://www.purdue.edu/apps/account/cas/login</param-value>
        </init-param>
        <init-param>
            <param-name>serverName</param-name>
            <param-value>https://www.purdue.edu</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>CAS Validation Filter</filter-name>
        <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
        <init-param>
            <param-name>casServerUrlPrefix</param-name>
            <param-value>https://www.purdue.edu/apps/account/cas</param-value>
        </init-param>
        <init-param>
            <param-name>serverName</param-name>
            <param-value>https://www.purdue.edu</param-value>
        </init-param>
        <init-param>
            <param-name>redirectAfterValidation</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>exceptionOnValidationFailure</param-name>
            <param-value>false</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
        <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>CAS Authentication Filter</filter-name>
        <url-pattern>/yourapp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>CAS Validation Filter</filter-name>
        <url-pattern>/yourapp</url-pattern>
    </filter-mapping>
    <filter-mapping>
        <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
        <url-pattern>/yourapp</url-pattern>
    </filter-mapping>
        

servlet code

    import org.jasig.cas.client.authentication.AttributePrincipal;

    String authenticatedLogin = request.getRemoteUser();

    // cas client as of 3.1.12 does not specify the Map types
    Map<?,?> attrs = ((AttributePrincipal)request.getUserPrincipal()).getAttributes();
    if( attrs == null ) {
        throw new ServletException("no attributes set by the CAS client");
    }

    String puid = (String)attrs.get("puid");  // always 10 digit leading zeros
    String email = (String)attrs.get("email");
    String lastname = (String)attrs.get("lastname");
    String firstname = (String)attrs.get("firstname");
    String fullname = (String)attrs.get("fullname");

    // multi valued attributes have to be passed as comma separated Strings through serviceValidate (as of Java CAS client 3.1.12)
    // (characteristic definitions can be found at https://www.purdue.edu/apps/account/I2A2Char)
    List<String> i2a2characteristics = Arrays.asList(((String)attrs.get("i2a2characteristics")).split(","));
        

You may choose to place the above servlet code into a servlet filter that fills a data transfer object, since that would separate your servlet code from any references to CAS altogether.

Questions

Please contact accounts@purdue.edu.

Feedback | Contact Purdue
Maintained by: IAMO Team

Purdue University, West Lafayette, IN 47907, (765) 494-4600
© 2010 - 2013 Purdue University | An equal access/equal opportunity university | Copyright Complaints
If you have trouble accessing this page because of a disability, please contact the CSC at itap@purdue.edu or (765) 494-4000.