首页 微博热点 正文

SpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德国际手机版_bv1946

针对cas完成单点登录主要是两个部分,一个部分是client,一个部分是server。关于client,咱们完成的时分需求在自己的项目中引进相应的jar包,然后添加相应的装备,而且完成相应的过滤器即可。而针对server,现在在cas的官网上下载的server都是springmvc的工程,所以主张直接下载运用,而且依据自己的需求进行修正装备,而不主张将server工程修正成springBoot工程。

(1)添加相应的maven依靠

 
org.jasig.cas.client
cas-client-core
3.3.3

(2)在application.properties中添加装备项

#cas config
spring.cas.sign-out-filters=/logout
spring.cas.auth-filters=/*
spring.cas.validate-filters=/*
spring.cas.request-wrapper-filters=/*
spring.cas.assertion-filters=/*
spring.cas.cas-server-login-url=http://loSpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946calhost:8080/login
spring.cas.cas-server-url-prefix=http://localhost:8080
spring.cas.redirect-after-validation=true
spring.cas.use-session=true
spring.cas.server-name=http://localhost:8001

留意上面的spring.cas.cas-server-login-url是登女主播米娜录地址的url,spring.cas.cas-server-url-prefix是登录地址的IP,spring.cas.server-name是添加单点登录服务的IP。

(3)添加cas主动装备项

import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.Arrays;
import java.util.List;

@ConfigurationProperties(prefix = "spring.cas")
public class Spr费玉清姐姐ingCasAutoconfig {

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 redisnackrectAfterValidation = true;

public List getValidateFilters() {
return Arrays.asList(validateFilters.split(separator));
}
public void setValidateFilters(String validateFilters) {
this.validateFilters = validateFilters;
}
public List getSignOutFilters() {
return Arrays.asList(signOutFilters.split(separator));
}
public void setSignOutFilters(String signOutFilters) {
this.signOutFilters = signOutFilters;
}
public List getAuthFilters() {
return Arrays.asList(authFilters.split(separator));
}
public void setAuthFilters(String authFilters) {
this.authFilters = authFilters;
}
public List getAssertionFilters() {
return Arrays.asList(assertionFilters.split(separator));
}
public void setAssertionFilters(String assertionFilters) {
this.assertionFilters = assertionFilters;
}
public List断桥铝门窗价格 getRequestWrapperFilters() {
return Arrays.asList(requestWrapperFilters.split(separator));
}
pub糖块派对lic void setReques炁tWrapperFilters(String requestWrapperFilters) {SpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946
this.requestWrapperFilters = requestWrapperFilters;
}
pSpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946ublic 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.redirectAfterValidat化装小游戏ion = redirectAfterValidation;
}
public boolean isUseSession() {
return useSession;
}
public void setUse七七电视Session(boolean useSession) {
this.useSession = useSession;
}

}

(4)添加需求的过滤器


import org.jasig.cas.client.authentication.Authenticati糠酸莫米松乳膏onFilter;
import org.jasig.cas.client.session.SingleSignOutFilter;
import org.jaSpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946sig.cas.client.session.SingleSignOutHttpSessionListe蝴蝶rozenaner;
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.springfram早年早年有个人爱你好久ework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.官网ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;


@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() {
ServletListenerRegistrationBean listener = new ServletListenerRegistrationBean<>();
listener.setEnabled(casEnabled);
listener.setListener(new SingleSignOutHttpSessionListener());
listener.setOrder(1);
return listener;
}

/**
* 该过滤器用于完成单点登出功用,单点退出装备,一定要放在其他filter之前
*/
@Bean
public FilterRegistrationBean logOutFilter() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
LogoutFilter logoutFilter = new LogoutFilter(autoconfig.getCasServerUrlPrefix() + "/logout?service=" + autoconfig.getServerName(),new SecurityContextLogoutHandler());
filterRegistration.setFilter(logoutFilter);
filterRegistration.setEnabled(casEnabled);
if(autoconfig.getSignOutFilters().size()>0)
filterRegistration.setUrlPatterns(autoconfig.getSignOutFilters());
else
filterRegistration.addUrlPatterns("/logout");
filterRegistration.addInitParameter("casServerUrlPrefix", autoconfig.getCasServerUrlPrefix());
filterRegistration.addInitParameter("serverName", autoconfig.getServerName());
filterRegistration.setOrder(2);
return filterRegistration;
}

