怎么在springboot中利用CASClient实现单点登陆验证
怎么在spring boot中利用CAS Client实现单点登陆验证?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
君山网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联。
CAS Client
负责处理对客户端受保护资源的访问请求,需要对请求方进行身份认证时,重定向到 CAS Server 进行认证。(原则上,客户端应用不再接受任何的用户名密码等 Credentials )。
实现方式一:使用第三方的starter
1、依赖的jar
net.unicon.cas cas-client-autoconfig-support 1.4.0-GA
2、增加配置文件
cas.server-url-prefix=http://127.0.0.1 cas.server-login-url=http://127.0.0.1/login cas.client-host-url=http://192.26.4.28:8080 cas.validation-type=CAS
3、开启CAS Client支持
@SpringBootApplication @ComponentScan(basePackages={"com.chhliu.emailservice"}) @EnableCasClient // 开启CAS支持 public class Application extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
通过上面的3步,就可以完成CAS的客户端认证了!
4、扩展
cas.validation-type目前支持3中方式:1、CAS;2、CAS3;3、SAML
其他可用的配置如下:
cas.authentication-url-patterns cas.validation-url-patterns cas.request-wrapper-url-patterns cas.assertion-thread-local-url-patterns cas.gateway cas.use-session cas.redirect-after-validation cas.allowed-proxy-chains cas.proxy-callback-url cas.proxy-receptor-url cas.accept-any-proxy server.context-parameters.renew
具体的含义从名字上就可以很清楚的看出来。
实现方式二:手动配置
我们原来使用CAS Client,需要在web.xml中做如下配置:
authenticationFilter org.jasig.cas.client.authentication.AuthenticationFilter casServerLoginUrl http://127.0.0.1/login serverName http://192.26.4.28:8080 authenticationFilter /* validationFilter org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter casServerUrlPrefix http://127.0.0.1 serverName http://192.26.4.28:8080 validationFilter /* httpServletRequestWrapperFilter org.jasig.cas.client.util.HttpServletRequestWrapperFilter httpServletRequestWrapperFilter /*
所以,我们手动配置的时候,需要手动配置上面xml中对应的Filter,代码如下:
@Configuration @Component public class CasConfigure { @Bean public FilterRegistrationBean authenticationFilterRegistrationBean() { FilterRegistrationBean authenticationFilter = new FilterRegistrationBean(); authenticationFilter.setFilter(new AuthenticationFilter()); MapinitParameters = new HashMap (); initParameters.put("casServerLoginUrl", "http://127.0.0.1/login"); initParameters.put("serverName", "http://192.26.4.28:8080"); authenticationFilter.setInitParameters(initParameters); authenticationFilter.setOrder(2); List urlPatterns = new ArrayList (); urlPatterns.add("/*");// 设置匹配的url authenticationFilter.setUrlPatterns(urlPatterns); return authenticationFilter; } @Bean public FilterRegistrationBean ValidationFilterRegistrationBean(){ FilterRegistrationBean authenticationFilter = new FilterRegistrationBean(); authenticationFilter.setFilter(new Cas20ProxyReceivingTicketValidationFilter()); Map initParameters = new HashMap (); initParameters.put("casServerUrlPrefix", "http://127.0.0.1"); initParameters.put("serverName", "http://192.26.4.28:8080"); authenticationFilter.setInitParameters(initParameters); authenticationFilter.setOrder(1); List urlPatterns = new ArrayList (); urlPatterns.add("/*");// 设置匹配的url authenticationFilter.setUrlPatterns(urlPatterns); return authenticationFilter; } @Bean public FilterRegistrationBean casHttpServletRequestWrapperFilter(){ FilterRegistrationBean authenticationFilter = new FilterRegistrationBean(); authenticationFilter.setFilter(new HttpServletRequestWrapperFilter()); authenticationFilter.setOrder(3); List urlPatterns = new ArrayList (); urlPatterns.add("/*");// 设置匹配的url authenticationFilter.setUrlPatterns(urlPatterns); return authenticationFilter; } @Bean public FilterRegistrationBean casAssertionThreadLocalFilter(){ FilterRegistrationBean authenticationFilter = new FilterRegistrationBean(); authenticationFilter.setFilter(new AssertionThreadLocalFilter()); authenticationFilter.setOrder(4); List urlPatterns = new ArrayList (); urlPatterns.add("/*");// 设置匹配的url authenticationFilter.setUrlPatterns(urlPatterns); return authenticationFilter; } }
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。
本文名称:怎么在springboot中利用CASClient实现单点登陆验证
标题来源:http://ybzwz.com/article/gisces.html