zoukankan      html  css  js  c++  java
  • 2020/03/23-浅谈shiro

    浅谈Shiro

    1.shiro能干啥?

    • 认证
    • 授权
    • 加密
    • 会话管理
    • 可以与web集成
    • 缓存
    • more&more。。。

    shiro不会去维护用户、维护权限;这些需要我们手动来完成,需要自己去设计和实现,然后再通过相应的接口注入给Shiro才行。

    2.从程序角度看shiro是如何工作的?

    上图意思是:
    1、应用代码通过Subject来进行认证和授权,而Subject又委托给SecurityManager(安全管理器);
    2、我们需要给Shiro的SecurityManager注入Realm,从而让SecurityManager能得到合法的用户及其权限进行判断。
    从这上面也能看出来了,shiro不提供维护用户权限,也就是Realm这部分是我自己来注入的!!!

    3.shiro的内部架构

    4.过滤器 权限拦截器

    过滤器简称 对应的java类
    anon org.apache.shiro.web.filter.authc.AnonymousFilter
    authc org.apache.shiro.web.filter.authc.FormAuthenticationFilter
    authcBasic org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
    perms org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
    port org.apache.shiro.web.filter.authz.PortFilter
    rest org.apache.shiro.web.filter.authz.HttpMethodPermissionFilter
    roles org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
    ssl org.apache.shiro.web.filter.authz.SslFilter
    user org.apache.shiro.web.filter.authc.UserFilter
    logout org.apache.shiro.web.filter.authc.LogoutFilter

    5.Jsp Shiro标签

    标签名称 标签条件(均是显示标签内容)
    <shiro:authenticated> 登录之后
    <shiro:notAuthenticated> 不在登录状态时
    <shiro:guest> 用户在没有RememberMe时
    <shiro:user> 用户在RememberMe时
    <shiro:hasAnyRoles name="abc,123" > 在有abc或者123角色时
    <shiro:hasRole name="abc"> 拥有角色abc
    <shiro:lacksRole name="abc"> 没有角色abc
    <shiro:hasPermission name="abc"> 拥有权限资源abc
    <shiro:lacksPermission name="abc"> 没有abc权限资源
    <shiro:principal> 默认显示用户名称

    6.Spring security 与apache shiro 差别:

    (1)Shiro更简单,更容易上手
    (2)在Spring环境下,security整合性更好
    (3)shiro适应性更强
    (4)shiro加密功能使用方便
    综上:我们使用shiro更省事!!

    shiro也支持注解,不过无法控制类一级别的访问,粗糙控制手段够用,但是要是细粒度控制,还得是使用过滤器的方式。

    总结:也就是说过滤器粗细都可以,注解只能粗不能细。

  • 相关阅读:
    MyBatis总结六:resultMap详解(包含多表查询)
    MyBatis总结五:#{}和${}的用法和区别
    MyBatis总结四:配置文件xml详解
    MyBatis使用动态代理报 invalid bound statement (not found) 错
    MyBatis总结三:使用动态代理实现dao接口
    MyBatis总结二:增删改查
    session详解&和cookie的区别
    cookie详解
    C#属性器Get和Set
    ORM实例介绍
  • 原文地址:https://www.cnblogs.com/ShenYian/p/12555454.html
Copyright © 2011-2022 走看看