一. 搭建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: