Ici, nous utilisons Spring-Security et le package Jasig CAS natif pour l'intégration. Pourquoi le printemps-sécurité-Cas est-il fourni par le printemps n'est pas utilisé directement? Il sera expliqué plus tard.
Configuration
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-potern> / * </ url-potern> </filter-mapping> <disener> <écouteur-classe> org.jasig.cas.client.sses.SingleSignouthTTSSessionListener </ auteur-cllass> </ounerner>
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: schemalation = "http://www.spring http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-serurity-3..xsdd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <bean id =" Casfilterchain "> <constructor-arg> <util: list> <Security: filter-chain Pattern =" / ** " filters = "singleSignoutFilter, cas20proxyreceiveTticketValidationFilter, AuthenticationFilter, httpservletRequestwrapperFilter, assertionThreadLocalFilter" /> <util: list> </ Constructor-arg> </ bean> <bean id = "singleSignoutfilter" /> <ean id = "Cas20ProxyReceiveTticketValidationFilter"> <propriété name = "servername" value = "$ {client.url}" /> <propriété name = "ticketvalidator" ref = "Cas20ServiceTticketValidator" /> </ bean> <bean id = "CAS20SERCETICKETVALIDATO Value = "$ {Cas.url}" /> <propriété name = "renouvellement" value = "false" /> </ bean> <bean id = "AuthenticationFilter"> <propriété name = "renouvellement" value = "false" /> <propriété name = "CasserverLoginUrl" Value = "$ {Cas.url}" /> <propriété = "Servername" Value = "$ {Client}" /> <pEPn name = " <bean id = "httpservletRequestwrapperFilter" /> <bean id = "AssertionThreadLocalFilter" /> </ beans> Propriétés
#CAS Adresse du service Cas.url = https: //cas.example.com: 8443 # L'adresse client CAS est l'adresse de cette application client.url = http: // localhost: 8080
analyser
Dans la chaîne de filtre de sécurité dans ApplicationContext-Security.xml, nous utilisons 5 filtres, à savoir: singleSignoutFilter, CAS20ProxyreceiveTticketValidationFilter, AuthenticationFilter, httpservlequestwrapperfilter et assertionthreadLocalFilter.
Pourquoi ne pas utiliser le printemps-sécurité-Cas
Spring-Security-Cas
Le filtre de validateur de billets responsable dans Spring-Security-Cas est le org.springframework.security.cas.authentication.casauthenticationprovider.
Private CasauthenticationToken AuthenticaTenow (authentification finale Authentification) lève AuthenticationException {Try {Final Assertion Assertion = this.TicketValidator.Validate (Authentication.getCredentials (). ToString (), getServiceUrl (Authentication)); ...Lors de la construction du deuxième paramètre de la méthode Validator du validateur
String privé getServiceUrl (authentification authentification) {String ServiceUrl; if (authentication.getdetails () instanceof ServiceAuthenticationDetails) {serviceUrl = ((ServiceAuthenticationDetails) authentication.getDetails ()). getServiceUrl (); } else if (ServiceProperties == null) {Throw New illégalStateException ("ServiceProperties ne peut pas être null à moins qu'Authentication.getDetails () implémente des services de service."); } else if (ServiceProperties.getService () == null) {Throw New illégalStateException ("ServiceProperties.getService () ne peut pas être null à moins qu'Authentication.getDetails () implémente des services de service.");); } else {ServiceUrl = ServiceProperties.getService (); } if (logger.isdebugeNabled ()) {logger.debug ("serviceUrl =" + serviceUrl); } return serviceUrl;}Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.