spring-shiro.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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" xmlns:aop="http://www.springframework.org/schema/aop"
  4. xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
  5. xmlns:context="http://www.springframework.org/schema/context"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  9. http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  10. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
  11. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
  12. <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
  13. <property name="maxIdle" value="100"/>
  14. <property name="minIdle" value="10"/>
  15. <property name="testOnBorrow" value="true"/>
  16. </bean>
  17. <bean id="jedisPool" class="redis.clients.jedis.JedisPool">
  18. <constructor-arg index="0" ref="jedisPoolConfig" />
  19. <constructor-arg index="1" value="${jedis.host}" name="host" type="java.lang.String"/>
  20. <constructor-arg index="2" value="${jedis.port}" name="port" type="int"/>
  21. <constructor-arg index="3" value="${jedis.timeout}" name="timeout" type="int"/>
  22. <constructor-arg index="4" value="${jedis.password}" name="password" type="java.lang.String"/>
  23. </bean>
  24. <bean id="sessionIdGenerator" class="org.apache.shiro.session.mgt.eis.JavaUuidSessionIdGenerator"/>
  25. <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie">
  26. <constructor-arg value="AFT_SID"/>
  27. <property name="httpOnly" value="true"/>
  28. <property name="maxAge" value="1296000"/>
  29. <!--
  30. <property name="domain" value=""/>
  31. -->
  32. </bean>
  33. <!-- custom shiro session listener -->
  34. <bean id="customSessionListener" class="com.goafanti.core.shiro.listener.CustomSessionListener">
  35. <property name="shiroSessionRepository" ref="jedisShiroSessionRepository"/>
  36. </bean>
  37. <!-- custom shiro session listener -->
  38. <bean id="customShiroSessionDAO" class="com.goafanti.core.shiro.CustomShiroSessionDAO">
  39. <property name="shiroSessionRepository" ref="jedisShiroSessionRepository"/>
  40. <property name="sessionIdGenerator" ref="sessionIdGenerator"/>
  41. </bean>
  42. <!-- -->
  43. <bean id="customSessionManager" class="com.goafanti.core.shiro.session.CustomSessionManager">
  44. <property name="shiroSessionRepository" ref="jedisShiroSessionRepository"/>
  45. <property name="customShiroSessionDAO" ref="customShiroSessionDAO"/>
  46. </bean>
  47. <!-- -->
  48. <bean id="sessionValidationScheduler" class="org.apache.shiro.session.mgt.ExecutorServiceSessionValidationScheduler">
  49. <!-- -->
  50. <property name="interval" value="${session.validate.timespan}"/>
  51. <property name="sessionManager" ref="sessionManager"/>
  52. </bean>
  53. <!-- -->
  54. <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
  55. <property name="realm" ref="userRealm"/>
  56. <property name="sessionManager" ref="sessionManager"/>
  57. <property name="cacheManager" ref="customShiroCacheManager"/>
  58. </bean>
  59. <!-- -->
  60. <bean id="customShiroCacheManager" class="com.goafanti.core.shiro.cache.impl.CustomShiroCacheManager">
  61. <property name="shiroCacheManager" ref="jedisShiroCacheManager"/>
  62. </bean>
  63. <!-- -->
  64. <bean id="jedisShiroCacheManager" class="com.goafanti.core.shiro.cache.impl.JedisShiroCacheManager">
  65. <property name="jedisManager" ref="jedisManager"/>
  66. </bean>
  67. <!-- -->
  68. <bean id="jedisManager" class="com.goafanti.core.shiro.cache.JedisManager">
  69. <property name="jedisPool" ref="jedisPool"/>
  70. </bean>
  71. <!-- SecurityUtils.setSecurityManager(securityManager) -->
  72. <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  73. <property name="staticMethod" value="org.apache.shiro.SecurityUtils.setSecurityManager"/>
  74. <property name="arguments" ref="securityManager"/>
  75. </bean>
  76. <!-- credential matcher -->
  77. <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
  78. <property name="hashAlgorithmName" value="${pwd.hash_algorithm_name}"/>
  79. <property name="hashIterations" value="${pwd.hash_iterations}"/>
  80. <property name="storedCredentialsHexEncoded" value="true"/>
  81. </bean>
  82. <!-- -->
  83. <bean id="userRealm" class="com.goafanti.core.shiro.token.UserRealm" >
  84. <property name="credentialsMatcher" ref="credentialsMatcher"/>
  85. </bean>
  86. <!-- Session Manager -->
  87. <bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
  88. <!-- -->
  89. <property name="sessionValidationInterval" value="1800000"/>
  90. <!-- -->
  91. <property name="globalSessionTimeout" value="1800000"/>
  92. <property name="sessionDAO" ref="customShiroSessionDAO"/>
  93. <!-- session -->
  94. <property name="sessionListeners">
  95. <list>
  96. <ref bean="customSessionListener"/>
  97. </list>
  98. </property>
  99. <!-- -->
  100. <property name="sessionValidationScheduler" ref="sessionValidationScheduler"/>
  101. <!-- -->
  102. <property name="sessionValidationSchedulerEnabled" value="true"/>
  103. <!-- -->
  104. <property name="deleteInvalidSessions" value="true"/>
  105. <!-- -->
  106. <property name="sessionIdCookie" ref="sessionIdCookie"/>
  107. </bean>
  108. <!-- -->
  109. <bean id="jedisShiroSessionRepository" class="com.goafanti.core.shiro.cache.JedisShiroSessionRepository" >
  110. <property name="jedisManager" ref="jedisManager"/>
  111. </bean>
  112. <!--
  113. -->
  114. <!-- -->
  115. <bean id="shiroManager" class="com.goafanti.core.shiro.service.impl.ShiroManagerImpl"/>
  116. <bean id="login" class="com.goafanti.core.shiro.filter.LoginFilter"/>
  117. <bean id="role" class="com.goafanti.core.shiro.filter.RoleFilter"/>
  118. <bean id="permission" class="com.goafanti.core.shiro.filter.PermissionFilter"/>
  119. <bean id="simple" class="com.goafanti.core.shiro.filter.SimpleAuthFilter"/>
  120. <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  121. <property name="securityManager" ref="securityManager" />
  122. <property name="loginUrl" value="/login" />
  123. <property name="successUrl" value="/main" />
  124. <property name="unauthorizedUrl" value="/login" />
  125. <!-- -->
  126. <property name="filterChainDefinitions" value="#{shiroManager.loadFilterChainDefinitions()}"/>
  127. <property name="filters">
  128. <util:map>
  129. <entry key="login" value-ref="login"></entry>
  130. <entry key="role" value-ref="role"></entry>
  131. <entry key="simple" value-ref="simple"></entry>
  132. <entry key="permission" value-ref="permission"></entry>
  133. </util:map>
  134. </property>
  135. </bean>
  136. <!-- -->
  137. <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
  138. </beans>