激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - Spring Security整合CAS的示例代碼

Spring Security整合CAS的示例代碼

2021-05-13 12:01亂世浮生 Java教程

本篇文章主要介紹了Spring Security整合CAS的示例代碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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

配置

web.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
<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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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

?
1
2
3
4
#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。

?
1
2
3
4
private casauthenticationtoken authenticatenow(final authentication authentication) throws authenticationexception {
 try {
  final assertion assertion = this.ticketvalidator.validate(authentication.getcredentials().tostring(), getserviceurl(authentication));
  ...

在構建validator的validator方法的第二個參數時

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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;
}

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

原文鏈接:http://atbug.com/spring-security-integrated-with-cas/

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美一级片一区 | 国产一区二区三区四区精 | 永久免费不卡在线观看黄网站 | 国产精品99久久久久久宅女 | 91嫩草丨国产丨精品入口 | 欧美一级鲁丝片免费看 | 北条麻菲| av电影在线免费 | 一道本不卡一区 | 一级黄色影院 | 久久久久久久久久亚洲 | 久久久久中精品中文字幕19 | 亚洲精品一区中文字幕 | 一级毛片电影网 | 国产精品亚洲一区二区三区久久 | 亚洲欧美在线看 | 欧美成人精品一区二区三区 | h视频免费观看 | 99精品国产成人一区二区 | 深夜影院a | 国产一区精品视频 | av手机在线电影 | av懂色| 污黄视频在线播放 | 一级黄色影片在线观看 | 亚洲精品v天堂中文字幕 | 毛片视频网址 | 色女孩网| 成人精品一区二区三区中文字幕 | 免费激情网站 | 在线 日本 制服 中文 欧美 | 日韩精品中文字幕一区 | 久久精品视频免费 | 综合精品一区 | 国产精品区一区二区三区 | 欧美一级黄色免费看 | 97色在线观看免费视频 | 成片免费观看视频大全 | 欧美xxxxx视频| 欧美日韩国产成人在线 | 99久久久国产精品露出 |