下面文章是摘自:http://www.jasig.org/cas/protocol
Author: Drew Mazurek
Contributors:
Version: 1.0
Release Date: May 4, 2005
Copyright © 2005, Yale University
This is the official specification of the CAS 1.0 and 2.0 protocols. It is subject to change.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119[1].
CAS is an HTTP[2,3]-based protocol that requires each of its components to be accessible through specific URIs. This section will discuss each of the URIs.
The /login URI operates with two behaviors: as a credential requestor, and as a credential acceptor. It responds to credentials by acting as a credential acceptor and otherwise acts as a credential requestor.
If the client has already established a single sign-on session with CAS, the web browser presents to CAS a secure cookie containing a string identifying a ticket-granting ticket. This cookie is called the ticket-granting cookie. If the ticket-granting cookie keys to a valid ticket-granting ticket, CAS may issue a service ticket provided all the other conditions in this specification are met. See Section 3.6 for more information on ticket-granting cookies.
The following HTTP request parameters may be passed to /login while it is acting as a credential requestor. They are all case-sensitive, and they all MUST be handled by /login.
Simple login example:
https://server/cas/login?service=http%3A%2F%2Fwww.service.com
Don't prompt for username/password:
https://server/cas/login?service=http%3A%2F%2Fwww.service.com&gateway=true
Always prompt for username/password:
https://server/cas/login?service=http%3A%2F%2Fwww.service.com&renew=true
When /login behaves as a credential requestor, the response will vary depending on the type of credentials it is requesting. In most cases, CAS will respond by displaying a login screen requesting a username and password. This page MUST include a form with the parameters, "username", "password", and "lt". The form MAY also include the parameter, "warn". If "service" was specified to /login, "service" MUST also be a parameter of the form, containing the value originally passed to /login. These parameters are discussed in detail in Section 2.2.1. The form MUST be submitted through the HTTP POST method to /login which will then act as a credential acceptor, discussed in Section 2.2.
Trust authentication accommodates consideration of arbitrary aspects of the request as a basis for authentication. The appropriate user experience for trust authentication will be highly deployer-specific in consideration of local policy and of the logistics of the particular authentication mechanism implemented.
When /login behaves as a credential requestor for trust authentication, its behavior will be determined by the type of credentials it will be receiving. If the credentials are valid, CAS MAY transparently redirect the user to the service. Alternately, CAS MAY display a warning that credentials were presented and allow the client to confirm that it wants to use those credentials. It is RECOMMENDED that CAS implementations allow the deployer to choose the preferred behavior. If the credentials are invalid or non-existent, it is RECOMMENDED that CAS display to the client the reason authentication failed, and possibly present the user with alternate means of authentication (e.g. username/password authentication).
If the client has already established a single sign-on session with CAS, the client will have presented its HTTP session cookie to /login and behavior will be handled as in Section 2.2.4. However, if the "renew" parameter is set, the behavior will be handled as in Section 2.1.3 or 2.1.4.
When a set of accepted credentials are passed to /login, /login acts as a credential acceptor and its behavior is defined in this section.
The following HTTP request parameters MAY be passed to /login while it is acting as a credential acceptor. They are all case-sensitive and they all MUST be handled by /login.
In addition to the OPTIONAL parameters specified in Section 2.2.1, the following HTTP request parameters MUST be passed to /login while it is acting as a credential acceptor for username/password authentication. They are all case-sensitive.
There are no REQUIRED HTTP request parameters for trust authentication. Trust authentication may be based on any aspect of the HTTP request.
One of the following responses MUST be provided by /login when it is operating as a credential acceptor.
/logout destroys a client's single sign-on CAS session. The ticket-granting cookie (Section 3.6) is destroyed, and subsequent requests to /login will not obtain service tickets until the user again presents primary credentials (and thereby establishes a new single sign-on session).
The following HTTP request parameter MAY be specified to /logout. It is case sensitive and SHOULD be handled by /logout.
/logout MUST display a page stating that the user has been logged out. If the "url" request parameter is implemented, /logout SHOULD also provide a link to the provided URL as described in Section 2.3.1.
/validate checks the validity of a service ticket./validate is part of the CAS 1.0 protocol and thus does not handle proxy authentication. CAS MUST respond with a ticket validation failure response when a proxy ticket is passed to /validate.
The following HTTP request parameters MAY be specified to /validate. They are case sensitive and MUST all be handled by /validate.
/validate will return one of the following two responses:
On ticket validation success:
yes<LF>username<LF>
On ticket validation failure:
no<LF><LF>
Simple validation attempt:
https://server/cas/validate?service=http%3A%2F%2Fwww.service.com&ticket=...
Ensure service ticket was issued by presentation of primary credentials:
https://server/cas/validate?service=http%3A%2F%2Fwww.service.com&ticket=...
/serviceValidate checks the validity of a service ticket and returns an XML-fragment response. /serviceValidate MUST also generate and issue proxy-granting tickets when requested. /serviceValidate MUST NOT return a successful authentication if it receives a proxy ticket. It is RECOMMENDED that if /serviceValidate receives a proxy ticket, the error message in the XML response SHOULD explain that validation failed because a proxy ticket was passed to /serviceValidate.
The following HTTP request parameters MAY be specified to /serviceValidate. They are case sensitive and MUST all be handled by /serviceValidate.
/serviceValidate will return an XML-formatted CAS serviceResponse as described in the XML schema in Appendix A. Below are example responses:
On ticket validation success:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>username</cas:user> <cas:proxyGrantingTicket>PGTIOU-84678-8a9d... </cas:proxyGrantingTicket> </cas:authenticationSuccess></cas:serviceResponse>
On ticket validation failure:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationFailure code="INVALID_TICKET"> Ticket ST-1856339-aA5Yuvrxzpv8Tau1cYQ7 not recognized </cas:authenticationFailure></cas:serviceResponse>
The following values MAY be used as the "code" attribute of authentication failure responses. The following is the minimum set of error codes that all CAS servers MUST implement. Implementations MAY include others.
For all error codes, it is RECOMMENDED that CAS provide a more detailed message as the body of the <cas:authenticationFailure> block of the XML response.
If a service wishes to proxy a client's authentication to a back-end service, it must acquire a proxy-granting ticket. Acquisition of this ticket is handled through a proxy callback URL. This URL will uniquely and securely identify the back-end service that is proxying the client's authentication. The back-end service can then decide whether or not to accept the credentials based on the back-end service's identifying callback URL.
The proxy callback mechanism works as follows:
Simple validation attempt:
https://server/cas/serviceValidate?service=http%3A%2F%2Fwww.service.com&...
Ensure service ticket was issued by presentation of primary credentials:
https://server/cas/serviceValidate?service=http%3A%2F%2Fwww.service.com&... ST-1856339-aA5Yuvrxzpv8Tau1cYQ7&renew=true
Pass in a callback URL for proxying:
https://server/cas/serviceValidate?service=http%3A%2F%2Fwww.service.com&...
/proxyValidate MUST perform the same validation tasks as /serviceValidate and additionally validate proxy tickets. /proxyValidate MUST be capable of validating both service tickets and proxy tickets.
/proxyValidate has the same parameter requirements as /serviceValidate. See Section 2.5.1.
/proxyValidate will return an XML-formatted CAS serviceResponse as described in the XML schema in Appendix A. Below are example responses:
On ticket validation success:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationSuccess> <cas:user>username</cas:user> <cas:proxyGrantingTicket>PGTIOU-84678-8a9d...</cas:proxyGrantingTicket> <cas:proxies> <cas:proxy>https://proxy2/pgtUrl</cas:proxy> <cas:proxy>https://proxy1/pgtUrl</cas:proxy> </cas:proxies> </cas:authenticationSuccess></cas:serviceResponse>
Note that when authentication has proceeded through multiple proxies, the order in which the proxies were traversed MUST be reflected in the <cas:proxies> block. The most recently-visited proxy MUST be the first proxy listed, and all the other proxies MUST be shifted down as new proxies are added. In the above example, the service identified byhttps://proxy1/pgtUrl was visited first, and that service proxied authentication to the service identified byhttps://proxy2/pgtUrl.
On ticket validation failure:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:authenticationFailure code="INVALID_TICKET"> ticket PT-1856376-1HMgO86Z2ZKeByc5XdYD not recognized </cas:authenticationFailure></cas:serviceResponse>
/proxyValidate accepts the same parameters as /serviceValidate. See Section 2.5.5 for use examples, substituting "proxyValidate" for "serviceValidate".
/proxy provides proxy tickets to services that have acquired proxy-granting tickets and will be proxying authentication to back-end services.
The following HTTP request parameters MUST be specified to /proxy. They are both case-sensitive.
/proxy will return an XML-formatted CAS serviceResponse as described in the XML schema in Appendix A. Below are example responses:
On request success:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:proxySuccess> <cas:proxyTicket>PT-1856392-b98xZrQN4p90ASrw96c8</cas:proxyTicket> </cas:proxySuccess></cas:serviceResponse>
On request failure:
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'> <cas:proxyFailure code="INVALID_REQUEST"> 'pgt' and 'targetService' parameters are both required </cas:proxyFailure></cas:serviceResponse>
The following values MAY be used as the "code" attribute of authentication failure responses. The following is the minimum set of error codes that all CAS servers MUST implement. Implementations MAY include others.
For all error codes, it is RECOMMENDED that CAS provide a more detailed message as the body of the <cas:authenticationFailure> block of the XML response.
Simple proxy request:
https://server/cas/proxy?targetService=http%3A%2F%2Fwww.service.com&pgt=......
A service ticket is an opaque string that is used by the client as a credential to obtain access to a service. The service ticket is obtained from CAS upon a client's presentation of credentials and a service identifier to /login as described in Section 2.2.
A proxy ticket is an opaque string that a service uses as a credential to obtain access to a back-end service on behalf of a client. Proxy tickets are obtained from CAS upon a service's presentation of a valid proxy-granting ticket (Section 3.3), and a service identifier for the back-end service to which it is connecting.
A proxy-granting ticket is an opaque string that is used by a service to obtain proxy tickets for obtaining access to a back-end service on behalf of a client. Proxy-granting tickets are obtained from CAS upon validation of a service ticket or a proxy ticket. Proxy-granting ticket issuance is described fully in Section 2.5.4.
A proxy-granting ticket IOU is an opaque string that is placed in the response provided by /serviceValidate and /proxyValidate used to correlate a service ticket or proxy ticket validation with a particular proxy-granting ticket. See Section 2.5.4 for a full description of this process.
A login ticket is a string that is provided by /login as a credential requestor and passed to /login as a credential acceptor for username/password authentication. Its purpose is to prevent the replaying of credentials due to bugs in web browsers.
A ticket-granting cookie is an HTTP cookie[5] set by CAS upon the establishment of a single sign-on session. This cookie maintains login state for the client, and while it is valid, the client can present it to CAS in lieu of primary credentials. Services can opt out of single sign-on through the "renew" parameter described in Sections 2.1.1, 2.4.1, and 2.5.1.
In addition to the above requirements, all CAS tickets and the value of the ticket-granting cookie MUST contain only characters from the set {A-Z, a-z, 0-9, and the hyphen character ?-'}.
<!-- The following is the schema for the Yale Central Authentication Service (CAS) version 2.0 protocol response. This covers the responses for the following servlets: /serviceValidate /proxyValidate /proxy This specification is subject to change. Author: Drew Mazurek Version: $Id: cas2.xsd,v 1.1 2005/02/14 16:19:06 dmazurek Exp $--><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cas="http://www.yale.edu/tp/cas" targetNamespace="http://www.yale.edu/tp/cas" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="serviceResponse" type="cas:ServiceResponseType"/> <xs:complexType name="ServiceResponseType"> <xs:choice> <xs:element name="authenticationSuccess" type="cas:AuthenticationSuccessType"/> <xs:element name="authenticationFailure" type="cas:AuthenticationFailureType"/> <xs:element name="proxySuccess" type="cas:ProxySuccessType"/> <xs:element name="proxyFailure" type="cas:ProxyFailureType"/> </xs:choice> </xs:complexType> <xs:complexType name="AuthenticationSuccessType"> <xs:sequence> <xs:element name="user" type="xs:string"/> <xs:element name="proxyGrantingTicket" type="xs:string" minOccurs="0"/> <xs:element name="proxies" type="cas:ProxiesType" minOccurs="0"/> </xs:sequence> </xs:complexType> <xs:complexType name="ProxiesType"> <xs:sequence> <xs:element name="proxy" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:complexType name="AuthenticationFailureType"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="code" type="xs:string" use="required"/> </xs:extension> </xs:simpleContent> </xs:complexType> <xs:complexType name="ProxySuccessType"> <xs:sequence> <xs:element name="proxyTicket" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="ProxyFailureType"> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="code" type="xs:string" use="required"/> </xs:extension> </xs:simpleContent> </xs:complexType></xs:schema>
After a successful login, safely redirecting the client from CAS to its final destination must be handled with care. In most cases, the client has sent credentials to the CAS server over a POST request. By this specification, the CAS server must then forward the user to the application with a GET request.
The HTTP/1.1 RFC[3] provides a response code of 303: See Other, which provides for the desired behavior: a script that receives data through a POST request can, through a 303 redirection, forward the browser to another URL through a GET request. However, not all browsers have implemented this behavior correctly.
The recommended method of redirection is thus JavaScript. A page containing a window.location.href in the following manner performs adequately:
<html> <head> <title>Yale Central Authentication Service</title> <script> window.location.href="https://portal.yale.edu/Login?ticket=ST-..." mce_href="https://portal.yale.edu/Login?ticket=ST-..."; </script> </head> <body> <noscript> <p>CAS login successful.</p> <p> Click <a xhref="https://portal.yale.edu/Login?ticket=ST-..." mce_href="https://portal.yale.edu/Login?ticket=ST-...">here</a> to access the service you requested.<br /> </p> </noscropt> </body></html>
Additionally, CAS should disable browser caching by setting all of the various cache-related headers:
The introduction of the login ticket removed the possibility of CAS accepting credentials that were cached and replayed by a browser. However, early versions of Apple's Safari browser contained a bug where through usage of the Back button, Safari could be coerced into presenting the client's credentials to the service it is trying to access. CAS can prevent this behavior by not automatically redirecting if it detects that the remote browser is one of these early versions of Safari. Instead, CAS should display a page that states login was successful, and provide a link to the requested service. The client must then manually click to proceed.
[1] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", RFC 2119, Harvard University, March 1997.
[2] Berners-Lee, T., Fielding, R., Frystyk, H., "Hypertext Transfer Protocol - HTTP/1.0", RFC 1945, MIT/LCS, UC Irvine, MIT/LCS, May 1996.
[3] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., Berners-Lee, T., "Hypertext Transfer Protocol - HTTP/1.1", RFC 2068, UC Irvine, Compaq/W3C, Compaq, W3C/MIT, Xerox, Microsoft, W3C/MIT, June 1999.
[4] Berners-Lee, T., Masinter, L., and MaCahill, M., "Uniform Resource Locators (URL)", RFC 1738, CERN, Xerox Corporation, University of Minnesota, December 1994.
[5] Kristol, D., Montulli, L., "HTTP State Management Mechanism", RFC 2965, Bell Laboratories/Lucent Technologies, Epinions.com, Inc., October 2000.
[6] Braden, R., "Requirements for Internet Hosts - Application and Support", RFC 1123, Internet Engineering Task Force, October 1989.
Copyright (c) 2000-2005 Yale University. All rights reserved.
THIS SOFTWARE IS PROVIDED "AS IS," AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE EXPRESSLY DISCLAIMED. IN NO EVENT SHALL YALE UNIVERSITY OR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED, THE COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGE.
Redistribution and use of this software in source or binary forms, with or without modification, are permitted, provided that the following conditions are met:
1. Any redistribution must include the above copyright notice and disclaimer and this list of conditions in any related documentation and, if feasible, in the redistributed software.
2. Any redistribution must include the acknowledgment, "This product includes software developed by Yale University," in any related documentation and, if feasible, in the redistributed software.
3. The names "Yale" and "Yale University" must not be used to endorse or promote products derived from this software.
May 4, 2005: v1.0 - initial release