欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring Security整合CAS的示例代碼

 更新時間:2018年07月06日 16:25:42   作者:亂世浮生  
本篇文章主要介紹了Spring Security整合CAS的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

這里使用的是spring-security和原生的jasig cas包來進行整合,為什么沒有直接使用spring提供的spring-security-cas,后面會進行解釋。

配置

web.xml

<filter>
 <filter-name>casFilterChain</filter-name>
 <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
 <filter-name>casFilterChain</filter-name>
 <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
 <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
</listener>

applicationContext-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:security="http://www.springframework.org/schema/security"
  xmlns:util="http://www.springframework.org/schema/util"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/security
  http://www.springframework.org/schema/security/spring-security-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

 <bean id="casFilterChain" class="org.springframework.security.web.FilterChainProxy">
  <constructor-arg>
   <util:list>
    <security:filter-chain pattern="/**" filters="singleSignOutFilter, cas20ProxyReceivingTicketValidationFilter, authenticationFilter, httpServletRequestWrapperFilter, assertionThreadLocalFilter"/>
   </util:list>
  </constructor-arg>
 </bean>

 <bean id="singleSignOutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter"/>

 <bean id="cas20ProxyReceivingTicketValidationFilter"
   class="org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter">
  <property name="serverName" value="${client.url}"/>
  <property name="ticketValidator" ref="cas20ServiceTicketValidator"/>
 </bean>

 <bean id="cas20ServiceTicketValidator" class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
  <constructor-arg value="${cas.url}"/>
  <property name="renew" value="false"/>
 </bean>

 <bean id="authenticationFilter" class="org.jasig.cas.client.authentication.AuthenticationFilter">
  <property name="renew" value="false"/>
  <property name="casServerLoginUrl" value="${cas.url}"/>
  <property name="serverName" value="${client.url}"/>
 </bean>

 <bean id="httpServletRequestWrapperFilter" class="org.jasig.cas.client.util.HttpServletRequestWrapperFilter"/>

 <bean id="assertionThreadLocalFilter" class="org.jasig.cas.client.util.AssertionThreadLocalFilter"/>

</beans>

properties

#CAS服務地址
cas.url=https://cas.example.com:8443
#CAS客戶端地址,就是本應用的地址
client.url=http://localhost:8080

分析

在applicationContext-security.xml中的security filter chain中,我們使用了5個filter,分別是:singleSignOutFilter、cas20ProxyReceivingTicketValidationFilter、authenticationFilter、httpServletRequestWrapperFilter、assertionThreadLocalFilter。

為什么不用spring-security-cas

spring-security-cas

在spring-security-cas中負責ticket validator filter使用的是org.springframework.security.cas.authentication.CasAuthenticationProvider。

private CasAuthenticationToken authenticateNow(final Authentication authentication) throws AuthenticationException {
 try {
  final Assertion assertion = this.ticketValidator.validate(authentication.getCredentials().toString(), getServiceUrl(authentication));
  ...

在構建validator的validator方法的第二個參數(shù)時

private String getServiceUrl(Authentication authentication) {
 String serviceUrl;
 if(authentication.getDetails() instanceof ServiceAuthenticationDetails) {
  serviceUrl = ((ServiceAuthenticationDetails)authentication.getDetails()).getServiceUrl();
 }else if(serviceProperties == null){
  throw new IllegalStateException("serviceProperties cannot be null unless Authentication.getDetails() implements ServiceAuthenticationDetails.");
 }else if(serviceProperties.getService() == null){
  throw new IllegalStateException("serviceProperties.getService() cannot be null unless Authentication.getDetails() implements ServiceAuthenticationDetails.");
 }else {
  serviceUrl = serviceProperties.getService();
 }
 if(logger.isDebugEnabled()) {
  logger.debug("serviceUrl = "+serviceUrl);
 }
 return serviceUrl;
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Java中List使用stream流轉成map的幾種方式詳解

    Java中List使用stream流轉成map的幾種方式詳解

    Stream是Java8中處理集合的關鍵抽象概念,它可以指定你希望對集合進行的操作,可以執(zhí)行非常復雜的查找、過濾和映射數(shù)據等操作,下面這篇文章主要給大家介紹了關于Java中List使用stream流轉成map的幾種方式,需要的朋友可以參考下
    2023-04-04
  • Java面試題沖刺第二十三天--分布式

    Java面試題沖刺第二十三天--分布式

    這篇文章主要為大家分享了最有價值的三道關于分布式的面試題,涵蓋內容全面,包括數(shù)據結構和算法相關的題目、經典面試編程題等,感興趣的小伙伴們可以參考一下
    2021-08-08
  • springsecurity輕松實現(xiàn)角色權限的示例代碼

    springsecurity輕松實現(xiàn)角色權限的示例代碼

    這篇文章主要介紹了springsecurity輕松實現(xiàn)角色權限的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-03-03
  • java對接微信支付之JSAPI支付(微信公眾號支付)

    java對接微信支付之JSAPI支付(微信公眾號支付)

    這篇文章主要給大家介紹了關于java對接微信支付之JSAPI支付(微信公眾號支付)的相關資料,微信JSAPI支付是近年來非常流行的一種支付方式,它使用了微信支付的SDK和demo來實現(xiàn)支付接口的對接,需要的朋友可以參考下
    2023-07-07
  • 解決idea報錯 Connot resolve column 的問題

    解決idea報錯 Connot resolve column 的問題

    這篇文章主要介紹了解決idea報錯 Connot resolve column 的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-02-02
  • eclipse/intellij idea 遠程調試hadoop 2.6.0

    eclipse/intellij idea 遠程調試hadoop 2.6.0

    這篇文章主要介紹了eclipse/intellij idea 遠程調試hadoop 2.6.0的相關資料,需要的朋友可以參考下
    2016-07-07
  • 詳解如何在SpringBoot中優(yōu)雅地重試調用第三方API

    詳解如何在SpringBoot中優(yōu)雅地重試調用第三方API

    在實際的應用中,我們經常需要調用第三方API來獲取數(shù)據或執(zhí)行某些操作,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2023-12-12
  • 關于Mybatis插入對象時空值的處理

    關于Mybatis插入對象時空值的處理

    這篇文章主要介紹了關于Mybatis插入對象時空值的處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • springboot發(fā)布dubbo服務注冊到nacos實現(xiàn)方式

    springboot發(fā)布dubbo服務注冊到nacos實現(xiàn)方式

    這篇文章主要介紹了springboot發(fā)布dubbo服務注冊到nacos實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • shiro與spring集成基礎Hello案例詳解

    shiro與spring集成基礎Hello案例詳解

    這篇文章主要介紹了shiro與spring集成基礎Hello案例詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-11-11

最新評論