ที่นี่เราใช้ความปลอดภัยในฤดูใบไม้ผลิและแพ็คเกจ Jasig CAS ดั้งเดิมสำหรับการรวม เหตุใด Spring-Security-CAS จึงไม่ได้ใช้ในฤดูใบไม้ผลิโดยตรง? มันจะถูกอธิบายในภายหลัง
การกำหนดค่า
web.xml
<silter> <filter-name> casfilterchain </filter-name> <filter-class> org.springframework.web.filter.delegatingFilterproxy </filter-class> </filter> <url-pattern>/*</url-pattern> </filter-mapping> <ผู้ฟัง> <Sistener-Lass> org.jasig.cas.client.session.singlesignouthttpsessionListener </listener-class> </listener>
ApplicationContext-security.xml
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://ww.w3.org/2001/xml xmlns: ความปลอดภัย = "http://www.springframework.org/schema/security" xmlns: util = "http://www.springframework.org/schema/util" xsi: schemalocation = "http:/ http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/Security http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <bean id =" casfilterchain "> ตัวกรอง = "SinglesignoutFilter, cas20proxyreceiveticketValidationFilter, AuthenticationFilter, httpservletrequestwrapperfilter, assertionthreadlocalfilter"/> </util: รายการ> id = "cas20proxyreceiveticketValidationFilter"> <property name = "servername" value = "$ {client.url}"/> <property name = "TicketValidator" ref = "cas20serviceticketValidator"/> </epean> value = "$ {cas.url}"/> <property name = "Renew" value = "false"/> </epean> <bean id = "AuthenticationFilter"> <property name = "reprange" value = "false"/> <property name = "casserverLoginurl" value = "$ {cas.url}" </ebean> <bean id = "httpservletrequestwrapperfilter"/> <bean id = "assertionthreadlocalfilter"/> </epe คุณสมบัติ
#CAS ที่อยู่บริการ cas.url = https: //cas.example.com: 8443#ที่อยู่ไคลเอนต์ CAS เป็นที่อยู่ของแอปพลิเคชันไคลเอนต์นี้ url = http: // localhost: 8080
วิเคราะห์
ในห่วงโซ่ตัวกรองความปลอดภัยใน ApplicationContext-security.xml เราใช้ 5 ตัวกรองคือ: SinglesignoutFilter, Cas20ProxyreceVeticketValidationFilter, AuthenticationFilter
ทำไมไม่ใช้ Spring-Security-CAS
ฤดูใบไม้ผลิความปลอดภัย -CAS
ตัวกรองการตรวจสอบตั๋วที่รับผิดชอบใน Spring-Security-CAS คือ org.springframework.security.cas.authentication.casauthenticationprovider
CasauthenticationToken ส่วนตัว Authenticatenow (การรับรองความถูกต้องการรับรองความถูกต้องขั้นสุดท้าย) พ่น AuthenticationException {ลอง {การยืนยันการยืนยันขั้นสุดท้าย = this.ticketValidator.validate (Authentication.getCredentials () ToString () -เมื่อสร้างพารามิเตอร์ที่สองของวิธีการตรวจสอบความถูกต้องของตัวตรวจสอบ
สตริงส่วนตัว getServiceUrl (การรับรองความถูกต้องการรับรองความถูกต้อง) {String ServiceUrl; if (Authentication.getDetails () Instanceof ServiceAuthenticationDetails) {serviceUrl = ((serviceAuthenticationDetails) Authentication.getDetails ()). getServiceUrl (); } อื่นถ้า (serviceProperties == null) {โยน unlueLstateException ใหม่ ("ServiceProperties ไม่สามารถเป็นโมฆะได้เว้นแต่การรับรองความถูกต้อง getDetails () ใช้ ServiceAuthenticationDetails"); } อื่นถ้า (ServiceProperties.getService () == null) {โยนใหม่ legenalStateException ("ServiceProperties.getService () ไม่สามารถเป็นโมฆะเว้นแต่การตรวจสอบสิทธิ์ getDetails () ใช้ serviceAuthenticationDetails"); } else {serviceUrl = serviceProperties.getService (); } if (logger.isdebugenabled ()) {logger.debug ("serviceUrl ="+serviceUrl); } return serviceUrl;}ข้างต้นเป็นเนื้อหาทั้งหมดของบทความนี้ ฉันหวังว่ามันจะเป็นประโยชน์ต่อการเรียนรู้ของทุกคนและฉันหวังว่าทุกคนจะสนับสนุน wulin.com มากขึ้น