CAS 3 Architecture
CAS 2 was written at Yale and was a Servlet. It was tiny compared to subsequent versions of CAS, but it just did the basic features and that was enough.
CAS 3 was a replacement that performed the same functions and used the same protocol, but provided a base to add additional optional features. The Spring Framework was selected as the base technology. Spring is good because it creates an application that can be reconfigured by changing some XML files without writing new code. If you are a Java programmer, then Spring provides its own richer API for doing lots of things that can be done with vanilla Java, but you have to read a new manual to understand them. This is not a place where I can reasonably introduce Spring, so either you know it or you can pick up a book.
CAS 5 has been released as a simpler configuration solution. The problem with CAS 3 is that every Bean of Java code was connected to every other Bean with an explicit XML configuration element. This is very powerful, but it produces massive configuration files that take time to learn and use. Subsequent generations of Spring have adopted an "autowire" approach, where default configuration is done with annotations in the Java source. CAS 5 can be configured with one very large properties file. You specify the properties of the options you select, and any option where you specify no properties simply doesn't get used.
Since we are currently using CAS 3, this document will tend to show XML configuration of Beans. The same Beans are still there in CAS 5, but some element will be configured differently.
CAS was designed to be flexible. In the original design, flexible meant that it would be easy to add new function by adding new Java code. Later releases were targeted to campuses with no Java development capability, so more recently flexibility is the opportunity to select from prepackaged options. Since Yale has had Java developers and has worked with CAS from the beginning, we have not been scared to write a little code and make CAS work exactly the way we want it to.
So to get along with CAS at Yale, you need to know a bit of the design that normally only developers care about.
Java creates objects with the "new" statement, and if the object requires parameters in order to fill in required fields, then they are passed to the "constructor". Spring creates Beans, which is an instance of a named class represented by an XML "Bean" element in some Spring configuration file. If the object requires parameters to fill in the values of required fields, then those parameters are in the XML as either Attributes of the Bean element of child elements of the Bean.
Java classes may require that a field be assigned a reference to another Bean. This is called "injection". Typically there will be an interface that defines the function that the Bean provides, and if in the entire application there is only one Bean that implements this interface then there is no problem figuring out what type of class has to be injected. However, there are several different ways that a password can be validated, and several different ways to store Ticket information for future use, and several ways to configure Services. In these cases you have to configure one specific choice from the many types of Beans that could provide the functions needed by the interface. In CAS 3 you would generate one XML element that names the class you have selected to perform the function. In CAS 5, you provide initialization parameters for the one class that could be used to satisfy the interface, and if you did not provide parameters that would allow any of the alternatives you might have selected to actually be loaded and run, then the only Bean that can be initialized must be the one that provides the required interface services.
There are a few objects that are created by the Tomcat container (a Request, a Response, a Session, and the things connected to them). There are also a few data objects that CAS creates during normal request processing: Credentials (a userid and password), Tickets (login or service tickets), Services. Everything else is a Spring Bean.
The good news is that CAS has a well defined set of layers represented by interfaces, and these layers can be described using the standard J2EE terminology. The next step is then to identify the key configuration components for each layer or interface and how they fit into the overall CAS process.
- The front end is a "Presentation Layer" that handles arriving HTTP requests. It is divided into two parts:
- The end user login from the browser is handled by a Spring Webflow configured in XML. If the user is already logged in (the CAS Cookie is present) then the request may be handled automatically as a Single SignOn. If not, the flow can optionally look for non-interactive forms of authentication like a User X.509 certificate and private key installed in the Browser. Otherwise, the flow presents the CAS Login page and gets the userid and password. Finally it generates the Cookie and returns the Service Ticket ID string.
- However, CAS also gets administrative requests and Service Ticket validation requests (/serviceValidate). These are handled by the Spring MVC mechanism, which is basically the Spring version of a Servlet.
- The Business Layer (where J2EE would have EJBs) validates the login (by verifying the userid/password against a backend system such as Kerberos or LDAP), and it creates Tickets including the Login TGT and Service Tickets.
- Tickets are stored in a Ticket Cache. Normally this is just an in-memory collection, although it can be replicated (for clustered failover) or stored in a shared database. Since Tickets can be persisted (even though they frequently aren't) they become Entities in a logical Persistence Layer.
Presentation Layer
CAS 3 uses two different Spring APIs to configure and code the Presentation Layer.
Protocol (Validate) Requests
The calls to validate Service Tickets and issue Proxy Tickets are processed by Spring MVC configured in the WEB-INF/cas-servlet.xml file.Spring "Action" Beans are configured that expose a method that receives the Request and Response object of an incoming HTTP operation.
<bean id="serviceValidateController" class="org.jasig.cas.web.ServiceValidateController" p:validationSpecificationClass="org.jasig.cas.validation.Cas20WithoutProxyingValidationSpecification" p:centralAuthenticationService-ref="centralAuthenticationService" p:proxyHandler-ref="proxy20Handler" p:argumentExtractor-ref="casArgumentExtractor" />
Action Beans are essentially Servlets, only with a Spring flavor. Parameters from the request are "bound" (used to set the properties of a bean). The Action Bean is inside the ApplicationContext, so it gets dependency injection. It returns an object (ModelAndView) that identifies the response (typically a JSP page although it can be a View Bean) and provides a Map of data that the JSP EL can use to populate variable fields in the response page.
Each Action Bean is called when the end of a request URL contains a string mapped to the Bean (again in cas-servlet.xml):
<prop key="/serviceValidate"> serviceValidateController </prop>
Login Webflow
The "/login" function is mapped to an entirely separate API called Spring WebFlow. WebFlow is a common computer design pattern called a "State Machine" coded as a sequence of XML elements in the WEB-INF/login-webflow.xml file. In some sense, a WebFlow demonstrates how to replace a dozen lines of Java with a hundred lines of considerably more complex XML (but at least you are not coding).
Each state is represented by an XML element that either performs a simple EL test or else calls a Bean method. The result of the test or return value of the method is "success" or "error" and generates a transition (a GOTO) to another state.
<action-state id="startAuthenticate"> <action bean="x509Check" /> <transition on="success" to="sendTicketGrantingTicket" /> <transition on="error" to="viewLoginForm" /> </action-state>
When the login flow gets to this state, it calls a method of the x509Check Bean (which determines if the Request has a valid X.509 Certificate that can be used to login the user). A return of "success" means the user has logged on and proceeds to a state/bean that generates the Ticket Granting Cookie in the response object. An "error" means that there is no certificate, so the normal interactive Login form is displayed.
The flow continues until there is a transition to an "end-state" which either displays a JSP page or else redirects the Browser to another page.
Ideally, the Presentation Layer would be the only component that deals with the Servlet API and its Request, Response, and Session objects. That is certainly possible for userid/password, but certain credentials may be inherently tied to the underlying socket and communications layers.
Business Logic
The Business Logic layer of CAS represents a set of services configured by the WEB-INF/deployerConfigContext.xml file. In a normal J2EE design, these would be the EJBs.
The entry to the Business Logic layer is the CentralAuthenticationService Interface. In a real EJB configuration, this would be the local service interface. It defines methods to create a TicketGrantingTicket (by logging on a user if the credentials presented are valid), create and validate ServiceTickets, and log the user off.
The rest of the Business Logic layer consists of secondary internal service interfaces configured in Spring and injected into other beans.
The most important secondary internal service, and the most important Spring configuration element, is the AuthenticationManager. An AuthenticationManager supports login requests, validating the user Credentials and generating (after a sucessful login) the TGT.
Each type of AuthenticationManager accepts as a Spring configuration property some sort of collection of AuthenticationHandlers and CredentialsToPrincipalResolvers. To simplify further documentation, we will call these Handlers and Resolvers.
Credentials are created by the Presentation Layer from something in the HTTP request. In the simple case, the Userid and Password are extracted from the form and combined to create a Credential object. If the container is configured to accept User Certificates, an X.509 Certificate can be extracted from the Request object and presented as a Credential. If SPNEGO is enabled, then the Browser of a client logged into a Kerberos 5 realm (typically an Active Directory Domain) can present a Kerberos 5 Service Ticket as proof of identity. Of course in the real world, most credentials consist of a userid and password string.
In the Spring configuration file, the AuthenticationManager has a property that gets a List of AuthenticationHandlers. Each Handler is called in turn and is given a chance to accept or pass on a particular type of credential. An X.509 Handler will only look at Certificate credentials and will pass on userid/password credentials. There can be more than one userid/password Handler if you want to authenticate users to multiple backend systems. Spring configuration allows you to plug in a Handler that does LDAP if you want to authenticate passwords using LDAP, or JAAS if you want to authenticate passwords using Kerberos.
When X.509 User Certificates are enabled to Tomcat or JBoss, then the container has already verified that the Certificate was digitally signed by a Certificate Authority in its list of configured "trusted" CAs. With SPNEGO, all the Kerberos 5 keys and tickets protocol has already been done down in the presentation layer using the Java interface to the system GSSAPI service. So some AuthenticationHandlers really validate the Credentials, while others simply verify that the type of object corresponds to something the container or Presentation Layer has already validated and then returns "true" because such Credentials are implicitly trusted.
A CredentialsToPrincipalResolver extracts the Principal (user) from the Credentials. For a userid/password, the Principal is just the userid. However, an X.509 certificate has a Distinguished Name and various SubjectAltNames from which a Principal may be determined. There is also the question of whether the Principal name should be qualified or not. At Yale, the Netid "gilbert" may also be identified as "yale\gilbert" (AD), "gilbert@YU.YALE.EDU" (Kerberos realm), "Howard.Gilbert@yale.edu" (EMail address and AD Universal Principal Name). Fully qualified principal names become more important when independent organizations join in some sort of Identity Federation.
There is enough flexibility here to get really confused. Words like Subject, Principal, and Realm are used throughout Java Security, JBoss, and CAS to mean roughly the same idea but with slight variations. Sometimes a precise technical needs to be applied at one point to make things work, but then in other places a more general meaning may be required. Consider the idea of a Principal.
- The user types something into a form. Since he is an end user, it should be as simple as possible. Suppose he types "gilbert".
- The AuthenticationHandler validates the Credential object containing "gilbert". However, in order to authenticate to a particular back end service, it may be necessary to transform what was typed in to something specific to that particular back end service. At Yale, if you want to use Kerberos 5 protocol to the MIT Kerberos servers you would use Principal name "gilbert@NET.YALE.EDU", while using the same protocol against Active Directory would use the same JaasAuthenticationHandler configuration and simply transform the typed in userid to "gilbert@YU.YALE.EDU".
- However, at Yale "gilbert" is a Netid that is maintained across a number of back end system. Any system protected against unauthorized modification might be used to authenticate this person, and while it may be of administrative interest how the authentication was done, when some CAS Service validates a Service Ticket it expects to get the naked Netid "gilbert". So even though a fully qualified Principal name may be used with the back end service, the unqualified name would be stored by CAS in the Ticket space.
- That works fine until Yale joins one or more federations of universities and allows cross-institutional login. Now to support legacy systems, the unqualified "gilbert" would be returned to all Yale services that expect that CAS only authenticates local Yale users. New services that are ready to accept fully qualified cross-institutional Principal names might get back "gilbert@harvard.edu" and would realize that this is almost certainly some other person named "gilbert" at a different institution and, therefore, someone completely different from the local Netid "gilbert" at Yale.
CAS can be configured to do all these different things if you know what you are doing. It neither provides nor excludes any complicated Principal naming scheme. Anything is possible, with some Spring configuration and a little coding. However, you have to understand the architecture and put your configuration and code in the right place.
A Handler authenticates or rejects one type of Credential object. The default AuthenticationManager accepts the opinion of the first Handler that recognizes that type of Credential object and it applies Resolvers separately.
However, some institutions may want to resolve the same userid/password against several back end systems (multiple Kerberos realms, LDAP directories, etc.) and accept them if the combination validates to any system. No matter which Handler approves them, a single Resolver could then extract the userid and set it as the accepted Netid in the TGT. So here there would be many Handlers all sharing a single Resolver. In other institutions, however, different back end systems might imply different formats for the CAS Netid, and that creates need for an AuthenticationManager configured in Spring XML with pairs of (Handler, Resolver).
JAAS (Kerberos) Password Handler
<bean class="org.jasig.cas.authentication.handler.support.JaasAuthenticationHandler" p:realm="CASJAASconfig" />
JAAS is a rather complicated standard feature of Java that has its own more comprehensive description page.
The configuration example given above tells CAS to authenticate the userid and password through JAAS using the bundle of parameters in the JAAS "login configuration" file named "CASJAASconfig". To determine exactly what JAAS is going to do, you have to search the environment, find the login configuration file, and lookup the name.
However, at this time it is very late for Java to be using legacy systems that JAAS supports like NIS and NT LAN Manager. If you want to authenticate to an LDAP server, it is better to use the CAS LDAP AuthenticationHandler described immediately below instead of using JAAS LDAP. So in practice, you use this configuration when you want to authenticate the userid and password in a Kerberos 5 KDC. This could be an MIT K5 server, or it could be Active Directory.
It is a matter of discussion whether the best way to authenticate to AD is using the K5 protocol though JAAS or using the LDAP Handler. Which is most efficient? Which provides the best recovery when a Domain Controller goes down? For the moment, Yale is inclined to use the LDAP Handler.
However, JAAS remains a live prospect when you are using exotic hardware (a USB dongle or a smart card) that requires authentication through some network appliance and the vendor only supplies a JAAS plug-in to do the authentication.
The one restriction is that the JaasAuthenticationHandler module supplied with CAS 3 only supports Credentials with a userid and password. If some new technology generates one time use passwords, it can be used as is. However, if authentication requires more than these two data items, then it may be necessary to modify this original handler to support any extra fields.
LDAP (AD) Password Handler
<bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler"> <property name="filter" value="sAMAccountName=%u" /> <property name="searchBase" value="dc=yu,dc=yale,dc=edu" /> <property name="contextSource" ref="ldapContextSource" /> <property name="ignorePartialResultException" value="yes" /> </bean>
An LDAP AutheticationHandler is one of the distributed optional modules of the CAS 3 distribution. It uses Spring LDAP to authenticate the userid and password. In this example, the bean is configured for Active Directory and uses a separate LdapContextSource bean not shown.
JAAS can authenticate a userid/password by logging the user on and then off of an external LDAP source. However, the BindLdapAuthenticationHandler shown here is more efficient because it maintains a pool of existing LDAP connections to AD that it reuses to validate passwords rather than setting up and tearing down a connection for every user login.
X.509 Certificate Handler
<bean class="org.jasig.cas.adaptors.x509.authentication.handler.support.X509CredentialsAuthenticationHandler" p:trustedIssuerDnPattern="CN=Yale University ITS Issuing Certifying Authority.+" p:maxPathLength="3" p:maxPathLengthAllowUnspecified="true" />
The X509CredentialsAuthenticationHandler examines a User Certificate submitted with the HTTP request. The container (Tomcat, JBoss, etc.) has already verified that the Certificate comes from a trusted Certificate Authority.Generally the container is configured to only accept User Certificates issued by one of the standard Yale University CAs and not from any public sources. With this configuration, the Bean requires that the CA be specifically the Yale University ITS Certifying Authority and not one of the other CAs that the container trusts.
X.509 Certificate Resolver
<bean class="org.jasig.cas.adaptors.x509.authentication.principal.X509CertificateCredentialsToIdentifierPrincipalResolver" p:identifier="$CN" />
If you decide to use X.509 certificates, you must configure or code a Resolver that knows how to search through the Distinguished Name fields and the SubjectAltName fields to extract the Netid. In extreme cases, the Netid may not be in the Certificate itself, so the Resolver will have to do some sort of (probably) LDAP lookup using the Certificate DN to find a suitable Netid string. However, in this example the netid is the first CN= field in the DN of certificates issued by the Yale ITS CA.