(原创)LDAP与CAS单点登录集成

本文介绍如何配置CAS使用LDAP作为认证源,并详细展示了deployerConfigContext-ldap.xml配置文件的内容。文章通过对比不同搜索基节点的影响,揭示了多账户认证的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 我的百度空间中也可以访问到这些文章:hi.baidu.com/five00
编写CAS的配置文件deployerConfigContext-ldap.xml,这里配置了关于Ldap认证源的各种信息,代码如下:
<? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
< beans >
< bean id = "authenticationManager"   class = "org.jasig.cas.authentication.AuthenticationManagerImpl" >
    < property name = "credentialsToPrincipalResolvers" >
        < list >
            < bean
        class = "org.jasig.cas.authentication.principal.UsernamePasswordCredentialsToPrincipalResolver" />
            < bean
    class = "org.jasig.cas.authentication.principal.HttpBasedServiceCredentialsToPrincipalResolver" />
        </ list >
    </ property >
    < property name = "authenticationHandlers" >
        < list >
            < bean               class = "org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" />
 
< bean               class = "org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" />
            < bean       class = "org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler" >
                < property name = "filter" value = "uid=%u" />
                 <!-- 基节点 -->
                < property name = "searchBase" value = "ou=People,ou=rootOrg,o=sevenSeas" />
                < property name = "contextSource" ref = "contextSource" />
            </ bean >
        </ list >
    </ property >
</ bean >
 
< bean id = "contextSource" class = "org.jasig.cas.adaptors.ldap.util.AuthenticatedLdapContextSource" >
        < property name = "password" value = "secret" />
        < property name = "pooled" value = "true" />
        < property name = "urls" >
            < list >
                < value > ldap://localhost:10389/ </ value >
            </ list >
        </ property >
        <!— 管理员 -->
        < property name = "userName" value = "uid=admin,ou=system" />
        < property name = "baseEnvironmentProperties" >
            < map >
                < entry >
                        < key >< value > java.naming.security.authentication </ value ></ key >
                     < value > simple </ value >
                 </ entry >
             </ map >
        </ property >
    </ bean >             
   
</ beans >
如果使用 ou=People,ou=rootOrg,o=sevenSeas 节点,如第7章的图所示,输出日志信息为:
[DEBUG] 2007-12-20 13:28:51,675 org.jasig.cas.web.flow.AuthenticationViaFormAction - Found existing form object with name 'credentials' of type [class org.jasig.cas.authentication.principal.UsernamePasswordCredentials] in scope Flow
[DEBUG] 2007-12-20 13:28:51,675 org.jasig.cas.CentralAuthenticationServiceImpl - Attempting to create TicketGrantingTicket for admin
username is [admin]
password is [secret]
[DEBUG] 2007-12-20 13:28:51,722 org.springframework.ldap.support.LdapContextSource - Principal: 'uid=admin,ou=system'
[DEBUG] 2007-12-20 13:28:52,113 org.springframework.ldap.support.LdapContextSource - Got Ldap context on server 'ldap://localhost:10389/'
cns is [[cn=admin]]
cns.isEmpty() is [false]
cns.size() is [1]
!this.allowMultipleAccounts is [true]
这是日志信息显示只有一个cn=admin的用户,可以进行Ldap认证。
如果将节点改为o=sevenSeas的话,如图:
以sevenSeas为基节点
再次验证日志信息会出现如下显示:
[DEBUG] 2007-12-20 13:43:56,347 org.jasig.cas.web.flow.AuthenticationViaFormAction - Found existing form object with name 'credentials' of type [class org.jasig.cas.authentication.principal.UsernamePasswordCredentials] in scope Flow
[DEBUG] 2007-12-20 13:43:56,347 org.jasig.cas.CentralAuthenticationServiceImpl - Attempting to create TicketGrantingTicket for admin
username is [admin]
password is [secret]
[DEBUG] 2007-12-20 13:43:56,363 org.springframework.ldap.support.LdapContextSource - Principal: 'uid=admin,ou=system'
[DEBUG] 2007-12-20 13:43:56,394 org.springframework.ldap.support.LdapContextSource - Got Ldap context on server 'ldap://localhost:10389/'
cns is [[cn=admin,ou=Roles,ou=rootOrg, cn=admin,ou=People,ou=rootOrg]]
cns.isEmpty() is [false]
cns.size() is [2]
!this.allowMultipleAccounts is [true]
这时我们看到people和role节点下面都有cn=admin,这时候 allowMultipleAccounts 的值为 true ,意味着当前有多歌同名帐号,系统不知道该选择哪个,所以会验证失败。这是需要注意的地方。v
 
### 部署配置CAS单点登录系统于TongWeb #### 选择合适的版本 为了确保兼容性和稳定性,在 TongWeb 上部署 CAS 单点登录系统前,需确认所使用的 CAS 版本 TongWeb 的适配情况。通常建议选用经过广泛测试且稳定发布的 CAS 版本[^1]。 #### 安装Java环境 由于 CAS 是基于 Java 开发的应用程序,因此需要先安装 JDK 或 JRE 环境。对于国产信创操作系统如麒麟服务器操作系统、统信 UOS 和华为欧拉等,应优先考虑使用这些平台官方推荐或预装的 Java 运行时环境以获得最佳性能和支持[^2]。 #### 下载并解压CAS包 从官方网站下载适合当前操作系统的 CAS 发布版压缩文件,并将其放置到指定目录下进行解压处理。注意检查下载链接的安全性以及验证文件完整性哈希值来保障安全性。 #### 修改配置文件 进入解压后的 CAS 文件夹内找到 `deployerConfigContext.xml` 及其他必要的配置文档,按照实际需求调整参数设置,比如更改端口号、启用 SSL/TLS 加密通信等功能选项。特别需要注意的是要正确配置数据库和 LDAP 身份认证对接的信息。 #### 打包WAR文件 完成上述准备工作之后,利用 Maven 工具构建项目并将最终产物打包成 WAR 形式的 Web 应用程序档案。此过程可能涉及到修改 pom.xml 中的一些依赖关系声明,请参照官方指南执行相应命令。 ```bash mvn clean package -DskipTests=true ``` #### 将WAR部署至TongWeb 通过管理界面或者命令行工具上传之前生成好的 cas.war 到 TongWeb 的 webapps 目录之下,随后启动容器使新加入的服务生效即可。如果遇到任何错误提示,则依据日志记录排查原因直至成功运行为止。 #### 测试SSO功能 最后一步便是检验整个流程是否顺畅无误地实现了预期目标—即多个应用程序之间能够借助同一套凭证顺利完成相互间的无缝切换而无需重复输入用户名密码。此时可以尝试编写简单的 API 接口用于不同编程语言(Java, PHP,.NET)接入 CAS 平台来进行联合调试工作。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值