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);
    }
  • 相关阅读:
    C#面向对象的基本原则
    EXTJS学习笔记:类似于Window的登录窗体
    c# 类似于QQ表情弹出框功能的二种实现方法
    EXTJS学习笔记:grid之分组实现groupingview
    RibbonBar屏蔽右键
    webservice安全性浅谈
    js生成二维码以及插入图片
    c++之const解惑
    最短路径连接表形式
    深入理解c++之动态内存和指针
  • 原文地址:https://www.cnblogs.com/BINGJJFLY/p/9296258.html
Copyright © 2011-2022 走看看