applicationContext-shiro.xml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  4. xmlns:context="http://www.springframework.org/schema/context" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  5. xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:util="http://www.springframework.org/schema/util"
  6. xsi:schemaLocation="
  7. http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  8. http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
  9. http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
  10. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
  11. http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
  12. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
  13. http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
  14. default-lazy-init="true">
  15. <description>xtframe Security Configuration</description>
  16. <context:property-placeholder
  17. ignore-resource-not-found="true" location="classpath*:spring/application.properties" />
  18. <!-- Shiro's main business-tier object for web-enabled applications -->
  19. <!-- 配置权限管理器-->
  20. <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager" depends-on="">
  21. <property name="authenticator" ref="authenticator" /><!-- 缓存管理器 -->
  22. <property name="realms">
  23. <list>
  24. <ref bean="customRealm"/>
  25. <ref bean="casRealm"/>
  26. </list>
  27. </property>
  28. <property name="cacheManager" ref="cacheManager" /><!-- 缓存管理器 -->
  29. </bean>
  30. <!-- 认证策略 -->
  31. <bean id="authenticator" class="org.apache.shiro.authc.pam.ModularRealmAuthenticator">
  32. <property name="authenticationStrategy">
  33. <bean class="org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy" />
  34. </property>
  35. </bean>
  36. <!-- 加密方式 -->
  37. <bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
  38. <property name="hashAlgorithmName" value="SHA-256" />
  39. </bean>
  40. <!-- 项目自定义的Realm -->
  41. <bean id="customRealm" factory-bean="securityContext" factory-method="getRealm">
  42. <constructor-arg name="credentialsMatcher" ref="credentialsMatcher" />
  43. </bean>
  44. <!-- 项目自定义的单点登录Realm -->
  45. <bean id="casRealm" factory-bean="securityContext" factory-method="getCasRealm">
  46. <property name="casServerUrlPrefix" value="http://${cas.serverIp}:${cas.serverPort}/znjg/" />
  47. <!--客户端的回调地址设置,必须和上面的shiro-cas过滤器拦截的地址一致 -->
  48. <property name="casService" value="http://${cas.localIp}:${cas.localPort}/jsjy/shiro-cas/"/>
  49. </bean>
  50. <!-- Shiro Filter -->
  51. <bean id="myFilter" class="com.xtframe.sec.common.CaptchaFormAuthenticationFilter" >
  52. <property name="loginUrl" value="/login" />
  53. <property name="successUrl" value="/main" />
  54. </bean>
  55. <!-- 单点登录的filter -->
  56. <bean id="casfilter" factory-bean="securityContext" factory-method="getCasFilter" >
  57. <property name="loginUrl" value="http://${cas.serverIp}:${cas.serverPort}/znjg?service=http://${cas.localIp}:${cas.localPort}/jsjy/shiro-cas/" />
  58. <property name="successUrl" value="/main" />
  59. <property name="failureUrl" value="/error/404.jsp" />
  60. </bean>
  61. <bean id="ssologout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
  62. <property name="redirectUrl" value="http://${cas.serverIp}:${cas.serverPort}/znjg/logout?service=http://${cas.localIp}:${cas.localPort}/jsjy/shiro-cas"/>
  63. </bean>
  64. <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
  65. <property name="securityManager" ref="securityManager" />
  66. <property name="filters">
  67. <map>
  68. <entry key="authc" value-ref="myFilter" />
  69. <entry key="casfilter" value-ref="casfilter"/><!-- sso的filter -->
  70. <entry key="ssologout" value-ref="ssologout"/><!-- sso的filter -->
  71. </map>
  72. </property>
  73. <property name="filterChainDefinitions">
  74. <value>
  75. /favicon.ico = anon
  76. /ssologout = ssologout
  77. /logout = logout
  78. /static/** = anon
  79. /error/** = anon
  80. /yzm=anon
  81. /services/** = anon
  82. /xkzfz/viewWhfzList = anon
  83. /xkzfz/getFileList = anon
  84. /xkzxx/viewxkzList = anon
  85. /xkzxx/getFileList = anon
  86. /shiro-cas/** = casfilter
  87. /**=authc
  88. <!-- 所有请求都要通过登录验证,未登录就跳转到登录页面 -->
  89. </value>
  90. </property>
  91. </bean>
  92. <!-- 用户授权信息Cache -->
  93. <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" />
  94. <!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
  95. <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
  96. <bean class="com.xtframe.web.authz.AuthorizationAttributeSourceAdvisor">
  97. <property name="securityManager" ref="securityManager" />
  98. </bean>
  99. </beans>