标签:
本文讲述了基于springmvc+shiro实现安全管理,shiro+freemarker实现权限验证。
首先我们从web.xml开始:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 5 <context-param> 6 <param-name>contextConfigLocation</param-name> 7 <param-value> 8 classpath:resources/tag-context.xml 9 classpath:resources/shiro-context.xml 10 </param-value> 11 </context-param> 12 <!-- log4j --> 13 <context-param> 14 <param-name>log4jConfigLocation</param-name> 15 <param-value>classpath:resources/log4j.properties</param-value> 16 </context-param> 17 <context-param> 18 <param-name>log4jDelay</param-name> 19 <param-value>10000</param-value> 20 </context-param> 21 <!-- Spring --> 22 <listener> 23 <listener-class> 24 org.springframework.web.context.ContextLoaderListener 25 </listener-class> 26 </listener> 27 <listener> 28 <listener-class> 29 com.itrip.rp.listener.InitConfigListener 30 </listener-class> 31 </listener> 32 <!-- log4j --> 33 <listener> 34 <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 35 </listener> 36 <!-- 日志记录过滤器 --> 37 <filter> 38 <filter-name>requestLogFilter</filter-name> 39 <filter-class> 40 com.itrip.rp.filter.RequestLogFilter 41 </filter-class> 42 </filter> 43 <filter-mapping> 44 <filter-name>requestLogFilter</filter-name> 45 <url-pattern>/*</url-pattern> 46 </filter-mapping> 47 <!-- 编码过滤 --> 48 <filter> 49 <filter-name>encoding</filter-name> 50 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 51 <init-param> 52 <param-name>encoding</param-name> 53 <param-value>UTF-8</param-value> 54 </init-param> 55 </filter> 56 <filter-mapping> 57 <filter-name>encoding</filter-name> 58 <url-pattern>/*</url-pattern> 59 </filter-mapping> 60 <!-- shiro 安全过滤器 --> 61 <!-- The filter-name matches name of a ‘shiroFilter‘ bean inside applicationContext.xml --> 62 <filter> 63 <filter-name>shiroFilter</filter-name> 64 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 65 <async-supported>true</async-supported> 66 <init-param> 67 <param-name>targetFilterLifecycle</param-name> 68 <param-value>true</param-value> 69 </init-param> 70 </filter> 71 <filter-mapping> 72 <filter-name>shiroFilter</filter-name> 73 <url-pattern>/*</url-pattern> 74 </filter-mapping> 75 <!-- SpringMVC --> 76 <servlet> 77 <servlet-name>resourcePlatform</servlet-name> 78 <servlet-class> 79 org.springframework.web.servlet.DispatcherServlet 80 </servlet-class> 81 <init-param> 82 <param-name>contextConfigLocation</param-name> 83 <param-value> 84 classpath:resources/applicationContext-*.xml 85 </param-value> 86 </init-param> 87 <load-on-startup>1</load-on-startup> 88 </servlet> 89 <servlet-mapping> 90 <servlet-name>resourcePlatform</servlet-name> 91 <url-pattern>/*</url-pattern> 92 </servlet-mapping> 93 </web-app>
按照web.xml初始化顺序依次为:context-param--->listener--->filter--->servlet
tag-context.xml中主要配置了权限验证标签,代码如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" default-lazy-init="true"> <!--后台权限标签--> <bean id="perm" class="com.itrip.rp.core.permission.PermissionDirective"/> </beans>
springmvc+shiro+freemarker实现的安全及权限管理
标签:
原文地址:http://www.cnblogs.com/baifeilong/p/4580622.html