Skip to main content

Connect a CAS client

This guide explains how to connect an application that supports the Central Authentication Service (CAS) protocol to Casdoor. Casdoor is a CAS server for CAS 1.0, 2.0, and 3.0.


Learning outcomes​

  • Find the CAS endpoints of a Casdoor application.
  • Allow the services of the client in the application.
  • Point a CAS client at Casdoor.
  • Choose the CAS version that the client uses.

What you need​

Sample code​


CAS endpoints​

Each Casdoor application has its own CAS endpoints under the prefix:

<casdoor-host>/cas/<organization>/<application>

For example, for the demo site https://door.casdoor.com, the organization casbin, and the application cas-java-app, the prefix is https://door.casdoor.com/cas/casbin/cas-java-app. Casdoor serves the following endpoints under the prefix:

EndpointCAS version
/loginAll
/logoutAll
/validate1.0
/serviceValidate2.0
/proxyValidate2.0
/proxy2.0
/p3/serviceValidate3.0
/p3/proxyValidate3.0
/samlValidateSAML 1.1 validation

For the parameters of each endpoint, see the CAS protocol specification.

Configure the application​

Casdoor issues tickets only for services that the application allows.

  1. In the Casdoor admin console, open the application and go to the OIDC/OAuth tab.
  2. Add the URL of each CAS service, the service parameter that the CAS client sends, to Redirect URLs. If the client uses proxy authentication, also add its proxy callback URL (pgtUrl) and the URLs of the target services of /proxy.
  3. Click Save.

Casdoor matches service against Redirect URLs in the same way as an OAuth redirect URL. An empty list allows no service, and script URLs, such as javascript: URLs, are always refused. A sign-in with a service that isn't allowed fails with Redirect URI: <service> doesn't exist in the allowed Redirect URI list.

Ticket validation​

When the CAS client validates a ticket, Casdoor applies these rules:

  • The service of the validation request must be exactly the service for which Casdoor issued the ticket, or its URL-encoded form. A service that only starts with the issued service doesn't match.
  • Service tickets and proxy tickets work once, and expire 5 minutes after Casdoor issues them. A used or expired ticket fails with INVALID_TICKET, or with no at /validate.
  • /serviceValidate and /p3/serviceValidate accept only service tickets, which start with ST. /proxyValidate and /p3/proxyValidate accept service tickets and proxy tickets.
  • pgtUrl must be an https URL that is in Redirect URLs. Otherwise, the validation fails with INVALID_PROXY_CALLBACK. Casdoor calls the callback with a timeout of 10 seconds and doesn't follow redirects. For applications outside the built-in organization, the callback must be an Internet address, not a private or loopback address.
  • /proxy issues a proxy ticket only for a targetService that is in Redirect URLs. Otherwise, it answers UNAUTHORIZED_SERVICE.
caution

Casdoor keeps tickets in memory. If you run several replicas of Casdoor, route the validation request to the replica that issued the ticket, for example with sticky sessions, or the validation fails.

Configure the Java CAS client​

The Apereo CAS sample Java web application works with Casdoor. Its CAS configuration is in src/main/webapp/WEB-INF/web.xml.

  1. Change every casServerUrlPrefix parameter to the CAS prefix of your Casdoor application:

    <param-name>casServerUrlPrefix</param-name>
    <param-value>http://door.casdoor.com/cas/casbin/cas-java-app</param-value>
  2. Change every casServerLoginUrl parameter to the /login endpoint:

    <param-name>casServerLoginUrl</param-name>
    <param-value>http://door.casdoor.com/cas/casbin/cas-java-app/login</param-value>
  3. Choose the CAS version through the validation filter. By default, the sample uses CAS 3.0:

    <filter-name>CAS Validation Filter</filter-name>
    <filter-class>org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter</filter-class>

    For CAS 2.0, use:

    <filter-name>CAS Validation Filter</filter-name>
    <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>

    For CAS 1.0, use:

    <filter-name>CAS Validation Filter</filter-name>
    <filter-class>org.jasig.cas.client.validation.Cas10TicketValidationFilter</filter-class>

For the other settings of the client, see the Java CAS client repository.

See also​