jeecg cas
时间: 2025-03-13 14:19:09 浏览: 31
### Jeecg与CAS单点登录集成概述
Jeecg作为一个高效的企业级快速开发平台,支持与其他安全认证机制的无缝集成。其中,Central Authentication Service (CAS) 是一种广泛使用的单点登录(SSO)协议,允许用户在一个地方完成身份验证后访问多个应用系统。
#### 集成步骤详解
以下是关于如何在Jeecg项目中集成CAS单点登录的关键技术要点:
1. **环境准备**
- 确保已安装并运行CAS服务器。如果未搭建CAS服务器,则需按照官方文档进行设置[^1]。
- 下载Jeecg项目的源码并通过Git克隆到本地环境中[^4]:
```bash
git clone https://github.com/zhangdaiscott/jeecg-boot.git
cd jeecg-boot/ant-design-jeecg-vue
```
2. **依赖引入**
在`pom.xml`文件中添加必要的Spring Security和CAS客户端库依赖项:
```xml
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- CAS Client Dependency -->
<dependency>
<groupId>org.jasig.cas.client</groupId>
<artifactId>cas-client-core</artifactId>
<version>3.6.1</version>
</dependency>
```
3. **配置文件调整**
修改`application.yml`或`application.properties`中的相关参数以适配CAS服务地址[^2]:
```yaml
cas:
server-url-prefix: http://localhost:8080/cas
client-host-url: http://localhost:9090/
login-url: ${cas.server-url-prefix}/login
logout-url: ${cas.server-url-prefix}/logout?service=${cas.client-host-url}
spring:
security:
user:
name: admin
password: 123456
```
4. **自定义过滤器链**
创建一个Java类用于重写默认的安全拦截规则,并注册CAS特定的过滤器实例[^3]:
```java
@Configuration
public class CasSecurityConfig extends WebSecurityConfigurerAdapter {
private final String casServerUrlPrefix;
private final String service;
public CasSecurityConfig(@Value("${cas.server-url-prefix}") String casServerUrlPrefix,
@Value("${cas.client-host-url}") String clientHostUrl) {
this.casServerUrlPrefix = casServerUrlPrefix;
this.service = clientHostUrl + "/j_spring_cas_security_check";
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable();
SingleSignOutFilter singleSignOutFilter = new SingleSignOutFilter();
singleSignOutFilter.setCasServerUrlPrefix(casServerUrlPrefix);
CasAuthenticationEntryPoint entryPoint = new CasAuthenticationEntryPoint();
entryPoint.setLoginUrl(casServerUrlPrefix + "/login");
entryPoint.setServiceProperties(serviceProperties());
http.addFilterBefore(singleSignOutFilter, BasicAuthenticationFilter.class);
http.exceptionHandling().authenticationEntryPoint(entryPoint);
}
@Bean
public ServiceProperties serviceProperties() {
ServiceProperties serviceProperties = new ServiceProperties();
serviceProperties.setService(service);
serviceProperties.setSendRenew(false);
return serviceProperties;
}
}
```
5. **前端页面修改**
如果需要兼容Vue或其他前端框架,在登录界面跳转至CAS入口时应确保URL拼接正确无误。
---
### 常见问题及其解决方案
- **异常处理:Invalid parameter: CAS Server**
当抛出此错误提示时表示传入的服务端路径有误或者网络连接存在问题,请仔细核对`server-url-prefix`字段值是否指向有效的CAS节点。
- **会话同步失败**
可能由于浏览器缓存策略影响跨域请求头携带的信息丢失所致;建议启用CORS插件测试联调效果。
- **登出不彻底**
登录注销环节务必清理掉所有关联Cookie数据以及通知其他子系统销毁对应Token记录。
---
阅读全文
相关推荐


















