当前位置:网站首页>基于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想』公众号
边栏推荐
- 多线程——线程池
- 【整数规划】
- 『云原生』KubeSphere可插拔组件之DevOps系统
- UDP multithreaded online chat
- Sqldeveloper tools quick start
- Prediction and value evaluation of technology fusion relationship based on multiple features
- 请问数据库规范的文档吗 参考一下?
- Mysql5.7 is installed through file zip - Ninth Five Year Plan xiaopang
- OpenCV中图像算术操作与逻辑操作
- How to do app upgrade test?
猜你喜欢
![[deep learning] fully connected network](/img/88/43f80b6a28773f9c4d2c31a8cb206b.png)
[deep learning] fully connected network

GOM login configuration free version generate graphic tutorial

Install dexdump on win10 and remove the shell
![Matlab solution of [analysis of variance]](/img/30/638c4671c3e37b7ce999c6c98e3700.png)
Matlab solution of [analysis of variance]

Leetcode question type priority queue (TOPK question)

What is the problem of the time series database that has been developed for 5 years?

Leetcode36 effective Sudoku
网络图片转本地导致内核退出

中部“第一城”,长沙“人才引力”从争先到领先

【文件上传漏洞-06】分布式配置文件攻击实验—以upload-labs-4为例
随机推荐
嵌入式开发:调试嵌入式软件的技巧
~6. CCF 2021-09-1 array derivation
键盘快捷键操作电脑(自己遇到不会的)
A survey of machine learning based technology term recognition
全校软硬件基础设施一站式监控 ,苏州大学以时序数据库替换 PostgreSQL
Unity学习笔记–无限地图
My creation Anniversary - from the heart
Seata deployment and microservice integration
What is restful style and its four specific implementation forms
Research on technology subject division method based on patent multi-attribute fusion
Plato farm is expected to further expand its ecosystem through elephant swap
c# 用移位 >> 和运算与 &判断两个 二进制数 是否发生过改变
请问下大家,flink sql有没有办法不输出update_before?
C语言入门必刷100题合集之每日一题(1-20)
Iscc2021 lock problem solution
Maya imports the model into unity
保证接口数据安全的10种方案
Create Yum warehouse inside the enterprise
多线程——线程池
GOM登录器配置免费版生成图文教程