900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > springboot 实现cas单点登录

springboot 实现cas单点登录

时间:2024-04-29 21:37:49

相关推荐

springboot 实现cas单点登录

一、部署服务端

我这边部署的是cas-server5.2

cas-server:/apereo/cas-overlay-template

cas documenthttps://apereo.github.io/cas/5.2.x/index.html

源代码:/wwwzhouzy/zhouzy-cas

1、构建

下载后解压如图:

构建,我的是windows,用build.cmd

也可以直接从/artifact/org.apereo.cas/cas-server-webapp-tomcatmaven库中下载服务端war包

2、war包部署

下载后重命名cas-server.war放入tomcat8中,只有tomcat8以上版本支持,7.0是不支持的

解压后需要修改一些配置文件:

application.properties加入一些配置

cas.tgc.secure=false

cas.serviceRegistry.initFromJson=true

修改services\HTTPSandIMAPS-10000001.json

找到serviceId让它支持http如图,默认是https,这个需要keytools工具先生成证书:

重新打成war包,运行

启动成功

访问:

http://localhost:8080/cas-server/login

application.properties文件中找到用户名密码:

登录 成功

二、客户端测试

1、客户端引pom文件,记住要jdk1.8版本

<dependency><groupId>org.jasig.cas.client</groupId><artifactId>cas-client-core</artifactId><version>3.4.1</version></dependency>

application.properties

cas.server-url-prefix=http://localhost:8080/cas-servercas.server-login-url=http://localhost:8080/cas-server/logincas.client-host-url=http://localhost:9002cas.use-session=truecas.validation-type=casserver.port=9002casClientLogoutUrl=http://localhost:8080/cas-server/logout?service=http://localhost:9002/logout/success

启动:

package com.oumuv.cas;import net.unicon.cas.client.configuration.EnableCasClient;import org.jasig.cas.client.authentication.AuthenticationFilter;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.web.servlet.FilterRegistrationBean;import org.springframework.context.annotation.Bean;import java.util.HashMap;import java.util.Map;@SpringBootApplication@EnableCasClient//启用cas clientpublic class CasApplication {public static void main(String[] args) {SpringApplication.run(CasApplication.class, args);}}

访问:localhost:9002/hello 因为没有登录跳转到cas服务端去登录:

登录后访问:

2、另起一个工程,application.properties配置

server.port=9003server.servlet.context-path=/server-url-prefix=http://localhost:8080/cas-serverserver-login-url=http://localhost:8080/cas-server/loginclient-host-url=http://localhost:9003/indexserver-logout-url =http://localhost:8080/cas-server/logoutclient-logout-url =http://localhost:8080/cas-server/logout?service=http://localhost:9003/logout/successvalidation-type=casserver-name=http://localhost:9003

启动:

package com.oumuv.cas;import net.unicon.cas.client.configuration.EnableCasClient;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication@EnableCasClient//启用cas clientpublic class CasCApplication {public static void main(String[] args) {SpringApplication.run(CasCApplication.class, args);}}

访问:

不需要登录就成功访问了

三、说说cas的原理

1、cas主要包含两部分server和client

CAS Server 负责完成对用户的认证工作 , 需要独立部署 , CAS Server 会处理用户名 / 密码等凭证(Credentials) 。

CAS Client负责处理对客户端受保护资源的访问请求,需要对请求方进行身份认证时,重定向到 CAS Server 进行认证。(原则上,客户端应用不再接受任何的用户名密码等 Credentials )。

CAS Client 与受保护的客户端应用部署在一起,以 Filter 方式保护受保护的资源。

2、原理图

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。