Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork604
apereo/java-cas-client
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is the official home of the Java Apereo CAS client. The client consists of a collection of Servlet filters that are suitable for most Java-based web applications. It also serves as an API platform to interact with the CAS server programmatically to make authentication requests, validate tickets and consume principal attributes.
All client artifacts are published to Maven central. Depending on functionality, applications will need include one or more of the listed dependencies in their configuration.
git clone git@github.com:apereo/java-cas-client.gitcd java-cas-clientmvn clean package- Core functionality, which includes CAS authentication/validation filters.
<dependency> <groupId>org.apereo.cas.client</groupId> <artifactId>cas-client-core</artifactId> <version>${java.cas.client.version}</version></dependency>
- Support for SAML functionality is provided by this dependency:
<dependency> <groupId>org.apereo.cas.client</groupId> <artifactId>cas-client-support-saml</artifactId> <version>${java.cas.client.version}</version></dependency>
- Distributed proxy ticket caching with Ehcache is provided by this dependency:
<dependency> <groupId>org.apereo.cas.client</groupId> <artifactId>cas-client-support-distributed-ehcache</artifactId> <version>${java.cas.client.version}</version></dependency>
- Distributed proxy ticket caching with Memcached is provided by this dependency:
<dependency> <groupId>org.apereo.cas.client</groupId> <artifactId>cas-client-support-distributed-memcached</artifactId> <version>${java.cas.client.version}</version></dependency>
- Spring Boot AutoConfiguration is provided by this dependency:
<dependency> <groupId>org.apereo.cas.client</groupId> <artifactId>cas-client-support-springboot</artifactId> <version>${java.cas.client.version}</version></dependency>
The client provides multiple strategies for the deployer to provide client settings. The following strategies are supported:
- JNDI (
JNDI) - Properties File (
PROPERTY_FILE). The configuration is provided via an external properties file. The path may be specified in the web context as such:
<context-param> <param-name>configFileLocation</param-name> <param-value>/etc/cas/file.properties</param-value></context-param>
If no location is specified, by default/etc/java-cas-client.properties will be used.
- System Properties (
SYSTEM_PROPERTIES) - Web Context (
WEB_XML) - Default (
DEFAULT)
In order to instruct the client to pick a strategy, strategy name must be specified in the web application's context:
<context-param> <param-name>configurationStrategy</param-name> <param-value>DEFAULT</param-value></context-param>
If noconfigurationStrategy is defined,DEFAULT is used which is a combination ofWEB_XML andJNDI.
The client can be configured inweb.xml via a series ofcontext-params and filterinit-params. Each filter for the client has a required (and optional) set of properties. The filters are designed to look for these properties in the following way:
- Check the filter's local
init-params for a parameter matching the required property name. - Check the
context-params for a parameter matching the required property name. - If two properties are found with the same name in the
init-params and thecontext-params, theinit-paramtakes precedence.
Note: If you're using theserverName property, you should note well that the fragment-URI (the stuff after the #) is not sent to the server by all browsers, thus the CAS client can't capture it as part of the URL.
An example application that is protected by the client isavailable here.
TheAuthenticationFilter is what detects whether a user needs to be authenticated or not. If a user needs to be authenticated, it will redirect the user to the CAS server.
<filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class>org.apereo.cas.client.authentication.AuthenticationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://battags.ad.ess.rutgers.edu:8443/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.acme-client.com</param-value> </init-param></filter><filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
casServerUrlPrefix | The start of the CAS server URL, i.e.https://localhost:8443/cas | Yes (unlesscasServerLoginUrl is set) |
casServerLoginUrl | Defines the location of the CAS server login URL, i.e.https://localhost:8443/cas/login. This overridescasServerUrlPrefix, if set. | Yes (unlesscasServerUrlPrefix is set) |
serverName | The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e.https://localhost:8443 (you must include the protocol, but port is optional if it's a standard port). | Yes |
service | The service URL to send to the CAS server, i.e.https://localhost:8443/yourwebapp/index.html | No |
renew | specifies whetherrenew=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all). Note thatrenew cannot be specified as localinit-param setting. | No |
gateway | specifies whethergateway=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all) | No |
artifactParameterName | specifies the name of the request parameter on where to find the artifact (i.e.ticket). | No |
serviceParameterName | specifies the name of the request parameter on where to find the service (i.e.service) | No |
encodeServiceUrl | Whether the client should auto encode the service url. Defaults totrue | No |
ignorePattern | Defines the url pattern to ignore, when intercepting authentication requests. | No |
ignoreUrlPatternType | Defines the type of the pattern specified. Defaults toREGEX. Other types areCONTAINS,EXACT,FULL_REGEX. Can also accept a fully-qualified class name that implementsUrlPatternMatcherStrategy. | No |
gatewayStorageClass | The storage class used to record gateway requests | No |
authenticationRedirectStrategyClass | The class name of the component to decide how to handle authn redirects to CAS | No |
method | The method used by the CAS server to send the user back to the application. Defaults tonull | No |
The following types are supported:
| Type | Description |
|---|---|
REGEX | Matches the URL theignorePattern usingMatcher#find(). It matches the next occurrence within the substring that matches the regex. |
CONTAINS | Uses theString#contains() operation to determine if the url contains the specified pattern. Behavior is case-sensitive. |
EXACT | Uses theString#equals() operation to determine if the url exactly equals the specified pattern. Behavior is case-sensitive. |
FULL_REGEX | Matches the URL theignorePattern usingMatcher#matches(). It matches the expression against the entire string as it implicitly add a^ at the start and$ at the end of the pattern, so it will not match substring or part of the string.^ and$ are meta characters that represents start of the string and end of the string respectively. |
The SAML 1.1AuthenticationFilter is what detects whether a user needs to be authenticated or not. If a user needs to be authenticated, it will redirect the user to the CAS server.
<filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class>org.apereo.cas.client.authentication.Saml11AuthenticationFilter</filter-class> <init-param> <param-name>casServerLoginUrl</param-name> <param-value>https://somewhere.cas.edu:8443/cas/login</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.the-client.com</param-value> </init-param></filter><filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
casServerUrlPrefix | The start of the CAS server URL, i.e.https://localhost:8443/cas | Yes (unlesscasServerLoginUrl is set) |
casServerLoginUrl | Defines the location of the CAS server login URL, i.e.https://localhost:8443/cas/login. This overridescasServerUrlPrefix, if set. | Yes (unlesscasServerUrlPrefix is set) |
serverName | The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e.https://localhost:8443 (you must include the protocol, but port is optional if it's a standard port). | Yes |
service | The service URL to send to the CAS server, i.e.https://localhost:8443/yourwebapp/index.html | No |
renew | specifies whetherrenew=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all). Note thatrenew cannot be specified as localinit-param setting. | No |
gateway | specifies whethergateway=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all) | No |
artifactParameterName | specifies the name of the request parameter on where to find the artifact (i.e.SAMLart). | No |
serviceParameterName | specifies the name of the request parameter on where to find the service (i.e.TARGET) | No |
encodeServiceUrl | Whether the client should auto encode the service url. Defaults totrue | No |
method | The method used by the CAS server to send the user back to the application. Defaults tonull | No |
Validates tickets using the CAS 1.0 Protocol.
<filter> <filter-name>CAS Validation Filter</filter-name> <filter-class>org.apereo.cas.client.validation.Cas10TicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://somewhere.cas.edu:8443/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.the-client.com</param-value> </init-param> </filter><filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
casServerUrlPrefix | The start of the CAS server URL, i.e.https://localhost:8443/cas | Yes |
serverName | The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e.https://localhost:8443 (you must include the protocol, but port is optional if it's a standard port). | Yes |
renew | Specifies whetherrenew=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all). Note thatrenew cannot be specified as localinit-param setting. | No |
redirectAfterValidation | Whether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults totrue. | No |
useSession | Whether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults totrue. | No |
exceptionOnValidationFailure | Whether to throw an exception or not on ticket validation failure. Defaults totrue. | No |
sslConfigFile | A reference to a properties file that includes SSL settings for client-side SSL config, used during back-channel calls. The configuration includes keys forprotocol which defaults toSSL,keyStoreType,keyStorePath,keyStorePass,keyManagerType which defaults toSunX509 andcertificatePassword. | No. |
encoding | Specifies the encoding charset the client should use | No |
hostnameVerifier | Hostname verifier class name, used when making back-channel calls | No |
Validates tickets using the SAML 1.1 protocol.
<filter> <filter-name>CAS Validation Filter</filter-name> <filter-class>org.apereo.cas.client.validation.Saml11TicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://battags.ad.ess.rutgers.edu:8443/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.acme-client.com</param-value> </init-param></filter><filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
casServerUrlPrefix | The start of the CAS server URL, i.e.https://localhost:8443/cas | Yes |
serverName | The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e.https://localhost:8443 (you must include the protocol, but port is optional if it's a standard port). | Yes |
renew | Specifies whetherrenew=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all). Note thatrenew cannot be specified as localinit-param setting. | No |
redirectAfterValidation | Whether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults totrue. | No |
useSession | Whether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults totrue. | No |
exceptionOnValidationFailure | whether to throw an exception or not on ticket validation failure. Defaults totrue | No |
tolerance | The tolerance for drifting clocks when validating SAML tickets. Note that 10 seconds should be more than enough for most environments that have NTP time synchronization. Defaults to1000 msec | No |
sslConfigFile | A reference to a properties file that includes SSL settings for client-side SSL config, used during back-channel calls. The configuration includes keys forprotocol which defaults toSSL,keyStoreType,keyStorePath,keyStorePass,keyManagerType which defaults toSunX509 andcertificatePassword. | No. |
encoding | Specifies the encoding charset the client should use | No |
hostnameVerifier | Hostname verifier class name, used when making back-channel calls | No |
Validates the tickets using the CAS 2.0 protocol. If you provide either theacceptAnyProxy or theallowedProxyChains parameters, aCas20ProxyTicketValidator will be constructed. Otherwise a generalCas20ServiceTicketValidator will be constructed that does not accept proxy tickets.
Note: If you are using proxy validation, you should place thefilter-mapping of the validation filter before the authentication filter.
<filter> <filter-name>CAS Validation Filter</filter-name> <filter-class>org.apereo.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class> <init-param> <param-name>casServerUrlPrefix</param-name> <param-value>https://battags.ad.ess.rutgers.edu:8443/cas</param-value> </init-param> <init-param> <param-name>serverName</param-name> <param-value>http://www.acme-client.com</param-value> </init-param></filter><filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
casServerUrlPrefix | The start of the CAS server URL, i.e.https://localhost:8443/cas | Yes |
serverName | The name of the server this application is hosted on. Service URL will be dynamically constructed using this, i.e.https://localhost:8443 (you must include the protocol, but port is optional if it's a standard port). | Yes |
renew | Specifies whetherrenew=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all). Note thatrenew cannot be specified as localinit-param setting. | No |
redirectAfterValidation | Whether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults totrue. | No |
useSession | Whether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults totrue. | No |
exceptionOnValidationFailure | whether to throw an exception or not on ticket validation failure. Defaults totrue | No |
proxyReceptorUrl | The URL to watch forPGTIOU/PGT responses from the CAS server. Should be defined from the root of the context. For example, if your application is deployed in/cas-client-app and you want the proxy receptor URL to be/cas-client-app/my/receptor you need to configure proxyReceptorUrl to be/my/receptor. | No |
acceptAnyProxy | Specifies whether any proxy is OK. Defaults tofalse. | No |
allowedProxyChains | Specifies the proxy chain. Each acceptable proxy chain should include a space-separated list of URLs (for exact match) or regular expressions of URLs (starting by the^ character). Each acceptable proxy chain should appear on its own line. | No |
proxyCallbackUrl | The callback URL to provide the CAS server to accept Proxy Granting Tickets. | No |
proxyGrantingTicketStorageClass | Specify an implementation of the ProxyGrantingTicketStorage class that has a no-arg constructor. | No |
sslConfigFile | A reference to a properties file that includes SSL settings for client-side SSL config, used during back-channel calls. The configuration includes keys forprotocol which defaults toSSL,keyStoreType,keyStorePath,keyStorePass,keyManagerType which defaults toSunX509 andcertificatePassword. | No. |
encoding | Specifies the encoding charset the client should use | No |
secretKey | The secret key used by theproxyGrantingTicketStorageClass if it supports encryption. | No |
cipherAlgorithm | The algorithm used by theproxyGrantingTicketStorageClass if it supports encryption. Defaults toDESede | No |
millisBetweenCleanUps | Startup delay for the cleanup task to remove expired tickets from the storage. Defaults to60000 msec | No |
ticketValidatorClass | Ticket validator class to use/create | No |
hostnameVerifier | Hostname verifier class name, used when making back-channel calls | No |
privateKeyPath | The path to a private key to decrypt PGTs directly sent encrypted as an attribute | No |
privateKeyAlgorithm | The algorithm of the private key. Defaults toRSA | No |
Validates the tickets using the CAS 3.0 protocol. If you provide either theacceptAnyProxy or theallowedProxyChains parameters,aCas30ProxyTicketValidator will be constructed. Otherwise a generalCas30ServiceTicketValidator will be constructed that does notaccept proxy tickets. Supports all configurations that are available forCas20ProxyReceivingTicketValidationFilter.
Identical toCas30ProxyReceivingTicketValidationFilter, yet the filter is able to accept validation responses from CASthat are formatted as JSON per guidelines laid out by the CAS protocol.See theprotocol documentationfor more info.
Validates service tickets that issued by the CAS server as JWTs.
Supported JWTs are:
- The JWT must be signed and encrypted, in that order, or...
- The JWT must be encrypted and signed, in that order, or...
- The JWT must be encrypted.
<filter> <filter-name>CAS Validation Filter</filter-name> <filter-class>org.apereo.cas.client.validation.CasJWTTicketValidationFilter</filter-class> <init-param> <param-name>signingKey</param-name> <param-value>...</param-value> </init-param> <init-param> <param-name>encryptionKey</param-name> <param-value>...</param-value> </init-param></filter><filter-mapping> <filter-name>CAS Validation Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
signingKey | The signing key. OnlyAES secret keys are supported. | Yes |
encryptionKey | The encryption key. OnlyAES secret keys are supported. | Yes |
expectedIssuer | iss claim value that is required to match what is in the JWT. | Yes |
expectedAudience | aud claim value that is required to match what is in the JWT. | Yes |
encryptionKeyAlgorithm | Default isAES. | No |
encryptionKeyAlgorithm | Default isAES. | No |
requiredClaims | Default issub,aud,iat,jti,exp,iss. | No |
base64EncryptionKey | If encryption key should be base64-decoded first. Default istrue. | No |
base64SigningKey | If encryption key should be base64-decoded first. Default isfalse. | No |
maxClockSkew | Maximum acceptable clock skew when validating expiration dates. Default is60 seconds. | No |
The client has support for clustering and distributing the TGT state among application nodes that are behind a load balancer. In order to do so,the parameter needs to be defined as such for the filter.
Configure the client:
<init-param> <param-name>proxyGrantingTicketStorageClass</param-name> <param-value>org.apereo.cas.client.EhcacheBackedProxyGrantingTicketStorageImpl</param-value></init-param>
The setting provides an implementation for proxy storage using EhCache to take advantage of its replication features so that the PGT is successfully replicated and shared among nodes, regardless which node is selected as the result of the load balancer rerouting.
Configuration of this parameter is not enough. The EhCache configuration needs to enable the replication mechanism through once of its suggested ways. A sample of that configuration based on RMI replication can be found here. Please note that while the sample is done for a distributed ticket registry implementation, the basic idea and configuration should easily be transferable.
When loading from theweb.xml, the Apereo CAS Client relies on a series of default values, one of which being that the cache must be configured in the default location (i.e.classpath:ehcache.xml).
<cacheManagerPeerProviderFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446"/> <cacheManagerPeerListenerFactoryclass="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"/> <cachename="org.apereo.cas.client.EhcacheBackedProxyGrantingTicketStorageImpl.cache"maxElementsInMemory="100"eternal="false"timeToIdleSeconds="100"timeToLiveSeconds="100"overflowToDisk="false"> <cacheEventListenerFactoryclass="net.sf.ehcache.distribution.RMICacheReplicatorFactory"/></cache>
A similar implementation based on Memcached is also available.
Configure the client:
<init-param> <param-name>proxyGrantingTicketStorageClass</param-name> <param-value>org.apereo.cas.client.proxy.MemcachedBackedProxyGrantingTicketStorageImpl</param-value></init-param>
When loading from theweb.xml, the Client relies on a series of default values, one of which being that the list of memcached servers must be defined in/cas/casclient_memcached_hosts.txt on the classpath). The file is a simple list of<hostname>:<ports> on separate lines.BE SURE NOT TO HAVE EXTRA LINE BREAKS.
Wraps anHttpServletRequest so that thegetRemoteUser andgetPrincipal return the CAS related entries.
<filter> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <filter-class>org.apereo.cas.client.HttpServletRequestWrapperFilter</filter-class></filter><filter-mapping> <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
| Property | Description | Required |
|---|---|---|
roleAttribute | Used to determine the principal role. | No |
ignoreCase | Whether role checking should ignore case. Defaults tofalse | No |
Places theAssertion in aThreadLocal for portions of the application that need access to it. This is useful when the Web application that this filter "fronts" needs to get the Principal name, but it has no access to theHttpServletRequest, hence makinggetRemoteUser() call impossible.
<filter> <filter-name>CAS Assertion Thread Local Filter</filter-name> <filter-class>org.apereo.cas.client.AssertionThreadLocalFilter</filter-class></filter><filter-mapping> <filter-name>CAS Assertion Thread Local Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
Filters that redirects to the supplied url based on an exception. Exceptions and the urls are configured via init filter name/param values.
| Property | Description | Required |
|---|---|---|
defaultErrorRedirectPage | Default url to redirect to, in case no error matches are found. | Yes |
java.lang.Exception | Fully qualified exception name. Its value must be redirection url | No |
<filter> <filter-name>CAS Error Redirect Filter</filter-name> <filter-class>org.apereo.cas.client.ErrorRedirectFilter</filter-class> <init-param> <param-name>java.lang.Exception</param-name> <param-value>/error.jsp</param-value> </init-param> <init-param> <param-name>defaultErrorRedirectPage</param-name> <param-value>/defaulterror.jsp</param-value> </init-param></filter><filter-mapping> <filter-name>CAS Error Redirect Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
Configuration via Spring IoC will depend heavily onDelegatingFilterProxy class. For each filter that will be configured for CAS via Spring, a correspondingDelegatingFilterProxy is needed in the web.xml.
As theHttpServletRequestWrapperFilter andAssertionThreadLocalFilter have no configuration options, we recommend you just configure them in theweb.xml
<filter> <filter-name>CAS Authentication Filter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetBeanName</param-name> <param-value>authenticationFilter</param-value> </init-param> </filter><filter-mapping> <filter-name>CAS Authentication Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
<beanname="authenticationFilter"class="org.apereo.cas.client.authentication.AuthenticationFilter"p:casServerLoginUrl="https://localhost:8443/cas/login"p:renew="false"p:gateway="false"p:service="https://my.local.service.com/cas-client" />
<beanname="ticketValidationFilter"class="org.apereo.cas.client.validation.Cas10TicketValidationFilter"p:service="https://my.local.service.com/cas-client"> <propertyname="ticketValidator"> <beanclass="org.apereo.cas.client.validation.Cas10TicketValidator"> <constructor-argindex="0"value="https://localhost:8443/cas" /> </bean> </property></bean>
<beanname="ticketValidationFilter"class="org.apereo.cas.client.validation.Saml11TicketValidationFilter"p:service="https://my.local.service.com/cas-client"> <propertyname="ticketValidator"> <beanclass="org.apereo.cas.client.validation.Saml11TicketValidator"> <constructor-argindex="0"value="https://localhost:8443/cas" /> </bean> </property></bean>
Configuration to validate tickets:
<beanname="ticketValidationFilter"class="org.apereo.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter"p:service="https://my.local.service.com/cas-client"> <propertyname="ticketValidator"> <beanclass="org.apereo.cas.client.validation.Cas20ServiceTicketValidator"> <constructor-argindex="0"value="https://localhost:8443/cas" /> </bean> </property></bean>
Configuration to accept a Proxy Granting Ticket:
<beanname="ticketValidationFilter"class="org.apereo.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter"p:service="https://my.local.service.com/cas-client"p:proxyReceptorUrl="/proxy/receptor"> <propertyname="ticketValidator"> <beanclass="org.apereo.cas.client.validation.Cas20ServiceTicketValidator"p:proxyCallbackUrl="/proxy/receptor"> <constructor-argindex="0"value="https://localhost:8443/cas" /> </bean> </property></bean>
Configuration to accept any Proxy Ticket (and Proxy Granting Tickets):
<beanname="ticketValidationFilter"class="org.apereo.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter"p:service="https://my.local.service.com/cas-client"p:proxyReceptorUrl="/proxy/receptor"> <propertyname="ticketValidator"> <beanclass="org.apereo.cas.client.validation.Cas20ProxyTicketValidator"p:acceptAnyProxy="true"p:proxyCallbackUrl="/proxy/receptor"> <constructor-argindex="0"value="https://localhost:8443/cas" /> </bean> </property></bean>
Configuration to accept Proxy Ticket from a chain (and Proxy Granting Tickets):
<beanname="ticketValidationFilter"class="org.apereo.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter"p:service="https://my.local.service.com/cas-client"p:proxyReceptorUrl="/proxy/receptor"> <propertyname="ticketValidator"> <beanclass="org.apereo.cas.client.validation.Cas20ProxyTicketValidator"p:proxyCallbackUrl="/proxy/receptor"> <constructor-argindex="0"value="https://localhost:8443/cas" /> <propertyname="allowedProxyChains"> <list> <value>http://proxy1 http://proxy2</value> </list> </property> </bean> </property></bean>
The specific filters can be configured in the following ways. Please see the JavaDocs included in the distribution for specific required and optional properties:
- Define a dependency:
Maven:
<dependency> <groupId>org.apereo.cas.client</groupId> <artifactId>cas-client-support-springboot</artifactId> <version>${java.cas.client.version}</version></dependency>
Gradle:
dependencies {... implementation'org.apereo.cas.client:cas-client-support-springboot:${java.cas.client.version}'...}- Add the following required properties in Spring Boot's
application.propertiesorapplication.yml:
cas.server-url-prefix=https://cashost.com/cascas.server-login-url=https://cashost.com/cas/logincas.client-host-url=https://casclient.com
- Annotate Spring Boot application (or any @Configuration class) with
@EnableCasClientannotation
@SpringBootApplication@Controller@EnableCasClientpublicclassMyApplication { .. }
For CAS3 protocol (authentication and validation filters) - which is default if nothing is specified
cas.validation-type=CAS3For CAS2 protocol (authentication and validation filters)
cas.validation-type=CASFor SAML protocol (authentication and validation filters)
cas.validation-type=SAMLcas.single-logout.enabledcas.authentication-url-patternscas.validation-url-patternscas.request-wrapper-url-patternscas.assertion-thread-local-url-patternscas.gatewaycas.use-sessioncas.attribute-authoritiescas.redirect-after-validationcas.allowed-proxy-chainscas.proxy-callback-urlcas.proxy-receptor-urlcas.accept-any-proxyserver.context-parameters.renew
An application that is handling security concerns via Spring Security can take advantageof this module to automatically populate the Spring Security authentication contextwith roles and authorities that are fetched as attributes from the CAS assertion.
To do so, the attributes names (i.e.membership) from the CAS assertion that should be translated to Spring Securityauthorities must be specified in the configuration:
cas.attribute-authorities=membershipThe application may then enforce role-based security via:
@SpringBootApplication@EnableCasClientpublicclassMyConfigurationextendsWebSecurityConfigurerAdapter {@Overrideprotectedvoidconfigure(HttpSecurityhttp)throwsException {http.authorizeRequests() .antMatchers("/").permitAll() .antMatchers("/protected-endpoint").hasAuthority("ADMIN") .anyRequest().authenticated(); }}
The translation between CAS attributes and Spring Security authorities and/or roles can be customized usingthe following bean definition:
@BeanpublicAuthenticationUserDetailsService<CasAssertionAuthenticationToken>springSecurityCasUserDetailsService() {returnnull;}
This module does not expose ALL the CAS client configuration options via standard Spring property sources, but only most commonly used ones.If there is a need however, to set any number of not exposed, 'exotic' properties, you can implement theCasClientConfigurerclass in your@EnableCasClient annotated class and override appropriate configuration method(s) for CAS client filter(s) in question.For example:
@SpringBootApplication@EnableCasClientclassCasProtectedApplicationimplementsCasClientConfigurer {@OverridevoidconfigureValidationFilter(FilterRegistrationBeanvalidationFilter) {validationFilter.getInitParameters().put("millisBetweenCleanUps","120000"); }@OverridevoidconfigureAuthenticationFilter(FilterRegistrationBeanauthenticationFilter) {authenticationFilter.getInitParameters().put("artifactParameterName","casTicket");authenticationFilter.getInitParameters().put("serviceParameterName","targetService"); } }
The Single Sign Out support in CAS consists of configuring oneSingleSignOutFilter and oneContextListener. Please note that if you have configured the CAS Client for Java as Web filters, this filter must come before the other filters as described.
TheSingleSignOutFilter can affect character encoding. This becomes most obvious when used in conjunction with applications such as Atlassian Confluence. It's recommended you explicitly configure either theVT Character Encoding Filter or theSpring Character Encoding Filter with explicit encodings.
| Property | Description | Required |
|---|---|---|
artifactParameterName | The ticket artifact parameter name. Defaults toticket | No |
logoutParameterName | Defaults tologoutRequest | No |
relayStateParameterName | Defaults toRelayState | No |
eagerlyCreateSessions | Defaults totrue | No |
artifactParameterOverPost | Defaults tofalse | No |
logoutCallbackPath | The path which is expected to receive logout callback requests from the CAS server. This is necessary if your app needs access to the raw input stream when handling form posts. If not configured, the default behavior will check every form post for a logout parameter. | No |
<filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class>org.apereo.cas.client.session.SingleSignOutFilter</filter-class></filter>...<filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>...<listener> <listener-class>org.apereo.cas.client.session.SingleSignOutHttpSessionListener</listener-class></listener>
<filter> <filter-name>CAS Single Sign Out Filter</filter-name> <filter-class>org.apereo.cas.client.session.SingleSignOutFilter</filter-class> <init-param> <param-name>artifactParameterName</param-name> <param-value>SAMLart</param-value> </init-param></filter>...<filter-mapping> <filter-name>CAS Single Sign Out Filter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>...<listener> <listener-class>org.apereo.cas.client.session.SingleSignOutHttpSessionListener</listener-class></listener>
The client has no code to help you handle log out. The client merely places objects in session. Therefore, we recommend you do asession.invalidate() call when you log a user out. However, that's entirely your application's responsibility. We recommend that text similar to the following appear when the application's session is ended.
You have been logged out of [APPLICATION NAME GOES HERE].To log out of all applications, click here. (provide link to CAS server's logout)
The client supports the Java Authentication and Authorization Service (JAAS) framework, which provides authn facilities to CAS-enabled JEE applications.
A general JAAS authentication module,CasLoginModule, is available with the specific purpose of providing authentication and authorization services to CAS-enabled JEE applications. The design of the module is simple: given a service URL and a service ticket in aNameCallback andPasswordCallback, respectively, the module contacts the CAS server and attempts to validate the ticket. In keeping with CAS integration for Java applications, a JEE container-specific servlet filter is needed to protect JEE Web applications. The JAAS support should be extensible to any JEE container.
It is expected that for JEE applications both authentication and authorization services will be required for CAS integration. The following JAAS module configuration file excerpt demonstrates how to leverage SAML 1.1 attribute release in CAS to provide authorization data in addition to authentication:
cas { jaas.org.apereo.cas.client.CasLoginModule required ticketValidatorClass="org.apereo.cas.client.validation.Saml11TicketValidator" casServerUrlPrefix="https://cas.example.com/cas" tolerance="20000" service="https://webapp.example.com/webapp" defaultRoles="admin,operator" roleAttributeNames="memberOf,eduPersonAffiliation" principalGroupName="CallerPrincipal" roleGroupName="Roles" cacheAssertions="true" cacheTimeout="480";}| Property | Description | Required |
|---|---|---|
ticketValidatorClass | Fully-qualified class name of CAS ticket validator class. | Yes |
casServerUrlPrefix | URL to root of CAS Web application context. | Yes |
service | CAS service parameter that may be overridden by callback handler.Note: service must be specified by at least one component such that it is available at service ticket validation time. | No |
defaultRoles | Comma-delimited list of static roles applied to all authenticated principals. | No |
roleAttributeNames | Comma-delimited list of attribute names that describe role data delivered to CAS in the service-ticket validation response that should be applied to the current authenticated principal. | No |
principalGroupName | The name of a group principal containing the primary principal name of the current JAAS subject. The default value isCallerPrincipal. | No |
roleGroupName | The name of a group principal containing all role data. The default value isRoles. | No |
cacheAssertions | Flag to enable assertion caching. This may be required for JAAS providers that attempt to periodically reauthenticate to renew principal. Since CAS tickets are one-time-use, a cached assertion must be provided on reauthentication. | No |
cacheTimeout | Assertion cache timeout in minutes. | No |
tolerance | The tolerance for drifting clocks when validating SAML tickets. | No |
Ajaas.org.apereo.cas.client.Servlet3AuthenticationFilter servlet filter that performs a programmatic JAAS login using the Servlet 3.0HttpServletRequest#login() facility. This component should be compatible with any servlet container that supports the Servlet 3.0/JEE6 specification.
The filter executes when it receives a CAS ticket and expects theCasLoginModule JAAS module to perform the CAS ticket validation in order to produce anAssertionPrincipal from which the CAS assertion is obtained and inserted into the session to enable SSO.
If aservice init-param is specified for this filter, it supersedesthe service defined for theCasLoginModule.
About
Apereo Java CAS Client
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.