https://my.oschina.net/wdmiye/blog/887193

 要想快速了解Shiro,必须先从整体上去了解它,先说说它的高度概括框架:

Shiro包含三个核心组件:Subject,SecurityManager 和 Realms。具体来说:

Subject 是与程序进行交互的对象,可以是人也可以是服务或者其他,通常就理解为用户。

所有Subject 实例都必须绑定到一个SecurityManager上。我们与一个 Subject 交互,运行时shiro会自动转化为与 SecurityManager交互的特定 subject的交互。
SecurityManager 是 Shiro的核心,初始化时协调各个模块运行。

当SecurityManager协调完毕,SecurityManager 会被单独留下,且我们只需要去操作Subject即可,无需操作SecurityManager 。 但是我们得知道,当我们正与一个 Subject 进行交互时,实质上是 SecurityManager在处理 Subject 安全操作。

 

Realms在 Shiro中作为应用程序和安全数据之间的“桥梁”或“连接器”。

它获取安全数据来判断subject是否能够登录,subject拥有什么权限。有点类似DAO。在配置realms时,需要至少一个realm。而且Shiro提供了一些常用的 Realms来连接数据源,如LDAP数据源的JndiLdapRealm,JDBC数据源的JdbcRealm,ini文件数据源的IniRealm,properties文件数据源的PropertiesRealm等等。我们也可以插入自己的 Realm实现来代表自定义的数据源。 像其他组件一样,Realms也是由SecurityManager控制

 

Shiro 主要有四个组件

 

  1. SecurityManager典型的 Facade,Shiro 通过它对外提供安全管理的各种服务。
  2. Authenticator对“Who are you ?”进行核实。通常涉及用户名和密码。

    这 个组件负责收集 principals 和 credentials,并将它们提交给应用系统。如果提交的 credentials 跟应用系统中提供的 credentials 吻合,就能够继续访问,否则需要重新提交 principals 和 credentials,或者直接终止访问。

  3. Authorizer身 份份验证通过后,由这个组件对登录人员进行访问控制的筛查,比如“who can do what”, 或者“who can do which actions”。Shiro 采用“基于 Realm”的方法,即用户(又称 Subject)、用户组、角色和 permission 的聚合体。
  4. Session Manager这个组件保证了异构客户端的访问,配置简单。它是基于 POJO/J2SE 的,不跟任何的客户端或者协议绑定。

 

1. 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> 默认显示用户名称

 

 

url过滤器

过滤器简称 对应的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