当前位置:网站首页>基于CAS的SSO单点客户端配置
基于CAS的SSO单点客户端配置
2022-07-26 14:31:00 【Xiang想】
基于CAS的SSO单点客户端配置
相关文章:
创建完了服务端,接着创建客户端,对服务端进行测试
1、初始化SpringBoot 项目
初始化的时候,勾选spring web服务,也可以直接搭建 maven 服务
<dependency>
<groupId>net.unicon.cas</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>2.3.0-GA</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
maven 基础不够扎实的朋友们,还是建议使用 IDEA 上自带的 spring 初始化工具,创建两个项目,分别是 web-client-01 和 web-client-02
2、编写代码
在 SpringBoot 启动类上添加 @EnableCasClient 开启 CAS


分别是 webClient01Application、webClient02Application
为了节省篇幅,后面的配置我只列出一份例子,大家仔细阅读文字
1、添加配置信息
server:
port: 9093
cas:
server-login-url: http://localhost:9101/cas/login # CAS 服务登录地址
server-url-prefix: http://localhost:9101/cas # CAS 服务
client-host-url: http://localhost:9093 # 本地服务
validation-type: cas3 # 加密类型
两个服务分别使用 9092、9093 端口,CAS 服务登录地址、CAS服务和加密类型都是一致的,也就是之前我们配置的那个端口地址,跳转地址:,只有本地服务端口要灵活配置
2、添加Controller
两个服务均添加此 controller
import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.validation.Assertion;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import static org.jasig.cas.client.util.AbstractCasFilter.CONST_CAS_ASSERTION;
@RestController
public class Controller {
@RequestMapping("/sso-test1")
public String test1(HttpSession session){
Assertion assertion = (Assertion)session.getAttribute(CONST_CAS_ASSERTION);
AttributePrincipal principal = assertion.getPrincipal();
String loginName = principal.getName();
return "sso-test1,当前登录账户"+loginName;
}
}
到这里就配置完了
3、启动客户端服务
访问地址:
http://localhost:9092/sso-test1
会发现页面直接跳转到了登录页面

我们填入配置的服务端用户名和密码

点击登录后

我们再测试单点效果,访问
http://localhost:9093/sso-test2

不出所料,单点登录模拟成功!最后展示一下 客户端的代码结构

客户端代码太简单了,我就不上传 GitHub 了,有想要的小伙伴可以联系本Up。最后祝愿大家找到心仪的工作
最后给点个关注吧 
关注 『Xiang想』公众号
边栏推荐
- TransC知识表示模型
- Low power multi-channel wfas1431 wireless data acquisition and transmission instrument operation process description
- Mysql5.7 is installed through file zip - Ninth Five Year Plan xiaopang
- Seata deployment and microservice integration
- 图神经网络Core数据集介绍
- 【方差分析】之matlab求解
- Matlab solution of [analysis of variance]
- 【整数规划】
- 填问卷,领奖品 | 诚邀您填写 Google Play Academy 活动调研问卷
- Redis data operation
猜你喜欢

~6. CCF 2021-09-1 array derivation

Comparison between agile development and Devops

Jzoffer51- reverse pairs in the array (merge sort solution)

保证接口数据安全的10种方案

图神经网络Core数据集介绍

31. Opinion-based Relational Pivoting forCross-domain Aspect Term Extraction 阅读笔记

【2022国赛模拟】白楼剑——SAM、回滚莫队、二次离线
![[ostep] 04 virtualized CPU - process scheduling strategy](/img/42/7ffb9745ef21a8db35861119dd70bf.png)
[ostep] 04 virtualized CPU - process scheduling strategy

VP video structured framework

《MySQL高级篇》五、InnoDB数据存储结构
随机推荐
GOM login configuration free version generate graphic tutorial
请问下大家,flink sql有没有办法不输出update_before?
Research on prediction of user churn in online health community based on user portrait
VP视频结构化框架
Arithmetic operation and logic operation of image in opencv
ISCC2021 LOCKK题解
图神经网络Core数据集介绍
OpenCV中图像算术操作与逻辑操作
Would you please tell me if there is a way for Flink SQL not to output update_ before?
Comparison between agile development and Devops
UE4 smart pointer and weak pointer
当AI邂逅生命健康,华为云为他们搭建三座桥
Flask send_ Absolute path traversal caused by file function
Realize the full link grayscale based on Apache APIs IX through MSE
Learning basic knowledge of Android security
【1.2.投资的收益和风险】
UDP多线程在线聊天
Technology evolution analysis framework based on two-level topic model and its application
Use cpolar to build a commercial website (apply for website security certificate)
VP video structured framework