亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Spring Security整合CAS的示例代碼

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

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

配置

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服務(wù)地址
cas.url=https://cas.example.com:8443
#CAS客戶端地址,就是本應(yīng)用的地址
client.url=http://localhost:8080

分析

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

為什么不用spring-security-cas

spring-security-cas

在spring-security-cas中負(fù)責(zé)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));
  ...

在構(gòu)建validator的validator方法的第二個(gè)參數(shù)時(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;
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java中List使用stream流轉(zhuǎn)成map的幾種方式詳解

    Java中List使用stream流轉(zhuǎn)成map的幾種方式詳解

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

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

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

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

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

    java對(duì)接微信支付之JSAPI支付(微信公眾號(hào)支付)

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

    解決idea報(bào)錯(cuò) Connot resolve column 的問題

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

    eclipse/intellij idea 遠(yuǎn)程調(diào)試hadoop 2.6.0

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

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

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

    關(guān)于Mybatis插入對(duì)象時(shí)空值的處理

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

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

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

    shiro與spring集成基礎(chǔ)Hello案例詳解

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

最新評(píng)論