CAS:Yale 大學發起的一個開源項目,旨在為 Web 應用系統提供一種可靠的單點登錄方法。
Shiro:Apache Shiro是一個Java安全框架,可以幫助我們完成認證、授權、會話管理、加密等,並且提供與web集成、緩存、rememberMed等功能。
*Shiro支持與CAS進行整合使用.
2.CAS Server搭建
參考:https://www.cnblogs.com/funyoung/p/9234947.html
3.CAS Client搭建
3.1 添加Shiro自身以及整合CAS的相關依賴
org.apache.shiro shiro-core 1.4.0 org.apache.shiro shiro-cas 1.4.0
3.2 配置Spring提供的過濾器代理
在web.xml中配置DelegatingFilterProxy並指定targetBeanName。
shiroFilter org.springframework.web.filter.DelegatingFilterProxy targetBeanName shiroFilter shiroFilter /*
*DelegatingFilterProxy是一個標準的Filter代理,通過targetBeanName指定其要代理的Filter的bean的id(默認情況下將代理bean id為filter-name的Filter)
3.2 新增shiro.properties配置文件並設置相關屬性
shiro.loginUrl=http://127.0.0.1:8080/cas/login?service=http://127.0.0.1:8080/A/shiro-casshiro.logoutUrl=http://127.0.0.1:8080/cas/logout?service=http://127.0.0.1:8080/A/shiro-casshiro.cas.serverUrlPrefix=http://127.0.0.1:8080/casshiro.cas.service=http://127.0.0.1:8080/A/shiro-casshiro.successUrl=http://127.0.0.1:8081/front/indexshiro.failureUrl=http://127.0.0.1:8081/front/index
*在spring-shiro.xml中需要使用到此文件的配置項.
3.3 創建自定義的CasRealm
*Shiro為了與CAS進行整合,提供了CasRealm實現類,其已經對AuthozingRealm抽象類
【本文地址】