cas client spring boot 配置

spring.mvc.view.prefix=/WEB-INF/page spring.mvc.view.suffix=.jsp server.session.cookie.domain=.castest.com server.session.cookie.path=/ server.port=8081 spring.cas.sign-out-filters=/* spring.cas.auth-filters=/test spring.cas.validate-filters=/test spring.cas.request-wrapper-filters=/* spring.cas.assertion-filters=/* spring.cas.cas-server-login-url=https://cas.castest.com:8443/cas/login spring.cas.cas-server-url-prefix=https://cas.castest.com:8443/cas/ spring.cas.redirect-after-validation=true spring.cas.use-session=true spring.cas.server-name=http://www.zrk1000.com:8081

 

 

 

import java.util.Arrays;
  import java.util.List;
   
  import org.springframework.boot.context.properties.ConfigurationProperties;
   
  @ConfigurationProperties(prefix = "spring.cas")
  public class SpringCasAutoconfig {
   
  static final String separator = ",";
   
  private String validateFilters;
  private String signOutFilters;
  private String authFilters;
  private String assertionFilters;
  private String requestWrapperFilters;
   
  private String casServerUrlPrefix;
  private String casServerLoginUrl;
  private String serverName;
  private boolean useSession = true;
  private boolean redirectAfterValidation = true;
   
  public List<String> getValidateFilters() {
  return Arrays.asList(validateFilters.split(separator));
  }
  public void setValidateFilters(String validateFilters) {
  this.validateFilters = validateFilters;
  }
  public List<String> getSignOutFilters() {
  return Arrays.asList(signOutFilters.split(separator));
  }
  public void setSignOutFilters(String signOutFilters) {
  this.signOutFilters = signOutFilters;
  }
  public List<String> getAuthFilters() {
  return Arrays.asList(authFilters.split(separator));
  }
  public void setAuthFilters(String authFilters) {
  this.authFilters = authFilters;
  }
  public List<String> getAssertionFilters() {
  return Arrays.asList(assertionFilters.split(separator));
  }
  public void setAssertionFilters(String assertionFilters) {
  this.assertionFilters = assertionFilters;
  }
  public List<String> getRequestWrapperFilters() {
  return Arrays.asList(requestWrapperFilters.split(separator));
  }
  public void setRequestWrapperFilters(String requestWrapperFilters) {
  this.requestWrapperFilters = requestWrapperFilters;
  }
  public String getCasServerUrlPrefix() {
  return casServerUrlPrefix;
  }
  public void setCasServerUrlPrefix(String casServerUrlPrefix) {
  this.casServerUrlPrefix = casServerUrlPrefix;
  }
  public String getCasServerLoginUrl() {
  return casServerLoginUrl;
  }
  public void setCasServerLoginUrl(String casServerLoginUrl) {
  this.casServerLoginUrl = casServerLoginUrl;
  }
  public String getServerName() {
  return serverName;
  }
  public void setServerName(String serverName) {
  this.serverName = serverName;
  }
  public boolean isRedirectAfterValidation() {
  return redirectAfterValidation;
  }
  public void setRedirectAfterValidation(boolean redirectAfterValidation) {
  this.redirectAfterValidation = redirectAfterValidation;
  }
  public boolean isUseSession() {
  return useSession;
  }
  public void setUseSession(boolean useSession) {
  this.useSession = useSession;
  }
   
  }

 

 

import org.jasig.cas.client.authentication.AuthenticationFilter;
  import org.jasig.cas.client.session.SingleSignOutFilter;
  import org.jasig.cas.client.session.SingleSignOutHttpSessionListener;
  import org.jasig.cas.client.util.AssertionThreadLocalFilter;
  import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;
  import org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.context.embedded.FilterRegistrationBean;
  import org.springframework.boot.context.embedded.ServletListenerRegistrationBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
   
  import com.zrk1000.cas.autoconfig.SpringCasAutoconfig;
   
  @Configuration
  public class CasConfig {
   
  @Autowired
  SpringCasAutoconfig autoconfig;
   
  private static boolean casEnabled = true;
   
  public CasConfig() {
  }
   
  @Bean
  public SpringCasAutoconfig getSpringCasAutoconfig(){
  return new SpringCasAutoconfig();
  }
   
  @Bean
  public ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> singleSignOutHttpSessionListener() {
  ServletListenerRegistrationBean<SingleSignOutHttpSessionListener> listener = new ServletListenerRegistrationBean<SingleSignOutHttpSessionListener>();
  listener.setEnabled(casEnabled);
  listener.setListener(new SingleSignOutHttpSessionListener());
  listener.setOrder(1);
  return listener;
  }
   
  @Bean
  public FilterRegistrationBean singleSignOutFilter() {
  FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
  filterRegistration.setFilter(new SingleSignOutFilter());
  filterRegistration.setEnabled(casEnabled);
  if(autoconfig.getSignOutFilters().size()>0)
  filterRegistration.setUrlPatterns(autoconfig.getSignOutFilters());
  else
  filterRegistration.addUrlPatterns("/*");
  filterRegistration.addInitParameter("casServerUrlPrefix", autoconfig.getCasServerUrlPrefix());
  filterRegistration.setOrder(2);
  return filterRegistration;
  }
   
  @Bean
  public FilterRegistrationBean authenticationFilter() {
  FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
  filterRegistration.setFilter(new AuthenticationFilter());
  filterRegistration.setEnabled(casEnabled);
  if(autoconfig.getAuthFilters().size()>0)
  filterRegistration.setUrlPatterns(autoconfig.getAuthFilters());
  else
  filterRegistration.addUrlPatterns("/*");
  filterRegistration.addInitParameter("casServerLoginUrl", autoconfig.getCasServerLoginUrl());
  filterRegistration.addInitParameter("serverName", autoconfig.getServerName());
  filterRegistration.addInitParameter("useSession", autoconfig.isUseSession()?"true":"false");
  filterRegistration.addInitParameter("redirectAfterValidation", autoconfig.isRedirectAfterValidation()?"true":"false");
  filterRegistration.setOrder(3);
  return filterRegistration;
  }
   
  @Bean
  public FilterRegistrationBean cas20ProxyReceivingTicketValidationFilter() {
  FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
  filterRegistration.setFilter(new Cas20ProxyReceivingTicketValidationFilter());
  filterRegistration.setEnabled(casEnabled);
  if(autoconfig.getValidateFilters().size()>0)
  filterRegistration.setUrlPatterns(autoconfig.getValidateFilters());
  else
  filterRegistration.addUrlPatterns("/*");
  filterRegistration.addInitParameter("casServerUrlPrefix", autoconfig.getCasServerUrlPrefix());
  filterRegistration.addInitParameter("serverName", autoconfig.getServerName());
  filterRegistration.setOrder(4);
  return filterRegistration;
  }
   
  @Bean
  public FilterRegistrationBean httpServletRequestWrapperFilter() {
  FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
  filterRegistration.setFilter(new HttpServletRequestWrapperFilter());
  filterRegistration.setEnabled(true);
  if(autoconfig.getRequestWrapperFilters().size()>0)
  filterRegistration.setUrlPatterns(autoconfig.getRequestWrapperFilters());
  else
  filterRegistration.addUrlPatterns("/*");
  filterRegistration.setOrder(5);
  return filterRegistration;
  }
   
  @Bean
  public FilterRegistrationBean assertionThreadLocalFilter() {
  FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
  filterRegistration.setFilter(new AssertionThreadLocalFilter());
  filterRegistration.setEnabled(true);
  if(autoconfig.getAssertionFilters().size()>0)
  filterRegistration.setUrlPatterns(autoconfig.getAssertionFilters());
  else
  filterRegistration.addUrlPatterns("/*");
  filterRegistration.setOrder(6);
  return filterRegistration;
  }
  }

 

 

import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.boot.builder.SpringApplicationBuilder;
  import org.springframework.boot.context.web.SpringBootServletInitializer;
  import org.springframework.context.annotation.Import;
   
  import com.zrk1000.cas.config.CasConfig;
   
   
  @Import(CasConfig.class)
  @SpringBootApplication
  public class CasClientBootApplication extends SpringBootServletInitializer{
   
  public static void main(String[] args) {
  SpringApplication.run(CasClientBootApplication.class, args);
  }
   
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  return application.sources(CasClientBootApplication.class);
  }
   
  }
posted @ 2017-10-25 23:18  采姑娘的蘑菇  阅读(4530)  评论(0编辑  收藏  举报