springboot 如何调用cas-client-autoconfig-support 解析ticket

时间: 2023-04-05 22:05:25 浏览: 93
可以使用Spring Security CAS扩展来实现。在pom.xml文件中添加以下依赖项: ``` <dependency> <groupId>org.springframework.security.extensions</groupId> <artifactId>spring-security-cas</artifactId> <version>1.0.7.RELEASE</version> </dependency> ``` 然后在application.properties文件中添加以下配置: ``` # CAS server URL cas.server.url=https://cas.example.com/cas # CAS server login URL cas.server.login.url=https://cas.example.com/cas/login # CAS server logout URL cas.server.logout.url=https://cas.example.com/cas/logout # CAS service URL cas.service.url=http://localhost:8080/login/cas # CAS service name cas.service.name=MyApp # CAS service login URL cas.service.login.url=http://localhost:8080/login # CAS service logout URL cas.service.logout.url=http://localhost:8080/logout # CAS service validate URL cas.service.validate.url=https://cas.example.com/cas/serviceValidate # CAS service ticket parameter name cas.service.ticket.parameterName=ticket # CAS service renew parameter name cas.service.renew.parameterName=renew # CAS service gateway parameter name cas.service.gateway.parameterName=gateway # CAS service artifact parameter name cas.service.artifact.parameterName=artifact # CAS service proxy callback URL cas.service.proxy.callbackUrl=http://localhost:8080/proxyCallback # CAS service proxy callback parameter name cas.service.proxy.callbackParameterName=pgtIou # CAS service proxy granting ticket parameter name cas.service.proxy.grantingTicket.parameterName=pgtIou # CAS service proxy granting ticket storage class cas.service.proxy.grantingTicket.storageClass=org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl # CAS service proxy granting ticket storage file cas.service.proxy.grantingTicket.storageFile=/tmp/cas-proxy-granting-tickets # CAS service proxy granting ticket storage clean interval cas.service.proxy.grantingTicket.storageCleanInterval=3600000 # CAS service proxy granting ticket storage clean up cas.service.proxy.grantingTicket.storageCleanUp=true # CAS service proxy granting ticket storage clean up interval cas.service.proxy.grantingTicket.storageCleanUpInterval=3600000 # CAS service proxy granting ticket storage clean up max age cas.service.proxy.grantingTicket.storageCleanUpMaxAge=7200000 ``` 然后在Spring Boot应用程序中添加以下配置类: ``` @Configuration @EnableWebSecurity @EnableCasSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired private CasAuthenticationEntryPoint casAuthenticationEntryPoint; @Autowired private CasAuthenticationProvider casAuthenticationProvider; @Autowired private SingleSignOutFilter singleSignOutFilter; @Autowired private CasAuthenticationFilter casAuthenticationFilter; @Autowired private CasProperties casProperties; @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/login").permitAll() .anyRequest().authenticated() .and() .exceptionHandling() .authenticationEntryPoint(casAuthenticationEntryPoint) .and() .logout() .logoutUrl("/logout") .logoutSuccessUrl("/") .addLogoutHandler(new SingleSignOutHandler(casProperties.getServer().getLogoutUrl())) .and() .addFilterBefore(singleSignOutFilter, CasAuthenticationFilter.class) .addFilter(casAuthenticationFilter); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.authenticationProvider(casAuthenticationProvider); } @Bean public ServiceProperties serviceProperties() { ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.setService(casProperties.getService().getUrl()); serviceProperties.setSendRenew(false); return serviceProperties; } @Bean public CasAuthenticationEntryPoint casAuthenticationEntryPoint() { CasAuthenticationEntryPoint casAuthenticationEntryPoint = new CasAuthenticationEntryPoint(); casAuthenticationEntryPoint.setLoginUrl(casProperties.getServer().getLoginUrl()); casAuthenticationEntryPoint.setServiceProperties(serviceProperties()); return casAuthenticationEntryPoint; } @Bean public CasAuthenticationProvider casAuthenticationProvider() { CasAuthenticationProvider casAuthenticationProvider = new CasAuthenticationProvider(); casAuthenticationProvider.setAuthenticationUserDetailsService(new UserDetailsServiceImpl()); casAuthenticationProvider.setServiceProperties(serviceProperties()); casAuthenticationProvider.setTicketValidator(new Cas30ServiceTicketValidator(casProperties.getServer().getUrl())); casAuthenticationProvider.setKey("casAuthenticationProviderKey"); return casAuthenticationProvider; } @Bean public SingleSignOutFilter singleSignOutFilter() { SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter(); singleSignOutFilter.setCasServerUrlPrefix(casProperties.getServer().getUrl()); singleSignOutFilter.setIgnoreInitConfiguration(true); return singleSignOutFilter; } @Bean public CasAuthenticationFilter casAuthenticationFilter() { CasAuthenticationFilter casAuthenticationFilter = new CasAuthenticationFilter(); casAuthenticationFilter.setAuthenticationManager(authenticationManager()); casAuthenticationFilter.setFilterProcessesUrl("/login/cas"); return casAuthenticationFilter; } } ``` 最后,在Spring Boot应用程序中添加以下服务类: ``` @Service public class UserDetailsServiceImpl implements AuthenticationUserDetailsService<CasAssertionAuthenticationToken> { @Override public UserDetails loadUserDetails(CasAssertionAuthenticationToken token) throws UsernameNotFoundException { String username = token.getName(); List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList("ROLE_USER"); return new User(username, "", authorities); } } ``` 现在,您可以使用Spring Boot应用程序调用CAS客户端自动配置支持来解析票据。

