You are viewing the development documentation for the Apereo CAS server. The
functionality presented
here is not officially released yet.
This is a work in progress and will be continually updated as development moves forward. To view
the documentation for a specific Apereo CAS server release, please choose an appropriate version.
The release schedule is also available here.
Ehcache Ticket Registry
Ehcache integration is enabled by including the following dependency in the Maven WAR overlay:
EhCacheTicketRegistry stores tickets in an Ehcache instance.
We present two configurations:
Single instance memory-backed cache with disk overflow for simple cases.
Distributed cache with peer replication over RMI for HA deployments.
Memory Cache with Disk Overflow
The following Spring configuration provides a template for ticketRegistry.xml.
The Ehcache configuration file ehcache-failsafe.xml mentioned in the Spring configuration above:
Distributed Cache
Distributed caches are recommended for HA architectures since they offer fault tolerance in the ticket storage subsystem. The registry maintains service tickets and ticket-granting tickets in two separate caches, so that:
Ticket Granting Tickets remain valid for a long time, replicated asynchronously
Service Tickets are short lived and must be replicated right away because the requests to validate them may very likely arrive at different CAS cluster nodes
RMI Replication
Ehcache supports RMI replication for distributed caches composed of two or more nodes. To learn more about RMI replication with Ehcache, see this resource.
Spring configuration template for ticketRegistry.xml.
The Ehcache configuration for ehcache-replicated.xml mentioned in the Spring config follows.
Use either manual or automatic peer discovery to assemble members of distributed cache. If manual discover is used
for configuration, the file would vary according to the node on which CAS is deployed. For that reason it may be
helpful to place the configuration file on the filesystem at a well-known location and reference it in the
EhCacheManagerFactoryBean above as follows:
JGroups Replication
JGroups can be used as the underlying mechanism for the replication operations in Ehcache. JGroups offers a very flexible protocol stack, reliable unicast, and multicast message transmission. On the down side JGroups can be complex to configure and some protocol stacks have dependencies on others.
Spring configuration template for ticketRegistry.xml.
The configuration is similar to above, except that ticket replicators and cache loaders need to be swapped out for their JGroups counterpart:
The Ehcache JGroups confguration itself needs to be altered to be similar to the following:
Your maven overlay pom.xml will also need to declare the following dependencies:
Eviction Policy
Ehcache manages the internal eviction policy of cached objects via timeToIdle and timeToLive settings. This results of having no need for a Ticket Registry Cleaner.
There have been reports of cache eviction problems when tickets are expired, but haven’t been removed from the cache due to ehache configuration. This can be a problem because old ticket references “hang around” in the cache despite being expired. In other words, Ehcache does inline eviction where expired objects in the cache object won’t be collected from memory until the cache max size is reached or the expired entry is explicitly accessed. To reclaim memory on expired tickets, cache eviction policies are must be carefully configured to avoid memory creep. Disk offload and/or a more aggressive eviction could provide a suitable workaround.
Troubleshooting Guidelines
You will need to ensure that network communication across CAS nodes is allowed and no firewall or other component is blocking traffic.
If you are running this on a server with active firewalls, you will probably need to specify a fixed remoteObjectPort, within the cacheManagerPeerListenerFactory.
Depending on environment settings and version of Ehcache used, you may also have to adjust the shared setting above.
Ensure that each cache manager specified a name that matches the Ehcache configuration itself.
You may also need to adjust your expiration policy to allow for a larger time span, specially for service tickets depending on network traffic and communication delay across CAS nodes particualrly in the event that a node is trying to join the cluster.