applicationContext-security.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans:beans xmlns="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 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  5. http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
  6. <!-- 是否启动AOP权限控制 -->
  7. <global-method-security pre-post-annotations="enabled">
  8. <!--
  9. AspectJ pointcut expression that locates our "post" method and
  10. applies security that way <protect-pointcut expression="execution(*
  11. bigbank.*Service.post*(..))" access="ROLE_TELLER"/>
  12. -->
  13. </global-method-security>
  14. <!-- 常用资源不过滤 -->
  15. <http pattern="/resources/**" security="none"></http>
  16. <http pattern="/mobile/**" security="none"></http>
  17. <http pattern="/**/*.jpg" security="none"></http>
  18. <http pattern="/**/*.png" security="none"></http>
  19. <http pattern="/**/*.gif" security="none"></http>
  20. <http pattern="/**/*.css" security="none"></http>
  21. <http pattern="/**/*.js" security="none"></http>
  22. <!-- 超时、禁止访问、页面找不到页面不过滤 -->
  23. <http pattern="/sessiontimeout.jsp" security="none"></http>
  24. <http pattern="/404.jsp" security="none"></http>
  25. <http pattern="/403.jsp" security="none"></http>
  26. <http pattern="/505.jsp" security="none"></http>
  27. <!-- 登陆 不过滤-->
  28. <http pattern="/login1.jsp" security="none"></http>
  29. <!-- 对外数据接口不过滤 -->
  30. <http pattern="/rest/**" security="none"></http>
  31. <http pattern="/app/mainView/**" security="none"></http>
  32. <http pattern="/app/common/**" security="none"></http>
  33. <http pattern="/app/sdk/**" security="none"></http>
  34. <http pattern="/app/images/**" security="none"></http>
  35. <http auto-config="true" use-expressions="true"
  36. access-denied-page="/403.jsp">
  37. <!--
  38. 除上述不需要过滤外,其它任何请求都需要登陆,也就是必须登陆拥有ROLE_USER 角色 <intercept-url
  39. pattern="/**" access="hasRole('ROLE_USER')" />
  40. -->
  41. <intercept-url pattern="/**/*" access="isAuthenticated()" />
  42. <!--
  43. default-target-url 登陆成功后跳转地址 ;login-processing-url
  44. 指定action可以做登录前的一些验证 default-target-url 指定action可以做登录成功后的一些事
  45. authentication-success-handler-ref="authenticationSuccessHandler"
  46. -->
  47. <form-login login-page="/login1.jsp"
  48. authentication-failure-url="/login1.jsp?error=true"
  49. authentication-success-handler-ref="authenticationSuccessHandler" />
  50. <!-- 登出,登出应该还有业务处理,如在线用户,要配置 success-handler-ref=""-->
  51. <logout logout-url="/j_spring_security_logout"
  52. logout-success-url="/login1.jsp" invalidate-session="true" />
  53. <!-- <remember-me data-source-ref="dataSource" /> -->
  54. <session-management invalid-session-url="/sessiontimeout.jsp"
  55. session-fixation-protection="none">
  56. <concurrency-control max-sessions="1"
  57. error-if-maximum-exceeded="true" />
  58. </session-management>
  59. <custom-filter ref="baseSecurityFilter" before="FILTER_SECURITY_INTERCEPTOR" />
  60. </http>
  61. <beans:bean id="authenticationSuccessHandler"
  62. class="com.xc.opal.security.authentication.BaseAuthenticationSuccessHandler"></beans:bean>
  63. <!--
  64. 安全URL拦截器 :
  65. FilterSecurityIntercepto,必须包含authenticationManager,accessDecisionManager,securityMetadataSource三个属性,
  66. 我们的所有控制将在这三个类中实现,解释详见具体配置
  67. -->
  68. <beans:bean id="baseSecurityFilter"
  69. class="com.xc.opal.security.filter.BaseSecurityInterceptorFilter">
  70. <beans:property name="authenticationManager" ref="authenticationManager" />
  71. <beans:property name="accessDecisionManager" ref="baseAccessDecisionManager" />
  72. <beans:property name="securityMetadataSource" ref="baseSecurityMetadataSource" />
  73. </beans:bean>
  74. <!-- 认证管理者 -->
  75. <authentication-manager alias="authenticationManager">
  76. <authentication-provider ref="authenticationProvider">
  77. </authentication-provider>
  78. </authentication-manager>
  79. <!-- 认证提供者 -->
  80. <beans:bean id="authenticationProvider"
  81. class="com.xc.opal.security.authentication.dao.BaseDaoAuthenticationProvider">
  82. <beans:property name="userDetailsService" ref="baseUserDetailService"></beans:property>
  83. <beans:property name="hideUserNotFoundExceptions"
  84. value="false"></beans:property>
  85. <beans:property name="passwordEncoder" ref="md5PasswordEncoder">
  86. </beans:property>
  87. <beans:property name="saltSource" ref="saltSource">
  88. </beans:property>
  89. </beans:bean>
  90. <!-- 密码 提供者,MD5+用户名盐值加密,格式为:密码{用户账号} 或 密码{盐值}-->
  91. <beans:bean id="md5PasswordEncoder"
  92. class="org.springframework.security.authentication.encoding.Md5PasswordEncoder"></beans:bean>
  93. <beans:bean id="saltSource"
  94. class="com.xc.opal.security.authentication.dao.BaseSaltSource"></beans:bean>
  95. <beans:bean id="baseUserDetailService"
  96. class="com.xc.opal.security.filter.BaseUserDetailsService" />
  97. <!-- 访问决策器,决定某个用户具有的角色,是否有足够的权限去访问某个资源。-->
  98. <beans:bean id="baseAccessDecisionManager"
  99. class="com.xc.opal.security.filter.BaseAccessDecisionManager">
  100. </beans:bean>
  101. <!-- 资源源数据定义,将所有的资源和权限对应关系建立起来,即定义某一资源可以被哪些角色去访问。 -->
  102. <beans:bean id="baseSecurityMetadataSource"
  103. class="com.xc.opal.security.filter.BaseInvocationSecurityMetadataSourceService">
  104. </beans:bean>
  105. <!--替换掉spring security的资源文件-->
  106. <beans:bean id="messageSource"
  107. class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  108. <beans:property name="basename"
  109. value="classpath:org/springframework/security/messages_zh_CN" />
  110. </beans:bean>
  111. </beans:beans>