首先我们来创建一个普通的 Spring Boot 项目,加入 Web 依赖 和 Spring Security 依赖,如下:
项目创建成功后,我们再来手动加入 cas 依赖:
org.springframework.security
spring-security-cas
接下来,在 application.properties 中配置 CAS Server 和 CAS Client 的请求地址信息:
cas.server.prefix=https://cas.javaboy.org:8443/cas
cas.server.login=${cas.server.prefix}/login
cas.server.logout=${cas.server.prefix}/logout
cas.client.prefix=http://client1.cas.javaboy.org:8080
cas.client.login=${cas.client.prefix}/login/cas
cas.client.logoutRelative=/logout/cas
cas.client.logout= c a s . c l i e n t . p r e f i x {cas.client.prefix} cas.client.prefix{cas.client.logoutRelative}
这些配置都是自定义配置,所以配置的 key 可以自己随意定义。至于配置的含义都好理解,分别配置了 CAS Server 和 CAS Client 的登录和注销地址。
配置好之后,我们需要将这些配置注入到实体类中使用,这里就用到了类型安全的属性绑定(参见:Spring Boot2 系列教程(四)理解配置文件 application.properties !)。
这里我创建两个类分别用来接收 CAS Server 和 CAS Client 的配置文件:
@ConfigurationPropert