shiro是如何实现httpsession的操作的

//获取当前用户
Subject subject = SecurityUtils.getSubject();
//获取当前用户session,默认为不存在session就创建session
Session session = subject.getSessio();

而subject的实现类通过打断点可以知道其实现类为DelegatingSubject,而他有一个方法叫getSession(boolean create),一看就知道
是获取session的意思,这个方法里有一段代码:Session session = this.securityManager.start(sessionContext);
这个this.securityManager的是实现类是ServletContainerSessionManager,查看他的start方法:

 Session session = this.securityManager.start(sessionContext);
其实就是包含了一个createSession方法,然后看HttpSession httpSession = request.getSession();这段代码,
原来shiro获取session还是依赖着httpSession的。


  protected Session createSession(SessionContext sessionContext) throws AuthorizationException {
        if (!WebUtils.isHttp(sessionContext)) {
            String msg = "SessionContext must be an HTTP compatible implementation.";
            throw new IllegalArgumentException(msg);
        }

        HttpServletRequest request = WebUtils.getHttpRequest(sessionContext);

        HttpSession httpSession = request.getSession();

        //SHIRO-240: DO NOT use the 'globalSessionTimeout' value here on the acquired session.
        //see: https://issues.apache.org/jira/browse/SHIRO-240

        String host = getHost(sessionContext);

        return createSession(httpSession, host);
    }

继续往下想,request是如何获取session的。。个人认为是tomcat实现的

转载于:https://my.oschina.net/wwwd/blog/804062

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值