/**
* 该过滤器用于完成单点登出功用,单点退出装备,一定要放在其他filter之前
*/
@Bean
public FilterRegistrationBean singleSignOutFilter() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
filterRegistration.setFilter(new SingleSignOutFilter());
filterRegistration.setEnabled(casEnabled);
if(autoconfig.getSignOutFilters().size()>0)
filterRegistration.setUrlPatterns(autoconfig.getSignOutFiltersSpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946());
else
filterRegistration.addUrlPatterns("/*");
filterRegistration.addInitParameter("casServerUrlPrefix", autoconfig.getCasServerUrlPrefix());
filterRegistration.adploicedInitParameter("serverName", autoconfig.getServerName());
filterRegistration.setOrder(3);
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("/*");
//casServerLoginUrl:cas服务的登陆url
filterRegistration.addInitParameter("casServerLoginUrl", autoconfig.getCasServerLoginUrl());
//本项目登录ip+port
filterRegistration.addInitParameter("serverName", autoconfig.getServerName());
f锁屏ilterRegistratio妥布霉素滴眼液n.addInitParameter("useSession", autoconfig.isUseSession()?"true":"false");
filterRegistration.addInitParameter("redirectAfterValidation", autoconfig.isRedirectAfterValidation()?"true":"false");
filterRegistration.setOrder(4);
return filterRegistration;
}

/**
* 该过滤器担任对Ticket的校验作业
*/
@Bean
public FilterRegistrationBean cas20ProxyReceivingTicketValidationFilter() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
Cas20ProxyReceivingTicketValidationFilter cas20ProxyReceivingTicketValidationFilter = new Cas20ProxyReceivingTicketValidationFilter();
cas20ProxyReceivingTicketValidationFilter.setServerName(autoconfig.getServerName());
filterRegistration.setFilter(cas20ProxyReceivingTicketValidationFilter);
filterRegistration.setEnabled(casEnabled);
if(autoconfig.getValidateFilters().size()>0)
filterRegistration.setUrlPatterns(autoconfig.getValidateFilters());
else
filterRegistration.addUrlPatterns("/*");
fSpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946ilterRegistration.addInitParameter("casServeSpringBoot集成化CAS手机客户端-www.betvictor31.com_伟德世界手机版_bv1946rUrlPrefix", autoconfig.getCasServerUrlPrefix());
filterRegistration.addInitParameter("serverName", autoconfig.getServerName());
filterRegistration.setOrder(5);
return filterRegistration;
}


/**
* 该过滤器对HttpServletRequest恳求包装, 可经过HttpServletRequest的getRemoteUser()办法取得登录用户的登录名
*
*/
@Bean
多动症public FilterRegistrationBean httpServletRequestWrapperFilter() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
filterRegistration.setFilter(new HttpServletRequestWrapperFilter());
filt葛尔兹erRegistration.setEnabled(true);
if(autoconfig.getRequestWrapperFilters().size()>0)
filterRegistration.setUrlPatterns(autoconfig.getRequestWrapperFilters());
else
filterRegistration.addUrlPatterns("/login");
filterRegistration.setOrder(6);
return filterRegistration;
}

/**
* 该过滤器使得可以经过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。
比方AssertionHolder.getAssertion().getPrincipal().getName()。
这个类把Assertion信息放在ThreadLocal变量中,这样应用程序不在web层也可以获取到当时登录信息
*/
@Bean
public FilterRegistrationBean assertionThreadLocalFilter() {
FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
filterRegistration.setFilter(new AssertionThreadLocalFilter());
filterRegistratoppo手机价格ion.setEnabled(true);
if(autoconfig.getAssertionFilte猫眼三姐妹rs().size()>0)
filterRegistration.setUrlPatterns(autoconfig.getAssertionFilters());
else
filterRegistration.addUrlPatterns("/*");
filterRegistration.setOrder(7);
return filterRegistration;
}


}

至此就完成了SpringBoot集成cas客户端,具体代码可参阅gitHub地址:springboot-cas client

相关推荐

  • 暂无相关文章