今天就跟大家聊聊有关使用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?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
软考中级精品资料免费领
- 历年真题答案解析
- 备考技巧名师总结
- 高频考点精准押题
- 资料下载
- 历年真题
193.9 KB下载数265
191.63 KB下载数245
143.91 KB下载数1148
183.71 KB下载数642
644.84 KB下载数2756
相关文章
发现更多好内容猜你喜欢
AI推送时光机使用spring boot如何实现对CAS进行整合
后端开发2023-05-31
使用spring boot如何实现对Swagger2进行整合
后端开发2023-05-31
使用spring boot如何实现对RabbitMQ进行整合
后端开发2023-05-31
使用Spring Boot如何实现对MongoDB进行整合
后端开发2023-05-31
使用Spring Boot如何对Mybatis进行整合
后端开发2023-05-31
使用Spring Boot如何实现对MyBatis的整合
后端开发2023-05-31
使用Spring boot怎么对Mybatis进行整合
后端开发2023-05-31
spring boot如何实现对RabbitMQ整合
后端开发2023-05-31
使用MongoDB如何对Spring进行整合
后端开发2023-05-31
使用Spring boot如何实现对Mybatis进行集成
后端开发2023-05-31
使用Spring Boot实现对RabbitMQ整合的方法
后端开发2023-05-31
使用spring如何对cxf框架进行整合
后端开发2023-05-31
使用springboot如何实现对freemarker进行整合
后端开发2023-05-31
使用springboot如何实现对 beatlsql进行整合
后端开发2023-05-31
使用spring如何实现springmvc与mybatis进行整合
后端开发2023-05-31
使用springboot如何实现对mongodb进行整合
后端开发2023-05-31
使用SpringBoot如何实现对ElasticSearch进行整合
后端开发2023-05-31
咦!没有更多了?去看看其它编程学习网 内容吧