Spring Boot 集成Shiro和CAS

时间:2024-03-23 17:21:57

首先看一下下面这张图:

第一个流程是单纯使用Shiro的流程。

第二个流程是单纯使用Cas的流程。

第三个图是Shiro集成Cas后的流程。

 

Spring Boot 集成Shiro和CAS

 

PS:流程图急急忙忙画的,整体上应该没有什么问题,具体细节问题还请大家留言指正。

 

如果你只是打算用到你的Spring Boot项目中,那么看着如下配置完成便可。

如果你想进一步了解其中的细节,还是建议大家单独配置Shiro、单独配置Cas,看看官方相关文档。

Shiro在1.2版本开始提供了对cas的集成,按下面添加依赖到pom.xml中:

 

Spring Boot 集成Shiro和CAS

shiro-cas 依赖 shiro-web,shiro-web 依赖 shiro-core,所以添加shiro-cas后shiro-web.jar和shiro-core.jar会自动被引用。

cas被shiro集成后,其原理就是shiro将casFilter加入到shiroFilter的filterChain中。

 

在SpringBoot工程中创建ShiroCasConfiguration.java

 

Spring Boot 集成Shiro和CAS

Spring Boot 集成Shiro和CAS

Spring Boot 集成Shiro和CAS

Spring Boot 集成Shiro和CAS

Spring Boot 集成Shiro和CAS


 

创建权限认证的 MyShiroCasRealm.java

 

Spring Boot 集成Shiro和CAS

Spring Boot 集成Shiro和CAS


 

在Controller中添加一个方法,用于将登录URL简单化,提供一个重定向功能

Spring Boot 集成Shiro和CAS

 

本文主要是介绍如何在Spring Boot中集成Shiro+Cas,并非一个从零创建工程到整体完成的介绍。