Spring Security 基于数据库的权限管理配置

目前在做一个原型系统,其中涉及到权限管理部分,研究了一下 Spring Security,由于网上资料都是在配置文件里面定义url权限的,基本上没有存在数据库中的。在这个过程中我在网上找了很多资料,但是没有一个是完全能够解决问题的,acegi的例子springside倒是有一个。 而下面这段是一位网上朋友提供的,还不错,解析的清楚,大家可以参考
applicationContext-security.xml文件如下:
Java代码 复制代码
  1. "1.0"encoding="UTF-8"?>
  2. "http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:p="http://www.springframework.org/schema/p"
  4. xmlns:security="http://www.springframework.org/schema/security"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security-2.0.2.xsd">
  7. "springSecurityFilterChain"
  8. class="org.springframework.security.util.FilterChainProxy">
  9. "filterInvocationDefinitionSource">
  10. CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
  11. PATTERN_TYPE_APACHE_ANT
  12. /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor
  13. ]]>
  14. "httpSessionContextIntegrationFilter"
  15. class="org.springframework.security.context.HttpSessionContextIntegrationFilter"/>
  16. "logoutFilter"
  17. class="org.springframework.security.ui.logout.LogoutFilter">
  18. "/login.action"/>
  19. "rememberMeServices"/>
  20. class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"/>
  21. "authenticationProcessingFilter"
  22. class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter"
  23. p:authenticationManager-ref="authenticationManager"
  24. p:authenticationFailureUrl="/login.action?login_error=1"
  25. p:defaultTargetUrl="/user.action"
  26. p:filterProcessesUrl="/j_spring_security_check"
  27. p:rememberMeServices-ref="rememberMeServices"/>
  28. "authenticationManager"
  29. class="org.springframework.security.providers.ProviderManager"
  30. p:sessionController-ref="concurrentSessionController">
  31. "providers">
  32. "daoAuthenticationProvider"/>
  33. class="org.springframework.security.providers.anonymous.AnonymousAuthenticationProvider"
  34. p:key="springsecurity"/>
  35. class="org.springframework.security.providers.rememberme.RememberMeAuthenticationProvider"
  36. p:key="springsecurity"/>
  37. "concurrentSessionController"
  38. class="org.springframework.security.concurrent.ConcurrentSessionControllerImpl"
  39. p:maximumSessions="1"
  40. p:exceptionIfMaximumExceeded="true"
  41. p:sessionRegistry-ref="sessionRegistry"
  42. p:messageSource-ref="messageSource"/>
  43. "sessionRegistry"
  44. class="org.springframework.security.concurrent.SessionRegistryImpl"/>
  45. "messageSource"
  46. class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
  47. p:basename="/WEB-INF/classes/messages_zh_CN"/>
  48. "securityContextHolderAwareRequestFilter"
  49. class="org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter"/>
  50. "rememberMeProcessingFilter"
  51. class="org.springframework.security.ui.rememberme.RememberMeProcessingFilter"
  52. p:authenticationManager-ref="authenticationManager"
  53. p:rememberMeServices-ref="rememberMeServices"/>
  54. "anonymousProcessingFilter"
  55. class="org.springframework.security.providers.anonymous.AnonymousProcessingFilter"
  56. p:key="springsecurity"
  57. p:userAttribute="anonymousUser,ROLE_ANONYMOUS"/>
  58. "exceptionTranslationFilter"
  59. class="org.springframework.security.ui.ExceptionTranslationFilter"
  60. p:accessDeniedHandler-ref="accessDeniedHandler"
  61. p:authenticationEntryPoint-ref="authenticationEntryPoint"/>
  62. "accessDeniedHandler"
  63. class="org.springframework.security.ui.AccessDeniedHandlerImpl"
  64. p:errorPage="/accessDenied.jsp"/>
  65. "authenticationEntryPoint"
  66. class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint"
  67. p:loginFormUrl="/login.action"
  68. p:forceHttps="false"/>
  69. "filterSecurityInterceptor"
  70. class="org.springframework.security.intercept.web.FilterSecurityInterceptor"
  71. p:authenticationManager-ref="authenticationManager"
  72. p:accessDecisionManager-ref="accessDecisionManager"
  73. p:objectDefinitionSource-ref="objectDefinitionSource">
  74. "objectDefinitionSource"
  75. class="com.shopin.modules.security.intercept.web.DataBaseFilterInvocationDefinitionSource"
  76. p:convertUrlToLowercaseBeforeComprison="true"
  77. p:useAntPath="true"
  78. p:cacheManager-ref="securityCacheManager"/>
  79. "accessDecisionManager"
  80. class="org.springframework.security.vote.AffirmativeBased"
  81. p:allowIfAllAbstainDecisions="false">
  82. "decisionVoters">
  83. class="org.springframework.security.vote.RoleVoter"/>
  84. class="org.springframework.security.vote.AuthenticatedVoter"/>
  85. "rememberMeServices"
  86. class="org.springframework.security.ui.rememberme.TokenBasedRememberMeServices"
  87. p:key="springsecurity"
  88. p:userDetailsService-ref="userDetailsService"/>
  89. "daoAuthenticationProvider"
  90. class="org.springframework.security.providers.dao.DaoAuthenticationProvider"
  91. p:userCache-ref="userCache"
  92. p:passwordEncoder-ref="passwordEncoder"
  93. p:userDetailsService-ref="userDetailsService"/>
  94. "passwordEncoder"
  95. class="org.springframework.security.providers.encoding.Md5PasswordEncoder"/>
  96. "resourceCache"
  97. class="com.shopin.modules.security.resourcedetails.EhCacheResourceCache">
  98. "cache">
  99. class="org.springframework.cache.ehcache.EhCacheFactoryBean"
  100. p:cacheManager-ref="cacheManager"
  101. p:cacheName="resourceCache"/>
  102. "userCache"
  103. class="org.springframework.security.providers.dao.cache.EhCacheBasedUserCache">
  104. "cache">
  105. class="org.springframework.cache.ehcache.EhCacheFactoryBean"
  106. p:cacheManager-ref="cacheManager"
  107. p:cacheName="userCache"/>
  108. "cacheManager"
  109. class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
  110. p:configLocation="classpath:ehcache-hibernate.xml">
  111. "userDetailsService"class="cn.shopin.miniweb.service.security.UserDetailServiceImpl"/>
  112. "securityCacheManager"
  113. class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
  114. p:transactionManager-ref="transactionManager"
  115. p:proxyTargetClass="true">
  116. "target">
  117. class="com.shopin.modules.security.cache.SecurityCacheManagerImpl"
  118. p:sessionFactory-ref="sessionFactory"
  119. p:resourcCache-ref="resourceCache"/>
  120. "transactionAttributes">
  121. "init*">PROPAGATION_REQUIRED,readOnly
  122. "get*">PROPAGATION_REQUIRED,readOnly
  123. "loggerListener"
  124. class="org.springframework.security.event.authentication.LoggerListener"/>

你可能感兴趣的:(Spring Security 基于数据库的权限管理配置)