zoukankan      html  css  js  c++  java
  • Shiro SessionDAO的设计概念

    SessionDao

    其行为有

    AbstractSessionDAO 

    具备了生成Session的ID的工具SessionIdGenerator,该工具有多种功能(默认是UUID形式的),可以生成UUID形式的,可以是随机数形式的

    公共的方法抽取出来交给AbstractSessionDao来做,如生成Session的ID,如新增、查询、更新、删除Session过程中涉及的行为(四种基础行为抽象)

    public Serializable create(Session session) {
        Serializable sessionId = doCreate(session);
        verifySessionId(sessionId);
        return sessionId;
    }
    
    private void verifySessionId(Serializable sessionId) {
        if (sessionId == null) {
            String msg = "sessionId returned from doCreate implementation is null.  Please verify the implementation.";
            throw new IllegalStateException(msg);
        }
    }
    
    protected abstract Serializable doCreate(Session session);

    MemorySessionDAO具体实现新增行为

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

    将Session存储到了内存中

    private ConcurrentMap<Serializable, Session> sessions;
    
    public MemorySessionDAO() {
        this.sessions = new ConcurrentHashMap<Serializable, Session>();
    }
    
    protected Session storeSession(Serializable id, Session session) {
        if (id == null) {
            throw new NullPointerException("id argument cannot be null.");
        }
        return sessions.putIfAbsent(id, session);
    }
  • 相关阅读:
    创建 demo项目表
    安装 vue-devtools
    安装 Visual Studio Code
    切面拦截过滤日志
    Mysql 创建自增序列表
    [编译] 8、在Linux下搭建 stm8 单片机的开发烧写环境(makefile版)
    [蓝牙嗅探-Ubertooth One] 千元开源蓝牙抓包 Ubertooth One 安装和使用
    微信客服接口文档
    七牛云违规删除问题
    好用的团队协助软件推荐
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/9296258.html
Copyright © 2011-2022 走看看