承接 fortyseeds/ci4-shield-ldap 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fortyseeds/ci4-shield-ldap

Composer 安装命令:

composer require fortyseeds/ci4-shield-ldap

包简介

Enhanced LDAP Authentication for CodeIgniter 4 Shield - Supports both Active Directory and OpenLDAP/FreeIPA

README 文档

README

Enhanced version of the LDAP Authentication library for CodeIgniter 4 Shield that supports both Active Directory and OpenLDAP/FreeIPA/389 Directory servers.

Features

  • Active Directory support (domain\username format)
  • OpenLDAP/FreeIPA/389 Directory support (DN format)
  • ✅ Automatic user creation on first login
  • ✅ LDAP attribute synchronization
  • ✅ Group membership handling
  • ✅ Configurable attribute mapping
  • ✅ Shield-compatible user identity management

Installation

composer require fortyseeds/ci4-shield-ldap

Configuration

1. Basic Setup

Copy the configuration file to your app:

cp vendor/fortyseeds/ci4-shield-ldap/src/Config/AuthLDAP.php app/Config/AuthLDAP.php

2. Configure for Active Directory

// app/Config/AuthLDAP.php
public string $ldap_host = 'ldap://dc.company.com';
public string $ldap_port = '389';
public bool $use_ldaps = true; // Use port 636 for LDAPS
public string $ldap_type = 'ad';
public string $ldap_domain = 'company'; // For domain\username format
public string $username = 'CN=Service Account,OU=Service Accounts,DC=company,DC=com';
public string $password = 'service_password';
public string $search_base = 'OU=Users,DC=company,DC=com';

// Active Directory attributes
public array $attributes = [
    'objectSID', 'distinguishedname', 'displayName', 'title', 'description', 
    'cn', 'givenName', 'sn', 'mail', 'co', 'telephoneNumber', 'mobile', 
    'company', 'department', 'l', 'postalCode', 'streetAddress',
    'samaccountname', 'thumbnailPhoto', 'userAccountControl'
];

3. Configure for OpenLDAP/FreeIPA

// app/Config/AuthLDAP.php
public string $ldap_host = 'ldap://ipa.company.com';
public string $ldap_port = '389';
public bool $use_ldaps = true; // Use port 636 for LDAPS
public string $ldap_type = 'ldap';
public string $login_attribute = 'uid'; // or 'cn' depending on your schema
public string $username = 'cn=admin,dc=company,dc=com';
public string $password = 'admin_password';
public string $search_base = 'cn=users,cn=accounts,dc=company,dc=com';

// OpenLDAP/FreeIPA attributes
public array $attributes = [
    'uid', 'cn', 'dn', 'distinguishedName', 'entryUUID', 'entryDN',
    'displayName', 'title', 'description', 'givenName', 'sn', 'mail',
    'telephoneNumber', 'mobile', 'o', 'ou', 'l', 'postalCode', 'street',
    'employeeNumber', 'employeeType', 'departmentNumber',
    'krbPrincipalName', 'krbCanonicalName', 'ipaUniqueID', 'memberOf'
];

4. Update Shield Configuration

// app/Config/Auth.php
public array $authenticators = [
    'ldap' => \Rakoitde\Shieldldap\Authentication\Authenticators\LDAP::class,
    'session' => \CodeIgniter\Shield\Authentication\Authenticators\Session::class,
    'tokens' => \CodeIgniter\Shield\Authentication\Authenticators\AccessTokens::class,
];

public array $authenticationChain = [
    'ldap',
    'session',
];

5. Database Migration

The package includes database migrations for additional LDAP fields. Run:

php spark migrate -all

Usage

Authentication Flow

  1. Active Directory: Users login with domain\username or just username
  2. OpenLDAP/FreeIPA: Users login with their uid (e.g., john.doe)

The system automatically:

  • Authenticates against LDAP
  • Creates local user account on first login
  • Synchronizes LDAP attributes
  • Manages user identity for Shield compatibility

Testing LDAP Connection

php spark shieldldap:check

Managing LDAP Users

php spark shieldldap:user

Authentication Types Comparison

Feature Active Directory OpenLDAP/FreeIPA
Login Format domain\username uid or cn
DN Format Automatic via domain uid=user,cn=users,cn=accounts,dc=domain,dc=com
Service Account domain\service or service@domain.com cn=admin,dc=domain,dc=com
Search Base OU=Users,DC=domain,DC=com cn=users,cn=accounts,dc=domain,dc=com
Primary Attributes samaccountname, objectSID uid, ipaUniqueID

Troubleshooting

Common Issues

  1. "Cannot assign null to property": Ensure LDAP attributes exist in your directory
  2. "UserIdentity not found": The enhanced version automatically creates email identities
  3. Connection timeout: Check firewall, ports (389/636), and network connectivity
  4. Authentication fails: Verify service account credentials and permissions

Debug Mode

Enable debug logging in your environment:

CI_ENVIRONMENT = development

Check logs in writable/logs/ for detailed LDAP authentication information.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Credits

Changelog

v2.0.0 (Enhanced Version)

  • ✅ Added OpenLDAP/FreeIPA/389 Directory support
  • ✅ Flexible DN construction based on LDAP type
  • ✅ Enhanced error handling and user identity management
  • ✅ Improved attribute mapping for different LDAP servers
  • ✅ Comprehensive documentation for both AD and OpenLDAP

v1.x (Original)

  • Active Directory support only

fortyseeds/ci4-shield-ldap 适用场景与选型建议

fortyseeds/ci4-shield-ldap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Authentication」 「ldap」 「openldap」 「shield」 「active-directory」 「codeigniter4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fortyseeds/ci4-shield-ldap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fortyseeds/ci4-shield-ldap 我们能提供哪些服务?
定制开发 / 二次开发

基于 fortyseeds/ci4-shield-ldap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-02