最近进行了spring整合shiro的工作,这里记录下shiro的URL Path Expressions使用的解释:
/account/** = ssl, authc
此行表明,“任何对我应用程序的/accout 或任何它的子路径(/account/foo, account/bar/baz,等等)的请求都将触
发'ssl, authc'过滤器链”。我们将在下面讨论过滤器链。
请注意,所有的路径表达式都是相对于你的应用程序的上下文根目录而言的。这意味着如果某一天你在某个位置部
署了你的应用程序,如 www.somehost.com/myapp ,然后又将它部署到了www.anotherhost.com (没有'myapp'子
目录),这样的匹配模式仍将继续工作。所有的路径都是相对于HttpServletRequest.getContextPath()的值来的。
Order Matters!
URL 路径表达式按事先定义好的顺序判断传入的请求,并遵循FIRST MATCH
WINS 这一原则。例如,让我们假设有如下链的定义:
/account/** = ssl, authc
/account/signup = anon
如果传入的请求旨在访问/account/signup/index.html(所有'anon'ymous 用
户都能访问),那么它将永不会被处理!原因是因为/account/**的模式第
一个匹配了传入的请求,“短路”了其余的定义。
始终记住基于FIRST MATCH WINS 的原则定义你的过滤器链!
Filter Chain Definitions
等号右边是逗号隔开的过滤器列表,用来执行匹配该路径的请求。它必须符合以下格式:
filter1[optional_config1], filter2[optional_config2], ..., filterN[optional_configN]
过滤器简称 |
对应的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< |