Shiro

Shiro

Apache Shiro

ShiroFilterFactoryBean

全局URL配置

  • loginUrl
  • successUrl
  • unauthorizedUrl

FilterChainDefinition

1
2
3
4
5
6
/index.html = anon 
/user/create = anon
/user/** = authc
/admin/** = authc, roles[administrator]
/rest/** = authc, rest
/remoting/rpc/** = authc, perms["remote:invoke"]

以上配置等价于 url = filter1[op1], ..., filterN[opN], 一条连接中配置的多个filter组成一条filterChain.

如: /index.htmlfilterChiananon(AnonymousFilter)组成

当浏览器发起请求时候通过url匹配来选择所需要的filterChain达到权限过滤的目的.

Shiro Filter

Filter名称 说明 类名
anon 匿名过滤器 o.a.s.w.f.authc.AnonymousFilter
authc 如果继续操作,需要做对应的表单验证否则不能通过 o.a.s.w.f.authc.FormAuthenticationFilter
authcBasic 基本http验证过滤如果不通过,跳转屋登录页面 o.a.s.w.f.authc.BasicHttpAuthenticationFilter
logout 登录退出过滤器 o.a.s.w.f.authc.LogoutFilter
noSessionCreation 没有session创建过滤器 o.a.s.w.f.session.NoSessionCreationFilter
perms 权限过滤器 o.a.s.w.f.authz.PermissionsAuthorizationFilter
port 端口过滤器,可以设置是否是指定端口如果不是跳转到登录页面 o.a.s.w.f.authz.PortFilter
rest http方法过滤器,可以指定如post不能进行访问等 o.a.s.w.f.authz.HttpMethodPermissionFilter
roles 角色过滤器,判断当前用户是否指定角色 o.a.s.w.f.authz.RolesAuthorizationFilter
ssl 请求需要通过ssl,如果不是跳转回登录页 o.a.s.w.f.authz.SslFilter
user 如果访问一个已知用户,比如记住我功能,走这个过滤器 o.a.s.w.f.authc.UserFilter

原文:大专栏  Shiro