zen/ldap-bundle
Composer 安装命令:
composer require zen/ldap-bundle
包简介
LDAP Bundle for Symfony 2 derived from imag/ldap-bundle
README 文档
README
LdapBundle provides a Ldap authentication system without the apache mod_ldap. It uses php-ldap extension with a form to authenticate the users. LdapBundle also can be used for the authorization. It retrieves the Ldap users' roles.
Contact
You can try to contact me on freenode irc ; channel #symfony-fr ; pseudo : aways
Install
- Download LdapBundle
- Configure the Autoloader
- Enable the Bundle
- Configure LdapBundle security.yml
- Import LdapBundle security.yml
- Import LdapBundle routing
- Implement Logout
- Subscribe to PRE_BIND event
Get the Bundle
Composer
Modify your composer.json on your project root
// {root}/composer.json { [...], "require": { [...], "imag/ldap-bundle": "dev-master" } }
Enable the Bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new IMAG\LdapBundle\IMAGLdapBundle(), ); }
Configure security.yml
# src/IMAG/LdapBundle/Resources/config/security.yml security: firewalls: restricted_area: pattern: ^/ anonymous: ~ provider: ldap imag_ldap: ~ # alternative configuration # imag_ldap: # login_path: /ninja/login logout: path: /logout target: / providers: ldap: id: imag_ldap.security.user.provider encoders: IMAG\LdapBundle\User\LdapUser: plaintext access_control: - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, roles: IS_AUTHENTICATED_FULLY } imag_ldap: client: host: your.host.foo port: 389 # version: 3 # Optional # username: foo # Optional # password: bar # Optional user: base_dn: ou=people,dc=host,dc=foo # filter: (&(foo=bar)(ObjectClass=Person)) #Optional name_attribute: uid role: base_dn: ou=group, dc=host, dc=foo # filter: (ou=group) #Optional name_attribute: cn user_attribute: member user_id: [ dn or username ]
You need to configure the parameters under the imag_ldap section.
Note:
If are not set, the optional parameters have default values. You can disable this ; Just set parameter to NULL.
imag_ldap: # ... role: # ... filter: NULL
Import security.yml
# app/config/config.yml imports: - { resource: ../../src/IMAG/LdapBundle/Resources/config/security.yml }
Import routing
# app/config/routing.yml imag_ldap: resource: "@IMAGLdapBundle/Resources/config/routing.yml"
Implement Logout
Just create a link with logout target.
<a href="{{ path('logout') }}">logout</a>
Note: You can refer to the official Symfony documentation : http://symfony.com/doc/2.0/book/security.html#logging-out
Subscribe to PRE_BIND event
Now you can perform you own logic before the user is authenticated on Ldap. If you want to break the authentication just return an Exception.
To subscribe:
<tag name="kernel.event_listener" event="imag_ldap.security.authentication.pre_bind" method="onPreBind" />
Exemple:
<?php use IMAG\LdapBundle\Event\LdapUserEvent, public function onPreBind(LdapUserEvent $event) { $user = $event->getUser(); $config = $this->appContext->getConfig(); $ldapConf = $config['ldap']; if (!in_array($user->getUsername(), $ldapConf['allowed'])) { throw new \Exception('Not allowed ldap user'); } $user->addRole('ROLE_LDAP'); }
zen/ldap-bundle 适用场景与选型建议
zen/ldap-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 68 次下载、GitHub Stars 达 0, 最近一次更新时间为 2012 年 11 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zen/ldap-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zen/ldap-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 68
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2012-11-21