天天看点

shiro(5)-重点研究的urls配置

在shiro.ini 中配置的结点urls可能是shiro中处理web项目比较核心的部分,在这里边配置各个过滤器的规则。

如果你想使用需要在web.xml中配置

可以动态的设置shiro.ini的路径,一种是写到配置文件中,一种是使用程序加载。

在web.xml中可以动态配置shiro.ini的位置

示例如下:

还有一种方式是通过应用程序加载

根据示例中的spring-hibernate

配置

设置filterchaindefinitions属性,就可以将设置中的值动态的加载到对应的ini类中。也可以实现加载配置过滤器的效果。

shiro.ini的[urls]节点

节点下的配置信息如下格式

url_ant_path_expression = path_specific_filter_chain

指定对应的url执行的过滤器链。

如果出现下面的这种过滤情况

则下面的默认永远都不执行,即访问/account/signup/index.html 的时候,只执行上面的过滤器,不执行下面的。

如果shiro提供的过滤器不能满足要求,则可以使用自定义的过滤器,设置的规则如下:

shiro中默认的过滤器

过滤器名称

过滤器类

描述

anon

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/anonymousfilter.html">org.apache.shiro.web.filter.authc.anonymousfilter</a>

匿名过滤器

authc

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/formauthenticationfilter.html">org.apache.shiro.web.filter.authc.formauthenticationfilter</a>

如果继续操作,需要做对应的表单验证否则不能通过

authcbasic

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/basichttpauthenticationfilter.html">org.apache.shiro.web.filter.authc.basichttpauthenticationfilter</a>

基本http验证过滤,如果不通过,跳转屋登录页面

logout

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/logoutfilter.html">org.apache.shiro.web.filter.authc.logoutfilter</a>

登录退出过滤器

nosessioncreation

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/session/nosessioncreationfilter.html">org.apache.shiro.web.filter.session.nosessioncreationfilter</a>

没有session创建过滤器

perms

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/permissionsauthorizationfilter.html">org.apache.shiro.web.filter.authz.permissionsauthorizationfilter</a>

权限过滤器

port

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/portfilter.html">org.apache.shiro.web.filter.authz.portfilter</a>

端口过滤器,可以设置是否是指定端口如果不是跳转到登录页面

rest

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/httpmethodpermissionfilter.html">org.apache.shiro.web.filter.authz.httpmethodpermissionfilter</a>

http方法过滤器,可以指定如post不能进行访问等

roles

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/rolesauthorizationfilter.html">org.apache.shiro.web.filter.authz.rolesauthorizationfilter</a>

角色过滤器,判断当前用户是否指定角色

ssl

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authz/sslfilter.html">org.apache.shiro.web.filter.authz.sslfilter</a>

请求需要通过ssl,如果不是跳转回登录页

user

<a href="http://shiro.apache.org/static/current/apidocs/org/apache/shiro/web/filter/authc/userfilter.html">org.apache.shiro.web.filter.authc.userfilter</a>

如果访问一个已知用户,比如记住我功能,走这个过滤器

当然也可以设置过滤器的使用或者禁用:

对应的设置如下:

基本表单登录

在login.jsp中

在不连接数据库的情况下