java教程之Spring Security系列教程之实现CAS单点登录下篇-搭建CAS客户端

本文详细介绍了如何使用Java和Spring Boot搭建CAS客户端,实现与CAS Server的单点登录集成。通过创建新项目,引入依赖,配置CAS客户端,创建安全配置类和测试接口,展示了单点登录的完整流程。同时,文中还提到了单点注销的实现方法,通过访问特定URL实现全局注销。此教程适用于Java开发者学习Spring Security和CAS集成。
摘要由CSDN通过智能技术生成

一. 搭建CAS客户端

1. 创建新项目

我们在之前的Spring Security项目中,创建一个新的module模块,作为CAS Client项目,如下图。

图片

2. 引入依赖

然后在这个模块的pom.xml文件中,引入相关依赖。

  <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-cas</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

其中最主要的依赖是spring-security-cas,其内部依赖关系如下:

图片

3. 配置CAS Client

创建一个application.yml文件,在其中添加CAS Client相关的配置,主要是与CAS Server进行关联的配置,这里请填写自己CAS Server端的地址信息。

  cas:
  #对服务端进行配置
  server:
    #cas server的主路径,这里指向我们的cas服务端
    prefix: https://cas.yyg.cn:8443/cas
    #指向cas服务端的登录页面
    login: ${cas.server.prefix}/login
    #指向cas服务端的退出登录页面
    logout: ${cas.server.prefix}/logout
  #对客户端进行配置  
  client:
    #配置cas客户端url前缀
    prefix: http://client.cas.yyg.cn:8080
    #配置客户端登录地址
    login: ${cas.client.prefix}/login/cas
    #以相对路径的形式配置退出登录接口
    relative: /logout/cas
    #以绝对路径的形式配置退出登录接口
    logout: ${cas.client.prefix}${cas.client.relative}
  user:
    
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值