相关推荐

最新推荐

springboot集成CAS实现单点登录的示例代码

主要介绍了springboot集成CAS实现单点登录的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

spring boot整合CAS Client实现单点登陆验证的示例

本篇文章主要介绍了spring boot整合CAS Client实现单点登陆验证的示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

CAS-PEAL-R1 人脸识别库

已分类的人脸识别库,对深度学习人脸识别有很大帮助,样本数量多,质量好,类别多。我们自己编写的小型算法验证准确率高达90%+,对于入门AI还是很有帮助的。

详解Spring Boot 集成Shiro和CAS

主要介绍了详解Spring Boot 集成Shiro和CAS,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

Shiro+Cas微服务化及前后端完全分离

主要为大家详细介绍了Shiro+Cas微服务化及前后端完全分离,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

stc12c5a60s2 例程

stc12c5a60s2 单片机的所有功能的实例,包括SPI、AD、串口、UCOS-II操作系统的应用。

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire

【迁移学习在车牌识别中的应用优势与局限】: 讨论迁移学习在车牌识别中的应用优势和局限

![【迁移学习在车牌识别中的应用优势与局限】: 讨论迁移学习在车牌识别中的应用优势和局限](https://img-blog.csdnimg.cn/direct/916e743fde554bcaaaf13800d2f0ac25.png) # 1. 介绍迁移学习在车牌识别中的背景 在当今人工智能技术迅速发展的时代,迁移学习作为一种强大的技术手段,在车牌识别领域展现出了巨大的潜力和优势。通过迁移学习,我们能够将在一个领域中学习到的知识和模型迁移到另一个相关领域,从而减少对大量标注数据的需求,提高模型训练效率,加快模型收敛速度。这种方法不仅能够增强模型的泛化能力,提升识别的准确率,还能有效应对数据

margin-top: 50%;

margin-top: 50%; 是一种CSS样式代码,用于设置元素的上边距(即与上方元素或父级元素之间的距离)为其父元素高度的50%。 这意味着元素的上边距将等于其父元素高度的50%。例如,如果父元素的高度为100px,则该元素的上边距将为50px。 请注意,这个值只在父元素具有明确的高度(非auto)时才有效。如果父元素的高度是auto,则无法确定元素的上边距。 希望这个解释对你有帮助!如果你还有其他问题,请随时提问。

Android通过全局变量传递数据

在Activity之间数据传递中还有一种比较实用的方式 就是全局对象 实用J2EE的读者来说都知道Java Web的四个作用域 这四个作用域从小到大分别是Page Request Session和Application 其中Application域在应用程序的任何地方都可以使用和访问 除非是Web服务器停止 Android中的全局对象非常类似于Java Web中的Application域 除非是Android应用程序清除内存 否则全局对象将一直可以访问 1 定义一个类继承Application public class MyApp extends Application 2 在AndroidMainfest xml中加入全局变量 android:name &quot; MyApp&quot; 3 在传数据类中获取全局变量Application对象并设置数据 myApp MyApp getApplication ; myApp setName &quot;jack&quot; ; 修改之后的名称 4 在收数据类中接收Application对象 myApp MyApp getApplication ;">在Activity之间数据传递中还有一种比较实用的方式 就是全局对象 实用J2EE的读者来说都知道Java Web的四个作用域 这四个作用域从小到大分别是Page Request Session和Application 其中Application域在应用程序的任何地方都可以使用和 [更多]