Skip to content

feat(auth): support standard CAS 2.0/3.0 SSO protocol #456

@XiaoSeS

Description

@XiaoSeS

背景

#444 的 review 中,我们决定不合并基于私有协议的 SSO 实现,转而支持标准 CAS 2.0/3.0 协议,使 OSS 用户可以对接 Apereo CAS Server、Keycloak CAS adapter 等主流实现。

关联 PR:#444(已关闭)

目标

实现标准 CAS 2.0/3.0 协议的 SSO 登录集成,复用现有 IdentityBindingService 身份映射抽象。

设计要点

协议支持

  • CAS 2.0:GET /serviceValidate?ticket=...&service=... → XML 响应
  • CAS 3.0:GET /p3/serviceValidate?ticket=...&service=...&format=JSON → JSON 响应
  • 优先实现 3.0 JSON 模式,兼容 2.0 XML fallback

架构原则

  1. 复用 IdentityBindingService:将 CAS attributes 适配为通用 IdentityClaims(需先将 IdentityBindingService.bindOrCreate 的入参从 OAuthClaims 抽象为 provider-neutral 接口)
  2. 复用 OAuthLoginRedirectSupport.sanitizeReturnTo():防止 open redirect
  3. HTTPS 强校验@PostConstruct 校验 CAS server URL 必须为 HTTPS(或提供显式 escape hatch 用于开发环境)
  4. Feature flag:默认 disabled,通过 skillhub.auth.cas.enabled=true 启用

配置项(初步)

skillhub:
  auth:
    cas:
      enabled: false
      server-url: https://cas.example.com  # CAS server base URL
      service-url: https://skillhub.example.com/api/v1/auth/cas/callback
      protocol-version: 3.0  # 2.0 | 3.0
      attributes:
        username: uid          # CAS attribute → platform username
        display-name: cn       # CAS attribute → display name
        email: mail            # CAS attribute → email (optional)

前端

实现步骤

  • 重构:将 IdentityBindingService.bindOrCreate(OAuthClaims) 抽象为 IdentityClaims 接口,OAuth 和 CAS 各自实现
  • 后端:CasProperties 配置类 + @PostConstruct 校验
  • 后端:CasTicketValidator(GET serviceValidate,解析 XML/JSON)
  • 后端:CasLoginController(/login 重定向 + /callback 票据验证)
  • 后端:CasIdentityClaims 适配器,调用 IdentityBindingService
  • 后端:RouteSecurityPolicyRegistry 放行 /api/v1/auth/cas/**
  • 前端:CasLoginEntry 组件 + runtime config
  • 前端:30-runtime-config.sh 添加 SKILLHUB_WEB_AUTH_CAS_ENABLED
  • 测试:CasTicketValidator 单测(mock XML/JSON 响应)
  • 测试:CasLoginController 单测(redirect / callback / error)
  • 文档:部署文档补充 CAS 配置说明

参考

备注

  • 如果内部部署需要对接非标准 CAS 协议(如讯飞内部 SSO 网关),建议作为独立私有模块维护,不进 OSS 主干
  • 可考虑直接使用 spring-security-cas 模块,但需评估与现有 PlatformSessionService 的集成成本

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/l大改动或高风险改动,需要 maintainer 负责 / Large or risky change requiring maintainer ownership.enhancementNew feature or requestpriority/p2中优先级 / Medium priority triage bucket.risk/high涉及安全、鉴权、迁移或公共契约 / Touches security, auth, migrations, or public contracts.triage/needs-info需要补充更多信息后才能分流 / Issue needs more detail before it can be routed.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions