Aqui, usamos a segurança da primavera e o pacote nativo Jasig Cas para integração. Por que a primavera-segurança é fornecida pela primavera não usada diretamente? Será explicado mais tarde.
Configuração
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> <lirer-class> org.jasig.cas.client.session.singLeSignouthttpSessionListener </lirer-class> </suvier>
ApplicationContext-security.xml
<? xml versão = "1.0" coding = "utf-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http:/wwww.w3 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. http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <bean id =" CasfilterChain "> <frutor-arg> Filters = "SingleSignoutFilter, Cas20ProxyReCeiveticketValidationFilter, AuthenticationFilter, HttpServletRequestWrapperFilter, AssertionThreadLocalfilter"/> </til: list> </frutructor-arg> </40i> <Bean Id => " id = "Cas20ProxyReCeiveticketValidationFilter"> <propriedade name = "servername" value = "$ {client.url}"/> <propriedade name = "ticketValidator" ref = "cas20ServiceticketValidator"/> </bean> <bean id = "cass20Servicticketvalidador"/> </bean> <bean = "Cas20- value = "$ {Cas.url}"/> <propriedade name = "renow" value = "false"/> </bean> <bean id = "autenticationfilter"> <names name = "renow" value = "false"/> <names name = "casserverlogurl" = "$" {Cas.url} "/> <bemerl}/" name "/" </bean> <bean id = "httpServletRequestwrapperFilter"/> <bean id = "assertionThreadLocalfilter"/> </ Beans> Propriedades
#CAS Serviço Endereço Cas.url = https: //cas.example.com: 8443#CAS O endereço do cliente é o endereço deste aplicativo client.url = http: // localhost: 8080
analisar
Na cadeia de filtro de segurança em ApplicationContext-security.xml, usamos 5 filtros, a saber: SingleSignOutFilter, Cas20ProxyReCeiveticketValidationFilter, AuthenticationFilter, HttpServErquestWrapperFilter e AssertionThreadLocalFilter.
Por que não usar o cas de segurança da primavera
Spring-Segurança-Cas
O filtro de validador de ingressos responsável no Spring-Security-Cas é o org.springframework.security.cas.authentication.casauthenticationProvider.
private CasauthenticationToken AuthenticatENow (autenticação final Autenticação) lança autenticaçãoException {Try {final Assertion Assertion = this.TicketValidator.validate (autenticação.getCredentials (). tostring (), getServiceurl (autenticação)); ...Ao construir o segundo parâmetro do método do validador do validador
private string getServiceurl (autenticação de autenticação) {string serviceUrl; if (autenticação.getDetails () instância de serviceAuthenticationDetails) {serviceUrl = ((serviceauthenticationDetails) autenticação.getDetails ()). getServiceurl (); } else if (ServiceProperties == NULL) {THROW NOVA ILGLELGALSTATEEXCECTION ("ServiceProperties não pode ser nulo, a menos que a autenticação.getDetails () implementa o serviceAuthenticationDetails."); } else if (ServiceProperties.getService () == null) {tire new ilegalStateException ("ServiceProperties.getService () não pode ser nulo, a menos que a autenticação.getDetails () implementa serviceauthenticationDetails."); } else {serviceUrl = serviceProperties.getService (); } if (logger.isdebugenabled ()) {Logger.debug ("ServiceUrl ="+ServiceUrl); } Retornar ServiceUrl;}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.