gtt / ad-poller
通过ldap轮询Active Directory并通过事件调度器分发有效载荷
Requires
- php: >=5.5|^7.0
- doctrine/orm: ^2.5
- laminas/laminas-ldap: ^2.10
- symfony/console: ^2.3|^3.0
- symfony/event-dispatcher: ^2.3|^3.0
Requires (Dev)
- phpspec/prophecy: ^1.7
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2024-09-15 04:05:35 UTC
README
此包是PHP实现的Active Directory服务器更改轮询算法,使用uSNChanged属性作为偏移量,并添加了允许自定义调整Active Directory获取过程和更改集处理的额外功能。
主要使用目的是保持您的应用程序与Active Directory结构同步。
概述
核心概念是持续轮询Active Directory服务器,并使用uSNChanged属性作为偏移量执行增量获取以获取更改集。每个轮询任务运行都会保存在数据库中以保存偏移量和获取统计信息。在Active Directory控制器交换、服务器故障或首次运行算法时,执行完整获取以获取完整集。接收到的数据将提交给目标应用程序进行处理。
该组件由三个主要部分组成:轮询器、获取器和同步器。
轮询器
这是库的核心和原始轮询算法的基础实现。使用获取器与Active Directory服务器交互以获取更改集,并使用同步器处理获取到的更改集。
请参阅轮询器实现以获取详细信息。
获取器
这部分负责与Active Directory交互。允许轮询器从Active Directory获取必要的元数据并使用zendframework/zend-ldap搜索更改集。
请参阅LdapFetcher实现以获取详细信息。
同步器
同步器是关于处理轮询过程中接收到的数据集的。基本实现使用symfony/event-dispatcher将更改集/完整集发布为事件。对于增量同步,有一个IncrementalSyncEvent,对于完整同步 - FullSyncEvent。
请参阅EventSynchronizer实现以获取详细信息。
组件提供了SynchronizerInterface,允许实现自定义同步器以实现自定义目标。
设置和使用
包安装
要安装此包,请使用composer
composer require gtt/ad-poller
数据库设置
可以使用 doctrine 控制台工具生成架构。您可以从头开始克隆存储库,调整 cli-config.php 文件以使用您的测试数据库凭证,并生成初始化 SQL。
composer install && php ./vendor/bin/doctrine orm:schema-tool:create --dump-sql
应用程序设置
创建轮询器
// configure ldap connector $ldapConnector = new Ldap( // Connector options. @see https://github.com/zendframework/zend-ldap for details [ 'host' => 'ldap.myorg.com', 'username' => 'poller@ldap.myorg.com', 'password' => 'secret', 'accountDomainName' => 'ldap.myorg.com', 'baseDn' => 'DC=myorg,DC=com' ] ); // configure ldap fetcher $ldapFetcher = new \Gtt\ADPoller\Fetch\LdapFetcher( $ldapConnector, // Optional ldap filter describes entries to fetch during full sync '&(objectClass=user)(objectCategory=person))', // Optional ldap filter describes entries to fetch during incremental sync. // It can differ from the previous one if you want track deactivatation of entities // (during full sync you need only active, but here - not) '&(objectClass=user)(objectCategory=person))', // Optional ldap filter describes deleted entries to fetch during incremental sync '&(objectClass=user)(objectCategory=person))', // list of properties to be fetched ['cn', 'displayname','telephonenumber', 'description'] ); // you also can specify additional ldap search options here if you need, for example: $ldapFetcher->setLdapSearchOptions(LDAP_OPT_SERVER_CONTROLS, [['oid' => '1.2.840.113556.1.4.529']]); // configure entity manager to persist poll tasks $em = \Doctrine\ORM\EntityManager::create($conn, $config); // configure synchronizer (use your own SynchronizerInterface implementation if needed) $sync = new \Gtt\ADPoller\Sync\Events\EventSynchronizer(new \Symfony\Component\EventDispatcher\EventDispatcher()); // configure Poller itself $poller = new Poller( $ldapFetcher, $sync, $em, // optionaly you can tell poller to fetch deleted entries // @see https://msdn.microsoft.com/en-us/library/ms677927(v=vs.85).aspx for details false // optional poller name - use it if you have different pollers 'mypoller' );
您也可以根据需要创建任意数量的轮询器,并使用不同的设置。
现在您可以永久轮询 Active Directory(通常使用 crontab),运行以下类似命令:
$poller->poll();
还有控制台命令,它提供了一个方便的方式来运行轮询器,并具有美观的输出和附加选项,如果您使用 symfony/console。
// bin/console (do not forget #!/usr/bin/env php at very first line) // create poller collection $pollerCollection = new \Gtt\ADPoller\PollerCollection(); // Add poller to collection: $pollerCollection->addPoller($poller); // create application and command $application = new \Symfony\Component\Console\Application(); $application->add(new \Gtt\ADPoller\Command\PollCommand($pollerCollection)); $application->run();
并将其放入 crontab 命令中以运行所有轮询器
php bin/console gtt:pollers:run
或具体的某一个
php bin/console gtt:pollers:run --poller=mypoller
框架集成
有一个 gtt/ad-poller-bundle,它可以集成到 Symfony2+ 生态系统中的组件。
测试
要运行库测试套件,只需克隆存储库,然后在内部执行以下命令:
composer install && ./vendor/bin/phpunit