Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Apereo Java CAS Client

License

NotificationsYou must be signed in to change notification settings

apereo/java-cas-client

Repository files navigation

Intro

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.

Build

git clone git@github.com:apereo/java-cas-client.gitcd java-cas-clientmvn clean package

Components

  • 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>

Configuration

Strategies

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.

Client Configuration Usingweb.xml

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 localinit-params for a parameter matching the required property name.
  • Check thecontext-params for a parameter matching the required property name.
  • If two properties are found with the same name in theinit-params and thecontext-params, theinit-param takes 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.

org.apereo.cas.client.authentication.AuthenticationFilter

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>
PropertyDescriptionRequired
casServerUrlPrefixThe start of the CAS server URL, i.e.https://localhost:8443/casYes (unlesscasServerLoginUrl is set)
casServerLoginUrlDefines the location of the CAS server login URL, i.e.https://localhost:8443/cas/login. This overridescasServerUrlPrefix, if set.Yes (unlesscasServerUrlPrefix is set)
serverNameThe 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
serviceThe service URL to send to the CAS server, i.e.https://localhost:8443/yourwebapp/index.htmlNo
renewspecifies 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
gatewayspecifies whethergateway=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all)No
artifactParameterNamespecifies the name of the request parameter on where to find the artifact (i.e.ticket).No
serviceParameterNamespecifies the name of the request parameter on where to find the service (i.e.service)No
encodeServiceUrlWhether the client should auto encode the service url. Defaults totrueNo
ignorePatternDefines the url pattern to ignore, when intercepting authentication requests.No
ignoreUrlPatternTypeDefines 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
gatewayStorageClassThe storage class used to record gateway requestsNo
authenticationRedirectStrategyClassThe class name of the component to decide how to handle authn redirects to CASNo
methodThe method used by the CAS server to send the user back to the application. Defaults tonullNo
Ignore Patterns

The following types are supported:

TypeDescription
REGEXMatches the URL theignorePattern usingMatcher#find(). It matches the next occurrence within the substring that matches the regex.
CONTAINSUses theString#contains() operation to determine if the url contains the specified pattern. Behavior is case-sensitive.
EXACTUses theString#equals() operation to determine if the url exactly equals the specified pattern. Behavior is case-sensitive.
FULL_REGEXMatches 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.

org.apereo.cas.client.authentication.Saml11AuthenticationFilter

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>
PropertyDescriptionRequired
casServerUrlPrefixThe start of the CAS server URL, i.e.https://localhost:8443/casYes (unlesscasServerLoginUrl is set)
casServerLoginUrlDefines the location of the CAS server login URL, i.e.https://localhost:8443/cas/login. This overridescasServerUrlPrefix, if set.Yes (unlesscasServerUrlPrefix is set)
serverNameThe 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
serviceThe service URL to send to the CAS server, i.e.https://localhost:8443/yourwebapp/index.htmlNo
renewspecifies 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
gatewayspecifies whethergateway=true should be sent to the CAS server. Valid values are eithertrue/false (or no value at all)No
artifactParameterNamespecifies the name of the request parameter on where to find the artifact (i.e.SAMLart).No
serviceParameterNamespecifies the name of the request parameter on where to find the service (i.e.TARGET)No
encodeServiceUrlWhether the client should auto encode the service url. Defaults totrueNo
methodThe method used by the CAS server to send the user back to the application. Defaults tonullNo

org.apereo.cas.client.validation.Cas10TicketValidationFilter

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>
PropertyDescriptionRequired
casServerUrlPrefixThe start of the CAS server URL, i.e.https://localhost:8443/casYes
serverNameThe 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
renewSpecifies 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
redirectAfterValidationWhether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults totrue.No
useSessionWhether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults totrue.No
exceptionOnValidationFailureWhether to throw an exception or not on ticket validation failure. Defaults totrue.No
sslConfigFileA 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.
encodingSpecifies the encoding charset the client should useNo
hostnameVerifierHostname verifier class name, used when making back-channel callsNo

org.apereo.cas.client.validation.Saml11TicketValidationFilter

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>
PropertyDescriptionRequired
casServerUrlPrefixThe start of the CAS server URL, i.e.https://localhost:8443/casYes
serverNameThe 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
renewSpecifies 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
redirectAfterValidationWhether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults totrue.No
useSessionWhether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults totrue.No
exceptionOnValidationFailurewhether to throw an exception or not on ticket validation failure. Defaults totrueNo
toleranceThe 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 msecNo
sslConfigFileA 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.
encodingSpecifies the encoding charset the client should useNo
hostnameVerifierHostname verifier class name, used when making back-channel callsNo

