spring security

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beans:beansxmlns="http://www.springframework.org/schema/security"
  3. xmlns:beans="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  6. http://www.springframework.org/schema/security
  7. http://www.springframework.org/schema/security/spring-security-3.0.xsd">
  8. <global-method-securitypre-post-annotations="enabled">
  9. </global-method-security>
  10. <!--entry-point-ref为用户第一次访问受保护的url时的处理程序.-->
  11. <httpuse-expressions="true"entry-point-ref="authenticationEntryPoint">
  12. <!--这里是拒绝用户访问的处理程序-->
  13. <access-denied-handlerref="accessDeniedHandler"/>
  14. <!--配置一些不需要认证过滤的地址-->
  15. <intercept-urlpattern="/roots/login.jsp"filters="none"/>
  16. <intercept-urlpattern="/css/**"filters="none"/>
  17. <intercept-urlpattern="/common/**"filters="none"/>
  18. <intercept-urlpattern="/images/**"filters="none"/>
  19. <intercept-urlpattern="/scripts/**"filters="none"/>
  20. <intercept-urlpattern="/DatePicker/**"filters="none"/>
  21. <intercept-urlpattern="/fckeditor/**"filters="none"/>
  22. <!--cooki认证的配置,具体看rememberMeServices的配置.-->
  23. <remember-meservices-ref="rememberMeServices"/>
  24. <!--
  25. 增加一个filter,这点与Acegi是不一样的,不能修改默认的filter了,这个filter位于FILTER_SECURITY_INTERCEPTOR之前
  26. -->
  27. <custom-filterposition="LOGOUT_FILTER"ref="logoutFilter"></custom-filter>
  28. <custom-filterbefore="FILTER_SECURITY_INTERCEPTOR"ref="myFilter"/>
  29. <custom-filterposition="FORM_LOGIN_FILTER"ref="myAuthFilter"/>
  30. <!--限制用户的最大登陆数,防止一个账号被多人使用-->
  31. <custom-filterposition="CONCURRENT_SESSION_FILTER"ref="concurrencyFilter"/>
  32. <session-management
  33. session-authentication-strategy-ref="sas"/>
  34. </http>
  35. <!--认证管理器,实现用户认证的入口,主要实现UserDetailsService接口即可如下,可以配置多个Provider-->
  36. <authentication-manageralias="authenticationManager">
  37. <authentication-providerref="daoAuthenticationProvider">
  38. <password-encoderhash="plaintext"></password-encoder>
  39. </authentication-provider>
  40. <authentication-providerref="rememberMeAuthenticationProvider">
  41. <password-encoderhash="plaintext"></password-encoder>
  42. </authentication-provider>
  43. </authentication-manager>
  44. <beans:beanid="daoAuthenticationProvider"
  45. class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
  46. <beans:propertyname="userDetailsService"ref="myUserDetailService"/>
  47. </beans:bean>
  48. <!--
  49. 一个自定义的filter,必须包含authenticationManager,accessDecisionManager,securityMetadataSource三个属性,
  50. 我们的所有控制将在这三个类中实现,解释详见具体配置
  51. -->
  52. <beans:beanid="myFilter"class="com.security.MyFilterSecurityInterceptor">
  53. <beans:propertyname="authenticationManager"ref="authenticationManager"/>
  54. <beans:propertyname="accessDecisionManager"ref="myAccessDecisionManagerBean"/>
  55. <beans:propertyname="securityMetadataSource"ref="securityMetadataSource"/>
  56. </beans:bean>
  57. <!--
  58. 下面的3个类,已做自动扫描<beans:beanid="myUserDetailService"
  59. class="com.security.MyUserDetailService"/>
  60. 访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源<beans:bean
  61. id="myAccessDecisionManagerBean"
  62. class="com.security.MyAccessDecisionManager"></beans:bean>
  63. 资源源数据定义,即定义某一资源可以被哪些角色访问<beans:beanid="securityMetadataSource"
  64. class="com.security.MyInvocationSecurityMetadataSource">
  65. </beans:bean>
  66. -->
  67. <beans:beanid="logoutFilter"
  68. class="org.springframework.security.web.authentication.logout.LogoutFilter">
  69. <beans:constructor-argvalue="/roots/login.jsp"/>
  70. <beans:constructor-arg>
  71. <beans:list>
  72. <beans:reflocal="rememberMeServices"/>
  73. <beans:bean
  74. class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"></beans:bean>
  75. </beans:list>
  76. </beans:constructor-arg>
  77. <beans:propertyname="filterProcessesUrl"value="/ss_Loginout"></beans:property>
  78. </beans:bean>
  79. <beans:beanid="concurrencyFilter"
  80. class="org.springframework.security.web.session.ConcurrentSessionFilter">
  81. <beans:propertyname="sessionRegistry"ref="sessionRegistry"/>
  82. <beans:propertyname="expiredUrl"value="/error/expired.jsp"/>
  83. </beans:bean>
  84. <beans:beanid="sas"
  85. class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
  86. <beans:constructor-argname="sessionRegistry"
  87. ref="sessionRegistry"/>
  88. <beans:propertyname="maximumSessions"value="1"/>
  89. </beans:bean>
  90. <beans:beanid="myAuthFilter"
  91. class="com.security.fliter.MyUsernamePasswordAuthenticationFilter">
  92. <beans:propertyname="sessionAuthenticationStrategy"
  93. ref="sas"/>
  94. <beans:propertyname="authenticationManager"ref="authenticationManager"/>
  95. <beans:propertyname="rememberMeServices"ref="rememberMeServices"></beans:property>
  96. <beans:propertyname="authenticationFailureHandler"
  97. ref="failureHandler"/>
  98. <beans:propertyname="authenticationSuccessHandler"
  99. ref="successHandler"/>
  100. <beans:propertyname="filterProcessesUrl"value="/ss_Login"></beans:property>
  101. </beans:bean>
  102. <beans:beanid="successHandler"
  103. class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler">
  104. <beans:propertyname="defaultTargetUrl"value="/roots/index.jsp"/>
  105. </beans:bean>
  106. <beans:beanid="failureHandler"
  107. class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
  108. <beans:propertyname="defaultFailureUrl"value="/roots/login.jsp?error=true"/>
  109. </beans:bean>
  110. <beans:beanid="sessionRegistry"
  111. class="org.springframework.security.core.session.SessionRegistryImpl"/>
  112. <!--
  113. remembermefliter此fliter的配置没有使用留做参考<beans:bean
  114. id="rememberMeFilter"
  115. class="org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter">
  116. <beans:propertyname="rememberMeServices"ref="rememberMeServices"/>
  117. <beans:propertyname="authenticationManager"
  118. ref="authenticationManager"/></beans:bean>
  119. -->
  120. <beans:beanid="rememberMeServices"
  121. class="org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices">
  122. <beans:propertyname="userDetailsService"ref="myUserDetailService"/>
  123. <beans:propertyname="key"value="springsecurityCookies1"/>
  124. <beans:propertyname="alwaysRemember"value="true"></beans:property>
  125. <beans:propertyname="tokenValiditySeconds"value="86400"></beans:property>
  126. <beans:propertyname="parameter"value="_spring_security_remember_me"></beans:property>
  127. </beans:bean>
  128. <beans:beanid="rememberMeAuthenticationProvider"
  129. class="org.springframework.security.authentication.RememberMeAuthenticationProvider">
  130. <beans:propertyname="key"value="springsecurityCookies1"/>
  131. </beans:bean>
  132. <!--
  133. 此fliter的配置没有使用留做参考<beans:beanid="exceptionTranslationFilter"
  134. class="org.springframework.security.web.access.ExceptionTranslationFilter">
  135. <beans:propertyname="authenticationEntryPoint"
  136. ref="authenticationEntryPoint"/><beans:property
  137. name="accessDeniedHandler"ref="accessDeniedHandler"/></beans:bean>
  138. -->
  139. <beans:beanid="authenticationEntryPoint"
  140. class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
  141. <beans:propertyname="loginFormUrl"value="/roots/login.jsp"/>
  142. </beans:bean>
  143. <beans:beanid="accessDeniedHandler"
  144. class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
  145. <beans:propertyname="errorPage"value="/roots/login.jsp?error=ad"/>
  146. </beans:bean>
  147. <!--下面配置,security对于方法的保护-->
  148. <beans:beanid="methodSecurityInterceptor"
  149. class="org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor">
  150. <beans:propertyname="validateConfigAttributes">
  151. <beans:value>false</beans:value>
  152. </beans:property>
  153. <beans:propertyname="authenticationManager">
  154. <beans:refbean="authenticationManager"/>
  155. </beans:property>
  156. <beans:propertyname="accessDecisionManager">
  157. <beans:refbean="myAccessDecisionManagerBean"/>
  158. </beans:property>
  159. <!--这里配置通过数据库配置来查找权限myMethodSecurityMetadataSource这个类继承AbstractMethodSecurityMetadataSource-->
  160. <beans:propertyname="securityMetadataSource"ref="myMethodSecurityMetadataSource"/>
  161. <!--
  162. 说明:下面的模式是配置了ISome类的doSupervisor的方法只需要ROLE_SUPERVISOR来访问<value>
  163. com.acegi.MethodInterceptionTest.method*=ROLE_ADMIN</value>
  164. </property>
  165. -->
  166. </beans:bean>
  167. <!--
  168. 在数据库里配置roleanddatebase...下面的autoProxyCreator还是要配置切入点的.
  169. myMethodSecurityMetadataSource已经配置在自动扫描中.
  170. -->
  171. <beans:beanid="sprintsecurityAutoIntercept"
  172. class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"
  173. scope="singleton">
  174. <beans:propertyname="beanNames">
  175. <!--在这里配置要切的类的名称,可以为一个配置好的bean的id,多个id用逗号分隔-->
  176. <beans:value>*test</beans:value>
  177. </beans:property>
  178. <!--这里就写上切入点-->
  179. <beans:propertyname="interceptorNames">
  180. <beans:list>
  181. <beans:value>methodSecurityInterceptor</beans:value>
  182. </beans:list>
  183. </beans:property>
  184. <!--这个,如果你的类被代理了,比如在spring中使用,一定要设置这个属性为true-->
  185. <beans:propertyname="proxyTargetClass"value="true"/>
  186. </beans:bean>
  187. <!--这里接收security日志的配置
  188. <beanid="authenticationLoggerListener"
  189. class="org.springframework.security.authentication.event.LoggerListener"/>
  190. <beanid="authorizationLoggerListener"
  191. class="org.springframework.security.access.event.LoggerListener"/>
  192. -->
  193. </beans:beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值