| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>EnterpriseCacheSessionDAO.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Shiro :: Core</a> > <a href="index.source.html" class="el_package">org.apache.shiro.session.mgt.eis</a> > <span class="el_source">EnterpriseCacheSessionDAO.java</span></div><h1>EnterpriseCacheSessionDAO.java</h1><pre class="source lang-java linenums">/* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.apache.shiro.session.mgt.eis; |
| |
| import org.apache.shiro.cache.AbstractCacheManager; |
| import org.apache.shiro.cache.Cache; |
| import org.apache.shiro.cache.CacheException; |
| import org.apache.shiro.cache.MapCache; |
| import org.apache.shiro.session.Session; |
| |
| import java.io.Serializable; |
| import java.util.concurrent.ConcurrentHashMap; |
| |
| /** |
| * SessionDAO implementation that relies on an enterprise caching product as the EIS system of record for all sessions. |
| * It is expected that an injected {@link org.apache.shiro.cache.Cache Cache} or |
| * {@link org.apache.shiro.cache.CacheManager CacheManager} is backed by an enterprise caching product that can support |
| * all application sessions and/or provide disk paging for resilient data storage. |
| * <h2>Production Note</h2> |
| * This implementation defaults to using an in-memory map-based {@code CacheManager}, which is great for testing but |
| * will typically not scale for production environments and could easily cause {@code OutOfMemoryException}s. Just |
| * don't forget to configure<b>*</b> an instance of this class with a production-grade {@code CacheManager} that can |
| * handle disk paging for large numbers of sessions and you'll be fine. |
| * <p/> |
| * <b>*</b>If you configure Shiro's {@code SecurityManager} instance with such a {@code CacheManager}, it will be |
| * automatically applied to an instance of this class and you won't need to explicitly set it in configuration. |
| * <h3>Implementation Details</h3> |
| * This implementation relies heavily on the {@link CachingSessionDAO parent class}'s transparent caching behavior for |
| * all storage operations with the enterprise caching product. Because the parent class uses a {@code Cache} or |
| * {@code CacheManager} to perform caching, and the cache is considered the system of record, nothing further needs to |
| * be done for the {@link #doReadSession}, {@link #doUpdate} and {@link #doDelete} method implementations. This class |
| * implements those methods as required by the parent class, but they essentially do nothing. |
| * |
| * @since 1.0 |
| */ |
| public class EnterpriseCacheSessionDAO extends CachingSessionDAO { |
| |
| <span class="fc" id="L54"> public EnterpriseCacheSessionDAO() {</span> |
| <span class="fc" id="L55"> setCacheManager(new AbstractCacheManager() {</span> |
| @Override |
| protected Cache<Serializable, Session> createCache(String name) throws CacheException { |
| <span class="nc" id="L58"> return new MapCache<Serializable, Session>(name, new ConcurrentHashMap<Serializable, Session>());</span> |
| } |
| }); |
| <span class="fc" id="L61"> }</span> |
| |
| protected Serializable doCreate(Session session) { |
| <span class="fc" id="L64"> Serializable sessionId = generateSessionId(session);</span> |
| <span class="fc" id="L65"> assignSessionId(session, sessionId);</span> |
| <span class="fc" id="L66"> return sessionId;</span> |
| } |
| |
| protected Session doReadSession(Serializable sessionId) { |
| <span class="nc" id="L70"> return null; //should never execute because this implementation relies on parent class to access cache, which</span> |
| //is where all sessions reside - it is the cache implementation that determines if the |
| //cache is memory only or disk-persistent, etc. |
| } |
| |
| protected void doUpdate(Session session) { |
| //does nothing - parent class persists to cache. |
| <span class="fc" id="L77"> }</span> |
| |
| protected void doDelete(Session session) { |
| //does nothing - parent class removes from cache. |
| <span class="nc" id="L81"> }</span> |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.eclemma.org/jacoco">JaCoCo</a> 0.7.7.201606060606</span></div></body></html> |