123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.gxzc.zen.umps.util
- import com.gxzc.zen.common.util.SpringContextHolder
- import org.apache.shiro.session.Session
- import org.apache.shiro.session.mgt.eis.SessionDAO
- /**
- * Shiro redis 工具类
- * @author NorthLan
- * @date 2018/5/3
- * @url https://noahlan.com
- */
- object ShiroRedisUtil {
- private var sessionDAO = SpringContextHolder.getBean(SessionDAO::class.java)
- get() {
- if (field == null) {
- field = SpringContextHolder.getBean(SessionDAO::class.java)
- }
- return field
- }
- fun getActiveSessions(): MutableCollection<Session> {
- return sessionDAO!!.activeSessions
- }
- private fun updateSession(session: Session) {
- sessionDAO!!.update(session)
- }
- fun removeAllSessionsAttributeKey(key: Any?) {
- val sessions = getActiveSessions()
- sessions.forEach { s ->
- s.setAttribute(key, null)
- updateSession(s)
- }
- }
- fun removeSessionAttributeKey(session: Session, key: Any?) {
- session.setAttribute(key, null)
- updateSession(session)
- }
- }
|