newtondasilva/ldaptools
Composer 安装命令:
composer require newtondasilva/ldaptools
包简介
LdapTools is a feature-rich LDAP library for PHP 5.6+.
README 文档
README
LdapTools is a feature-rich LDAP library for PHP 5.6+. It was designed to be customizable for use with pretty much any directory service, but contains default attribute converters and schemas for Active Directory and OpenLDAP.
- A fluent and easy to understand syntax for generating LDAP queries.
- Easily create/modify/delete/restore common LDAP objects (Users, Groups, Contacts, Computers, OUs).
- Retrieve LDAP objects as either a simple array or an object with automagic setters/getters.
- A logging mechanism for all LDAP operations
- An event system for further customization, extensibility, and integration.
- Parse and create LDIF files.
- View and modify Active Directory permissions.
Installation
The recommended way to install LdapTools is using Composer:
composer require ldaptools/ldaptools
Getting Started
The easiest way to get started is by creating a YAML config file. See the example config file for basic usage. See the configuration file reference doc for a list of all available options.
Once you have a configuration file defined, you can get up and running by doing the following:
use LdapTools\Configuration; use LdapTools\LdapManager; $config = (new Configuration())->load('/path/to/ldap/config.yml'); $ldap = new LdapManager($config);
Searching LDAP
With the LdapManager up and going you can now easily build LDAP queries without having to remember all the special
syntax for LDAP filters. All values are also automatically escaped. Check the tutorial for all
available methods and the cookbook for more query examples.
use LdapTools\Object\LdapObjectType; // Get an instance of the query... $query = $ldap->buildLdapQuery(); // Returns a LdapObjectCollection of all users whose first name // starts with 'Foo' and last name is 'Bar' or 'Smith'. // The result set will also be ordered by state name (ascending). $users = $query->fromUsers() ->where($query->filter()->startsWith('firstName', 'Foo')) ->orWhere(['lastName' => 'Bar']) ->orWhere(['lastName' => 'Smith']) ->orderBy('state') ->getLdapQuery() ->getResult(); echo "Found ".$users->count()." user(s)."; foreach ($users as $user) { echo "User: ".$user->getUsername(); } // Get all OUs and Containers at the base of the domain, ordered by name. $results = $ldap->buildLdapQuery() ->from(LdapObjectType::OU) ->from(LdapObjectType::CONTAINER) ->orderBy('name') ->setScopeOneLevel() ->getLdapQuery() ->getResult(); // Get a single LDAP object and select some specific attributes... $user = $ldap->buildLdapQuery() ->select(['upn', 'guid', 'sid', 'passwordLastSet']) ->fromUsers() ->where(['username' => 'chad']) ->getLdapQuery() ->getSingleResult(); // Get a single attribute value from a LDAP object... $guid = $ldap->buildLdapQuery() ->select('guid') ->fromUsers() ->where(['username' => 'chad']) ->getLdapQuery() ->getSingleScalarResult(); // It also supports the concepts of repositories... $userRepository = $ldap->getRepository('user'); // Find all users whose last name equals Smith. $users = $userRepository->findByLastName('Smith'); // Get the first user whose username equals 'jsmith'. Returns a `LdapObject`. $user = $userRepository->findOneByUsername('jsmith'); echo "First name ".$user->getFirstName()." and last name ".$user->getLastName();
See the docs for more information on building LDAP queries.
Modifying LDAP Objects
Modifying LDAP is as easy as searching for the LDAP object as described above, then making changes directly to the object
and saving it back to LDAP using the LdapManager.
$user = $ldap->buildLdapQuery() ->select(['title', 'mobilePhone', 'disabled']) ->fromUsers() ->where(['username' => 'jsmith']) ->getLdapQuery() ->getSingleResult(); // Make some modifications to the user account. // All these changes are tracked so it knows how to modify the object. $user->setTitle('CEO'); if ($user->hasMobilePhone()) { $user->resetMobilePhone(); } // Set a field by a property instead... if ($user->disabled) { $user->disabled = false; } // Add a value to an attribute... $user->addOtherIpPhones('#001-5555'); // Add a few values at one time... $user->addOtherIpPhones('#001-4444', '#001-3333', '#001-2222'); // Now actually save the changes back to LDAP... try { $ldap->persist($user); } catch (\Exception $e) { echo "Error updating user! ".$e->getMessage(); }
See the docs for more information on modifying LDAP objects.
Deleting LDAP Objects
Deleting LDAP objects is a simple matter of searching for the object you want to remove, then passing it to the delete
method on the LdapManager:
// Decide they no longer work here and should be deleted? $user = $userRepository->findOneByUsername('jsmith'); try { $ldap->delete($user); } catch (\Exception $e) { echo "Error deleting user! ".$e->getMessage(); }
Creating LDAP Objects
Creating LDAP objects is easily performed by just passing what you want the attributes to be and what container/OU the object should end up in:
$ldapObject = $ldap->createLdapObject(); // Creating a user account (enabled by default) $ldapObject->createUser() ->in('cn=Users,dc=example,dc=local') ->with(['username' => 'jsmith', 'password' => '12345']) ->execute(); // Create a typical AD global security group... $ldapObject->createGroup() ->in('dc=example,dc=local') ->with(['name' => 'Generic Security Group']) ->execute(); // Creates a contact user... $ldapObject->createContact() ->in('dc=example,dc=local') ->with(['name' => 'Some Guy', 'emailAddress' => 'SomeGuy@SomeDomain.com']) ->execute(); // Creates a computer object... $ldapObject->createComputer() ->in('dc=example,dc=local') ->with(['name' => 'MYWOKRSTATION']) ->execute(); // Creates an OU object... $ldapObject->createOU() ->in('dc=example,dc=local') ->with(['name' => 'Employees']) ->execute();
See the docs for more information on creating LDAP objects.
Documentation
Browse the docs folder for more information about LdapTools.
- Main Configuration Reference
- Schema Configuration
- Using the LdapManager
- Building LDAP Queries
- Creating LDAP Objects
- Modifying LDAP Objects
- LDIF files
- Active Directory Permissions
- Default Schema Attributes
- The Event System
TODO
Things that still need to be implemented:
- Automatic generation of the schema based off of information in LDAP.
- More work needed on the OpenLDAP schema.
newtondasilva/ldaptools 适用场景与选型建议
newtondasilva/ldaptools 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 03 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ldap」 「active directory」 「openldap」 「Microsoft Exchange」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 newtondasilva/ldaptools 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 newtondasilva/ldaptools 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 newtondasilva/ldaptools 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Propel2 is an open-source Object-Relational Mapping (ORM) for PHP 5.5 and up.
A Symfony extension to get active class base on current bundle/controller/action
LDAP user provider bundle for Symfony 6.4
The helper class for Laravel applications to get active class base on current route for Laravel 11
Anax Database Active Record module for model classes.
Package
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-16