Shiro系列教程URL匹配规则(AntPathMatcher)

来源:互联网 发布:jquery.reveal js关闭 编辑:程序博客网 时间:2024/06/05 18:55

官方示例

...[urls]/index.html = anon/user/create = anon/user/** = authc/admin/** = authc, roles[administrator]/rest/** = authc, rest/remoting/rpc/** = authc, perms["remote:invoke"]


匹配规则

?  匹配一个字符
*  匹配一个或多个字符
** 匹配一个或多个目录

com/t?st.jsp 匹配 com/test.jsp but also com/tast.jsp or com/txst.jsp 
PatternMatcher matcher = new AntPathMatcher();System.out.println(matcher.matches("/com/t?st.jsp", "/com/txst.jsp"));System.out.println(matcher.matches("/com/t?st.jsp", "/com/tast.jsp"));System.out.println(matcher.matches("/com/t?st.jsp", "/com/txst.jsp"));

com/*.jsp 匹配com目录下任何.jsp文件
PatternMatcher matcher = new AntPathMatcher();System.out.println(matcher.matches("com/*.jsp", "com/txst.jsp"));System.out.println(matcher.matches("com/*.jsp", "com/tast.jsp"));System.out.println(matcher.matches("com/*.jsp", "com/txst.jsp"));

com/**/test.jsp 匹配 com目录下任何text.jsp文件
PatternMatcher matcher = new AntPathMatcher();System.out.println(matcher.matches("com/**/test.jsp", "com/a/test.jsp"));System.out.println(matcher.matches("com/**/test.jsp", "com/b/test.jsp"));System.out.println(matcher.matches("com/**/test.jsp", "com/c/d/test.jsp"));

org/apache/shiro/**/*.jsp  匹配org/apache/shiro 目录下任何jsp文件
PatternMatcher matcher = new AntPathMatcher();System.out.println(matcher.matches("org/apache/shiro/**/*.jsp ", "org/apache/shiro/test.jsp"));System.out.println(matcher.matches("org/apache/shiro/**/*.jsp ", "org/apache/shiro/sub1/sub1.jsp"));System.out.println(matcher.matches("org/apache/shiro/**/*.jsp ", "org/apache/shiro/sub2/sub2.jsp"));

org/**/servlet/bla.jsp   匹配 org/apache/shiro/servlet/bla.jsp  ||  org/apache/shiro/testing/servlet/bla.jsp || org/servlet/bla.jsp 
PatternMatcher matcher = new AntPathMatcher();System.out.println(matcher.matches("org/**/servlet/bla.jsp", "org/apache/shiro/servlet/bla.jsp"));System.out.println(matcher.matches("org/**/servlet/bla.jsp", "org/apache/shiro/testing/servlet/bla.jsp"));System.out.println(matcher.matches("org/**/servlet/bla.jsp", "org/servlet/bla.jsp"));


0 0
原创粉丝点击