org.apereo.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter

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>
PropertyDescriptionRequired
casServerUrlPrefixThe start of the CAS server URL, i.e.https://localhost:8443/casYes
serverNameThe 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
renewSpecifies 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
redirectAfterValidationWhether to redirect to the same URL after ticket validation, but without the ticket in the parameter. Defaults totrue.No
useSessionWhether to store the Assertion in session or not. If sessions are not used, tickets will be required for each request. Defaults totrue.No
exceptionOnValidationFailurewhether to throw an exception or not on ticket validation failure. Defaults totrueNo
proxyReceptorUrlThe 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
acceptAnyProxySpecifies whether any proxy is OK. Defaults tofalse.No
allowedProxyChainsSpecifies 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
proxyCallbackUrlThe callback URL to provide the CAS server to accept Proxy Granting Tickets.No
proxyGrantingTicketStorageClassSpecify an implementation of the ProxyGrantingTicketStorage class that has a no-arg constructor.No
sslConfigFileA 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.
encodingSpecifies the encoding charset the client should useNo
secretKeyThe secret key used by theproxyGrantingTicketStorageClass if it supports encryption.No
cipherAlgorithmThe algorithm used by theproxyGrantingTicketStorageClass if it supports encryption. Defaults toDESedeNo
millisBetweenCleanUpsStartup delay for the cleanup task to remove expired tickets from the storage. Defaults to60000 msecNo
ticketValidatorClassTicket validator class to use/createNo
hostnameVerifierHostname verifier class name, used when making back-channel callsNo
privateKeyPathThe path to a private key to decrypt PGTs directly sent encrypted as an attributeNo
privateKeyAlgorithmThe algorithm of the private key. Defaults toRSANo

org.apereo.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter

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.

org.apereo.cas.client.validation.Cas30JsonProxyReceivingTicketValidationFilter

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.

org.apereo.cas.client.validation.CasJWTTicketValidationFilter

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>
PropertyDescriptionRequired
signingKeyThe signing key. OnlyAES secret keys are supported.Yes
encryptionKeyThe encryption key. OnlyAES secret keys are supported.Yes
expectedIssueriss claim value that is required to match what is in the JWT.Yes
expectedAudienceaud claim value that is required to match what is in the JWT.Yes
encryptionKeyAlgorithmDefault isAES.No
encryptionKeyAlgorithmDefault isAES.No
requiredClaimsDefault issub,aud,iat,jti,exp,iss.No
base64EncryptionKeyIf encryption key should be base64-decoded first. Default istrue.No
base64SigningKeyIf encryption key should be base64-decoded first. Default isfalse.No
maxClockSkewMaximum acceptable clock skew when validating expiration dates. Default is60 seconds.No
Proxy Authentication vs. Distributed Caching

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.

Ehcache

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>
Memcached

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.

org.apereo.cas.client.HttpServletRequestWrapperFilter

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>
PropertyDescriptionRequired
roleAttributeUsed to determine the principal role.No
ignoreCaseWhether role checking should ignore case. Defaults tofalseNo

org.apereo.cas.client.AssertionThreadLocalFilter

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>

org.apereo.cas.client.ErrorRedirectFilter

Filters that redirects to the supplied url based on an exception. Exceptions and the urls are configured via init filter name/param values.

PropertyDescriptionRequired
defaultErrorRedirectPageDefault url to redirect to, in case no error matches are found.Yes
java.lang.ExceptionFully qualified exception name. Its value must be redirection urlNo
<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>

Client Configuration Using Spring

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>

Bean Configuration

AuthenticationFilter
<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" />
Cas10TicketValidationFilter
<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>
Saml11TicketValidationFilter
<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>
Cas20ProxyReceivingTicketValidationFilter

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:

Spring Boot AutoConfiguration

Usage

  • 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'sapplication.properties orapplication.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@EnableCasClient annotation
@SpringBootApplication@Controller@EnableCasClientpublicclassMyApplication { .. }

For CAS3 protocol (authentication and validation filters) - which is default if nothing is specified

cas.validation-type=CAS3

For CAS2 protocol (authentication and validation filters)

cas.validation-type=CAS

For SAML protocol (authentication and validation filters)

cas.validation-type=SAML

Available optional properties

  • cas.single-logout.enabled
  • cas.authentication-url-patterns
  • cas.validation-url-patterns
  • cas.request-wrapper-url-patterns
  • cas.assertion-thread-local-url-patterns
  • cas.gateway
  • cas.use-session
  • cas.attribute-authorities
  • cas.redirect-after-validation
  • cas.allowed-proxy-chains
  • cas.proxy-callback-url
  • cas.proxy-receptor-url
  • cas.accept-any-proxy
  • server.context-parameters.renew

Spring Security Integration

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=membership

The 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;}

Advanced configuration

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");    }                                }

Configuring Single Sign Out

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.

Configuration

PropertyDescriptionRequired
artifactParameterNameThe ticket artifact parameter name. Defaults toticketNo
logoutParameterNameDefaults tologoutRequestNo
relayStateParameterNameDefaults toRelayStateNo
eagerlyCreateSessionsDefaults totrueNo
artifactParameterOverPostDefaults tofalseNo
logoutCallbackPathThe 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

CAS Protocol

<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>

SAML Protocol

<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>

Recommend Logout Procedure

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)

JAAS

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.

Configure CasLoginModule

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";}
PropertyDescriptionRequired
ticketValidatorClassFully-qualified class name of CAS ticket validator class.Yes
casServerUrlPrefixURL to root of CAS Web application context.Yes
serviceCAS 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
defaultRolesComma-delimited list of static roles applied to all authenticated principals.No
roleAttributeNamesComma-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
principalGroupNameThe name of a group principal containing the primary principal name of the current JAAS subject. The default value isCallerPrincipal.No
roleGroupNameThe name of a group principal containing all role data. The default value isRoles.No
cacheAssertionsFlag 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
cacheTimeoutAssertion cache timeout in minutes.No
toleranceThe tolerance for drifting clocks when validating SAML tickets.No

Programmatic JAAS login using the Servlet 3

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.


[8]ページ先頭

©2009-2025 Movatter.jp