shiro框架解读

最近看了一下shiro源码,觉得shiro做有关权限系统挺方便的,很多的东西它都是默认了的,根据实际情况重写一些方法,便可应用到实际开发中。扩展性非常强,灵活性高,是一个不错的优秀开源框架,通过阅读源码,运用到一些设计模式,还是挺值得去学习的。

shiro框架图

在这里插入图片描述
Subject 主体:可以是当前的用户,可以是第三方服务。
Security Manager 安全管理器:负责协调各个组件的。
Authenticator:登录认证器,登录时用到。
Authorizer:权限认证器,当访问的资源需要权限校验时会调用。
realm:使用shiro框架登录与鉴权时,一定要至少配置一个realm,实现其中的那个两个方法,一个是身份信息(AuthenticationInfo)封装返回,一个是权限信息(AuthorizationInfo)封装返回。

shiro登录校验流程及权限校验流程

在这里插入图片描述
登记认证时可以通过FormAuthenticationFilter进行验证,也可以直接通过subje.login(token),其实FormAuthenticationFilter在做检验时,间接调用了subje.login(token)方法进行权限校验。

shiro cookie信息创建

//shiro中创建cookie信息
AbstractNativeSessionManager:
public Session start(SessionContext context) {
   Session session = this.createSession(context); //创建simpleSession
     this.applyGlobalSessionTimeout(session);
     this.onStart(session, context);
     this.notifyStart(session);//通知
     return this.createExposedSession(session, context);
 }
 
DefaultWebSessionManager:
protected void onStart(Session session, SessionContext context) {
    super.onStart(session, context);
    if (!WebUtils.isHttp(context)) {
        log.debug("SessionContext argument is not HTTP compatible or does not have an HTTP request/response pair. No session ID cookie will be set.");
    } else {
        HttpServletRequest request = WebUtils.getHttpRequest(context);
        HttpServletResponse response = WebUtils.getHttpResponse(context);
        if (this.isSessionIdCookieEnabled()) {
            Serializable sessionId = session.getId();
            this.storeSessionId(sessionId, request, response);//将sessionid保存到cookie
        } else {
            log.debug("Session ID cookie is disabled.  No cookie has been set for new session with id {}", session.getId());
        }

        request.removeAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_ID_SOURCE);
        request.setAttribute(ShiroHttpServletRequest.REFERENCED_SESSION_IS_NEW, Boolean.TRUE);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值