CasFilterConfig.java
Posted 500年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CasFilterConfig.java相关的知识,希望对你有一定的参考价值。
CasFilterConfig.java
import com.webber.cm.conf.CasLoginConfig;
import org.jasig.cas.client.authentication.AuthenticationFilter;
import org.jasig.cas.client.util.AssertionThreadLocalFilter;
import org.jasig.cas.client.util.HttpServletRequestWrapperFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Configuration
public class CasFilterConfig {
private String casServerLoginUrl;
private String service;
@Autowired
CasLoginConfig.CasLogin casLogin;
private boolean enabled;
@PostConstruct
private void init(){
casServerLoginUrl = casLogin.getCasServerLoginUrl();
service = casLogin.getService();
enabled = casLogin.isEnabled();
}
@Bean(name="cASFilterRegistrationBean")
public FilterRegistrationBean<AuthenticationFilter> CASFilterRegistrationBean() {
FilterRegistrationBean<AuthenticationFilter> authenticationFilter = new FilterRegistrationBean<AuthenticationFilter>();
authenticationFilter.setFilter(new AuthenticationFilter());
Map<String, String> initParameters = new HashMap<>();
initParameters.put("casServerLoginUrl", casServerLoginUrl+"/login");
initParameters.put("service", service);
initParameters.put("encoding","UTF-8");
authenticationFilter.setInitParameters(initParameters);
authenticationFilter.setOrder(2);
authenticationFilter.setEnabled(enabled);
List<String> urlPatterns = new ArrayList<>();
urlPatterns.add("/caslogin");// 设置匹配的url
authenticationFilter.setUrlPatterns(urlPatterns);
return authenticationFilter;
}
@Bean(name="casValidationFilterRegistrationBean")
public FilterRegistrationBean<Cas20ProxyReceivingTicketValidationFilter> CASValidationFilterRegistrationBean() {
FilterRegistrationBean<Cas20ProxyReceivingTicketValidationFilter> authenticationFilter = new FilterRegistrationBean<Cas20ProxyReceivingTicketValidationFilter>();
authenticationFilter.setFilter(new Cas20ProxyReceivingTicketValidationFilter());
Map<String, String> initParameters = new HashMap<String, String>();
initParameters.put("casServerUrlPrefix", casServerLoginUrl);
initParameters.put("service", service);
initParameters.put("encoding","UTF-8");
authenticationFilter.setInitParameters(initParameters);
authenticationFilter.setOrder(1);
authenticationFilter.setEnabled(enabled);
List<String> urlPatterns = new ArrayList<String>();
urlPatterns.add("/caslogin");// 设置匹配的url
authenticationFilter.setUrlPatterns(urlPatterns);
return authenticationFilter;
}
@Bean(name="httpServletRequestWrapperBean")
public FilterRegistrationBean<HttpServletRequestWrapperFilter> httpServletRequestWrapperBean() {
FilterRegistrationBean<HttpServletRequestWrapperFilter> filter = new FilterRegistrationBean<HttpServletRequestWrapperFilter>();
filter.setFilter(new HttpServletRequestWrapperFilter());
filter.setOrder(2);
filter.setEnabled(enabled);
List<String> urlPatterns = new ArrayList<>();
urlPatterns.add("/caslogin");// 设置匹配的url
filter.setUrlPatterns(urlPatterns);
return filter;
}
@Bean(name="assertionThreadLocalBean")
public FilterRegistrationBean<AssertionThreadLocalFilter> AssertionThreadLocalBean() {
FilterRegistrationBean<AssertionThreadLocalFilter> filter = new FilterRegistrationBean<AssertionThreadLocalFilter>();
filter.setFilter(new AssertionThreadLocalFilter());
filter.setOrder(2);
filter.setEnabled(enabled);
List<String> urlPatterns = new ArrayList<>();
urlPatterns.add("/caslogin");// 设置匹配的url
filter.setUrlPatterns(urlPatterns);
return filter;
}
}
以上是关于CasFilterConfig.java的主要内容,如果未能解决你的问题,请参考以下文章