All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.shiro.cache.j2cache.J2CacheCachingSessionDAO Maven / Gradle / Ivy

There is a newer version: 1.0.1.RELEASE
Show newest version
/*
 * Copyright (c) 2018, vindell (https://github.com/vindell).
 *
 * Licensed 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.cache.j2cache;

import java.io.Serializable;

import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.CachingSessionDAO;

public class J2CacheCachingSessionDAO extends CachingSessionDAO {

	@Override
	public void setCacheManager(CacheManager cacheManager) {
		super.setCacheManager(cacheManager);
		if (cacheManager instanceof J2CacheManager) {
			((J2CacheManager) cacheManager).init();
		}
	}

	@Override
	protected Serializable doCreate(Session session) {
		Serializable sessionId = generateSessionId(session);
		assignSessionId(session, sessionId);
		return sessionId;
	}

	@Override
	protected Session doReadSession(Serializable sessionId) {
		return null; 
		// should never execute because this implementation relies on parent class to access cache, which
		// is where all sessions reside - it is the cache implementation that determines
		// if the cache is memory only or disk-persistent, etc.
	}
	
	@Override
	protected void doUpdate(Session session) {
		// does nothing - parent class persists to cache.
	}

	@Override
	protected void doDelete(Session session) {
		// does nothing - parent class removes from cache.
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy