spring-security.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:security="http://www.springframework.org/schema/security"
  5. xsi:schemaLocation="
  6. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
  8. <!-- 该路径下的资源不用过滤 -->
  9. <security:http pattern="/css/**" security="none"/>
  10. <security:http pattern="/qui/**" security="none"/>
  11. <security:http pattern="/js/**" security="none"/>
  12. <security:http pattern="/ckeditor/**" security="none"/>
  13. <security:http pattern="/image/**" security="none"/>
  14. <security:http pattern="/images/**" security="none"/>
  15. <security:http pattern="/login.jsp" security="none"/>
  16. <security:http pattern="/WEB-INF/view/aah/content.jsp" security="none"/>
  17. <security:http pattern="/jatoolsPrinter.cab" security="none"/>
  18. <security:http pattern="/upload/*.xls" security="none"/>
  19. <security:http pattern="/install_lodop32.exe" security="none"/>
  20. <security:http pattern="/install_lodop64.exe" security="none"/>
  21. <security:http pattern="/minicolors/**" security="none"/>
  22. <security:http pattern="/pic/**" security="none"/>
  23. <security:http pattern="/WEB-INF/view/wx/**" security="none"/>
  24. <!-- 自动配置模式,拦截所有请求进行匹配,有ROLE_USER才可以通过 -->
  25. <security:http auto-config="true" use-expressions="true">
  26. <!--使用表单登录-->
  27. <!--
  28. login-page:指定登录页面。
  29. login-processing-url:指定了客户在登录页面中按下 Sign In 按钮时要访问的 URL。
  30. authentication-failure-url:指定了身份验证失败时跳转到的页面。
  31. default-target-url:指定了成功进行身份验证和授权后默认呈现给用户的页面。
  32. always-use-default-target:指定了是否在身份验证通过后总是跳转到default-target-url属性指定的URL。
  33. -->
  34. <security:form-login login-page="/login.jsp" always-use-default-target="false" />
  35. <!--注销用户
  36. logout-url:指定了用于响应退出系统请求的URL。
  37. logout-success-url:退出系统后转向的URL。
  38. invalidate-session:指定在退出系统时是否要销毁Session。
  39. -->
  40. <security:logout invalidate-session="true" logout-url="/logout.do" logout-success-url="/login.jsp"/>
  41. <!-- 实现免登陆验证 -->
  42. <security:remember-me />
  43. <!-- 增加一个自定义的filter,放在FILTER_SECURITY_INTERCEPTOR之前, 实现用户、角色、权限、资源的数据库管理。 -->
  44. <security:custom-filter before="FILTER_SECURITY_INTERCEPTOR" ref="permissionFilter" />
  45. <!--尝试访问没有权限的页面时跳转的页面 ,accessDeniedHandler会接管操作,并转向/403.jsp页面-->
  46. <security:access-denied-handler ref="accessDeniedHandler"/>
  47. </security:http>
  48. <bean id="accessDeniedHandler" class="com.core.web.security.AccessDeniedHandlerImpl">
  49. <property name="accessDeniedUrl" value="/403.jsp"></property>
  50. </bean>
  51. <!-- 一个自定义的filter,必须包含authenticationManager,accessDecisionManager, 三个属性,我们的所有控制将在这三个类中实现 -->
  52. <bean id="permissionFilter" class="com.core.web.security.PermissionFilter">
  53. <!-- 用户拥有的权限 -->
  54. <property name="authenticationManager" ref="authenticationManager" />
  55. <!-- 访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源 -->
  56. <property name="accessDecisionManager" ref="accessDecisionManager" />
  57. <!-- 资源与权限对应关系 -->
  58. <property name="securityMetadataSource" ref="securityMetadataSource" />
  59. </bean>
  60. <!-- 认证管理器,实现用户认证的入口,主要实现UserDetailsService接口即可 -->
  61. <security:authentication-manager alias="authenticationManager" >
  62. <security:authentication-provider user-service-ref="userDetailsManager">
  63. <!-- 密码采用md5加密方式加密 -->
  64. <security:password-encoder base64="false" ref="passwordEncoder">
  65. <!-- 用username做盐值加密,防止md5字典攻击 -->
  66. <security:salt-source user-property="userName"/>
  67. </security:password-encoder>
  68. </security:authentication-provider>
  69. </security:authentication-manager>
  70. <!-- 访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源 -->
  71. <bean id="accessDecisionManager" class="com.core.web.security.AccessDecisionManagerImpl"/>
  72. <!-- 资源源数据定义,即定义某一资源可以被哪些角色访问 -->
  73. <bean id="securityMetadataSource" class="com.core.web.security.SecurityMetadataSourceImpl" scope="singleton">
  74. <constructor-arg index="0" ref="popResourceService"/>
  75. <!--设置不需要登陆就可以访问-->
  76. <property name="anonymousUrls">
  77. <set>
  78. <value>/login.do</value>
  79. <value>/logout.do </value>
  80. <value>/register/view.do</value>
  81. <value>/wx/View.do</value>
  82. <value>/wx/wxview.do</value>
  83. <value>/wx/wxxquery.do</value>
  84. <value>/wx/wxQuery.do</value>
  85. <value>/wx/wxYearQuery.do</value>
  86. <value>/wx/wxYearShow.do</value>
  87. <value>/wx/viewYearWaterPlan.do</value>
  88. <value>/wx/viewYearUnitNotice.do</value>
  89. <value>/wx/wxCreate.do</value>
  90. <value>/wx/binding.do</value>
  91. <value>/wx/index.do</value>
  92. <value>/wx/outOfPlan.do</value>
  93. <value>/wx/binding2.do</value>
  94. <value>/wx/bindInfo.do</value>
  95. <value>/wx/claim.do</value>
  96. <value>/wx/booking.do</value>
  97. <value>/register/checkUserName.do</value>
  98. <value>/register/checkOrgName.do</value>
  99. <value>/register/checkOrgCode.do</value>
  100. <value>/register/getValidCode.do</value>
  101. <value>/register/registerSubmit.do</value>
  102. <value>/org/validateOrgCode.do</value>
  103. <value>/org/validateOrgName.do</value>
  104. <value>/user/validateUserName.do</value>
  105. <!-- <value>/notices/listNoticesShow.do</value> -->
  106. <!-- <value>/notices/view.do</value> -->
  107. <!-- <value>/notices/downloadFile.do</value> -->
  108. <value>/wx/outOfPlan.do</value>
  109. <value>/wx/outOfPlanSearch.do</value>
  110. <value>/templateExport/templateExport.do</value>
  111. <!--
  112. <value>/test/uploadData.do</value>
  113. <value>/test/uploadPage.do</value>
  114. <value>/test/formData.do</value>
  115. -->
  116. </set>
  117. </property>
  118. <!--每个用户登陆后才可以访问的公共资源(如何后台框架),不需要通过角色来分配权限才能看到-->
  119. <property name="publicUrls">
  120. <set>
  121. <value>/frame/main.do</value>
  122. <value>/frame/left.do</value>
  123. <value>/frame/open.do</value>
  124. </set>
  125. </property>
  126. </bean>
  127. <!-- 用户的密码加密或解密 -->
  128. <bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"/>
  129. </beans>