文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

使用spring boot如何实现对CAS进行整合

2023-05-31 14:47

关注

今天就跟大家聊聊有关使用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;   }       @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;   }       @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("   @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("   @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("   @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("   @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;   } } 

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 资料下载
  • 历年真题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