最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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;
}

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

相關(guān)文章

  • HelloSpringMVC配置版實(shí)現(xiàn)步驟解析

    HelloSpringMVC配置版實(shí)現(xiàn)步驟解析

    這篇文章主要介紹了HelloSpringMVC配置版實(shí)現(xiàn)步驟解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 舉例講解Java編程中this關(guān)鍵字與super關(guān)鍵字的用法

    舉例講解Java編程中this關(guān)鍵字與super關(guān)鍵字的用法

    這篇文章主要介紹了Java編程中this關(guān)鍵字與super關(guān)鍵字的用法示例,super是this的父輩,在繼承過程中兩個(gè)關(guān)鍵字經(jīng)常被用到,需要的朋友可以參考下
    2016-03-03
  • SpringBoot自定義注解及AOP的開發(fā)和使用詳解

    SpringBoot自定義注解及AOP的開發(fā)和使用詳解

    在公司項(xiàng)目中,如果需要做一些公共的功能,如日志等,最好的方式是使用自定義注解,自定義注解可以實(shí)現(xiàn)我們對(duì)想要添加日志的方法上添加,這篇文章基于日志功能來講講自定義注解應(yīng)該如何開發(fā)和使用,需要的朋友可以參考下
    2023-08-08
  • Java Applet查找素?cái)?shù)小程序代碼實(shí)例

    Java Applet查找素?cái)?shù)小程序代碼實(shí)例

    這篇文章主要介紹了Java Applet查找素?cái)?shù)小程序代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • java實(shí)現(xiàn)壓縮字符串和java字符串過濾

    java實(shí)現(xiàn)壓縮字符串和java字符串過濾

    這篇文章主要介紹了java實(shí)現(xiàn)壓縮字符串和java字符串過濾,需要的朋友可以參考下
    2014-04-04
  • Java實(shí)現(xiàn)按權(quán)重隨機(jī)數(shù)

    Java實(shí)現(xiàn)按權(quán)重隨機(jī)數(shù)

    這篇文章主要介紹了Java實(shí)現(xiàn)按權(quán)重隨機(jī)數(shù),本文給出了提出問題、分析問題、解決問題三個(gè)步驟,需要的朋友可以參考下
    2015-04-04
  • 一文梳理Java超大型文件讀取的18種方法和性能

    一文梳理Java超大型文件讀取的18種方法和性能

    這篇文章主要為大家詳細(xì)介紹了Java中超大型文件讀取的18種方法和性能對(duì)比,文中的示例代碼簡(jiǎn)潔易懂,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-02-02
  • SpringCloud實(shí)現(xiàn)基于RabbitMQ消息隊(duì)列的詳細(xì)步驟

    SpringCloud實(shí)現(xiàn)基于RabbitMQ消息隊(duì)列的詳細(xì)步驟

    在Spring Cloud框架中,我們可以利用RabbitMQ實(shí)現(xiàn)強(qiáng)大而可靠的消息隊(duì)列系統(tǒng),本篇將詳細(xì)介紹如何在Spring Cloud項(xiàng)目中集成RabbitMQ,并創(chuàng)建一個(gè)簡(jiǎn)單的消息隊(duì)列,感興趣的朋友一起看看吧
    2024-03-03
  • Java多線程的同步優(yōu)化的6種方案

    Java多線程的同步優(yōu)化的6種方案

    大家使用多線程無非是為了提高性能,在Java中,有多線程并發(fā)時(shí),我們可以使用多線程同步的方式來解決內(nèi)存一致性的問題。本文就詳細(xì)的介紹了Java多線程同步優(yōu)化,感興趣的可以了解一下
    2021-05-05
  • Java中的迭代和遞歸詳解

    Java中的迭代和遞歸詳解

    這篇文章主要給大家介紹了關(guān)于Java中的迭代和遞歸,文章顯示分別介紹了Java中的迭代和遞歸,而后又介紹了迭代和遞歸的區(qū)別以及數(shù)形遞歸的相關(guān)內(nèi)容,文中介紹的很詳細(xì),相信會(huì)對(duì)大家學(xué)習(xí)具有一定的參考借鑒價(jià)值,有需要的朋友們可以參考借鑒。
    2016-11-11

最新評(píng)論

哈巴河县| 福清市| 玉屏| 临潭县| 望城县| 蕲春县| 翼城县| 慈溪市| 正蓝旗| 伊金霍洛旗| 武胜县| 云浮市| 桐梓县| 新绛县| 万山特区| 新源县| 浦城县| 聊城市| 遂川县| 双柏县| 尖扎县| 武夷山市| 聂拉木县| 老河口市| 濮阳县| 曲靖市| 获嘉县| 塔河县| 永登县| 抚州市| 盖州市| 灵台县| 黔西| 涡阳县| 长武县| 竹溪县| 阿勒泰市| 全椒县| 凤阳县| 凌海市| 从化市|