在这里我们创建了两个客户端。
整合cas(以shiro-cas-client-one为例)
总pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lhl.shiro.cas</groupId>
<artifactId>shiro-cas</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>shiro-cas-client-one</module>
<module>shiro-cas-client-two</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<java.cas.client.version>3.5.0</java.cas.client.version>
</properties>
</project>
shiro-cas-client-one pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>shiro-cas</artifactId>
<groupId>com.lhl.shiro.cas</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>shiro-cas-client-one</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--thymeleaf 模板依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--cas的客户端 -->
<dependency>
<groupId>net.unicon.cas</groupId>
<artifactId>cas-client-autoconfig-support</artifactId>
<version>1.4.0-GA</version>
<exclusions>
<exclusion>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>${java.cas.client.version}</version>
</dependency>
</dependencies>
</project>
shiro-cas-client-one application.properties(这里先使用http的方式进行访问)
server.port=9010
#cas配置
#cas服务端前缀,不是登录地址
cas.server-url-prefix=http://shiro.sso.com:8080
#cas的登录地址
cas.server-login-url=http://shiro.sso.com:8080/login
#当前客户端的地址
cas.client-host-url=http://shiro.sso.com:9010
#Ticket校验器使用Cas30ProxyReceivingTicketValidationFilter
cas.validation-type=CAS
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/
spring.mvc.view.prefix=classpath:/templates/
# 给返回的页面添加后缀名
spring.mvc.view.suffix=.html
给启动类加注解
package com.lhl.shiro.cas.client.one;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import net.unicon.cas.client.configuration.EnableCasClient;
@SpringBootApplication
@EnableCasClient//开启cas
public class ShiroCasClientOneApplication {
public static void main(String[] args) {
SpringApplication.run(ShiroCasClientOneApplication.class, args);
}
}
配置访问链接跳转地址
package com.lhl.shiro.cas.client.one.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author: hualiang.liu
* @description:
* @date: created in 2021/2/18 11:19
*/
@Controller
@RequestMapping("/one")
public class AliveUrlController {
//shiro.sso.com:9010/one/fireworks
@GetMapping("/fireworks")
public String fireworks(){
return "Fireworks/index";
}
@GetMapping("/whiteClouds")
public String whiteClouds(){
return "whiteClouds/index";
}
}
启动cas服务端
启动客户端(shiro-cas-client-one)
访问地址:http://shiro.sso.com:9010/one/fireworks
报了一个问题
原因是服务端不允许客户端的http协议的请求。需要对服务端做以下修改,让他妥协。
在之前我们定义了shiro-cas------自定义登录页面
对所有https和http请求的service进行允许认证,在resources/services下修改文件shiroCasOne-100.json;
"serviceId"
由原来的
"^(https|imaps)://.*"
改成
"^(https|imaps|http)://.*"
{
"@class": "org.apereo.cas.services.RegexRegisteredService",
"serviceId": "^(https|imaps|http)://.*",
"name": "shiroCasOne",
"id": 100,
"description": "shiroCasOne 登入",
"evaluationOrder": 10,
"theme" : "shiroCasOne"
}
在application.properties文件中添加:
cas.tgc.secure=false
cas.serviceRegistry.initFromJson=true
然后重新启动服务
重新访问 跳转到认证页面
输入用户名密码登录跳转我们之前访问的地址页
访问http://shiro.sso.com:9020/two/raindrops(客户端shiro-cas-client-two)直接访问
上面两个登陆后动画是在网上找的。。。
简单集成完成!