这里使用的是spring-security和原生的jasig cas包来进行整合,为什么没有直接使用spring提供的spring-security-cas,后面会进行解释。
配置
web.xml
applicationContext-security.xml
分析
在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。
private CasAuthenticationToken authenticateNow(final Authentication authentication) throws AuthenticationException { try { final Assertion assertion = this.ticketValidator.validate(authentication.getCredentials().toString(), getServiceUrl(authentication)); ...在构建validator的validator方法的第二个参数时
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;}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。