91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用spring boot如何實現對CAS進行整合

發布時間:2020-11-19 16:17:06 來源:億速云 閱讀:535 作者:Leah 欄目:編程語言

今天就跟大家聊聊有關使用spring boot如何實現對CAS進行整合,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。

代碼整合cas的重要過程

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.jasig.cas.client.validation.Cas20ServiceTicketValidator; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.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.cas.ServiceProperties; 
import org.springframework.security.cas.authentication.CasAuthenticationProvider; 
import org.springframework.security.cas.userdetails.GrantedAuthorityFromAssertionAttributesUserDetailsService; 
import org.springframework.security.web.authentication.logout.LogoutFilter; 
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; 
 
import java.util.List; 
 
 
@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<>(); 
    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&#63;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.getSignOutFilters()); 
    else 
      filterRegistration.addUrlPatterns("/*"); 
    filterRegistration.addInitParameter("casServerUrlPrefix", autoconfig.getCasServerUrlPrefix()); 
    filterRegistration.addInitParameter("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()); 
    filterRegistration.addInitParameter("useSession", autoconfig.isUseSession()&#63;"true":"false"); 
    filterRegistration.addInitParameter("redirectAfterValidation", autoconfig.isRedirectAfterValidation()&#63;"true":"false"); 
    filterRegistration.setOrder(4); 
    return filterRegistration; 
  } 
 
  /** 
   * 該過濾器負責對Ticket的校驗工作 
   */ 
  @Bean 
  public FilterRegistrationBean cas20ProxyReceivingTicketValidationFilter() { 
    FilterRegistrationBean filterRegistration = new FilterRegistrationBean(); 
    Cas20ProxyReceivingTicketValidationFilter cas20ProxyReceivingTicketValidationFilter = new Cas20ProxyReceivingTicketValidationFilter(); 
    //cas20ProxyReceivingTicketValidationFilter.setTicketValidator(cas20ServiceTicketValidator()); 
    cas20ProxyReceivingTicketValidationFilter.setServerName(autoconfig.getServerName()); 
    filterRegistration.setFilter(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(5); 
    return filterRegistration; 
  } 
 
 
  /** 
   * 該過濾器對HttpServletRequest請求包裝, 可通過HttpServletRequest的getRemoteUser()方法獲得登錄用戶的登錄名 
   * 
   */ 
  @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(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()); 
    filterRegistration.setEnabled(true); 
    if(autoconfig.getAssertionFilters().size()>0) 
      filterRegistration.setUrlPatterns(autoconfig.getAssertionFilters()); 
    else 
      filterRegistration.addUrlPatterns("/*"); 
    filterRegistration.setOrder(7); 
    return filterRegistration; 
  } 
} 

2.為了讓你們更省力且直接的看到效果,我把相關配置也貼出來

import org.springframework.boot.context.properties.ConfigurationProperties; 
import org.springframework.context.annotation.Configuration; 
 
import java.util.Arrays; 
import java.util.List; 
 
@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; 
  } 
 
} 

3.配置文件  dev.yml

  #cas client config 
  spring:cas: 
  sign-out-filters: /logout 
  auth-filters: /* 
  validate-filters: /* 
  request-wrapper-filters: /* 
  assertion-filters: /* 
  cas-server-login-url: cas登錄url 
  cas-server-url-prefix:cas登錄域名 
  redirect-after-validation: true 
  use-session: true 
  server-name: http://localhost:8080

看完上述內容,你們對使用spring boot如何實現對CAS進行整合有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

象山县| 滦南县| 鞍山市| 武强县| 天台县| 冕宁县| 黎平县| 基隆市| 左权县| 唐山市| 尼勒克县| 晋宁县| 田东县| 开封市| 周口市| 额尔古纳市| 天峻县| 金华市| 白银市| 斗六市| 广东省| 漾濞| 溧水县| 文昌市| 呼图壁县| 巴里| 民丰县| 乌拉特中旗| 永新县| 攀枝花市| 镇雄县| 绥阳县| 阳山县| 莲花县| 翁牛特旗| 长春市| 海兴县| 霍林郭勒市| 桦南县| 陇西县| 上栗县|