我的简单、原始的LDAP包

dev-master 2016-03-30 20:29 UTC

This package is auto-updated.

Last update: 2024-09-29 04:20:00 UTC


README

安装

Composer

要安装,只需将以下内容放入您的composer json文件中

"require": {
  		"mikebywater/ldap": "dev-master"
},

然后简单运行

composer update

参数

LDAP依赖于全局变量被设置。

Laravel

在Laravel中,只需在.env文件中设置以下变量

LDAP_SERVER =server.example.com
LDAP_DOMAIN=mydomain
LDAP_BASE_DSN=dc=example,dc=com
LDAP_ADMIN_USER=admin
LDAP_ADMIN_PASSWORD=password

使用方法

验证用户

use mikebywater\LDAP\LDAP as LDAP;
$ldap = new LDAP();
$username = 'testmember';
$password = 'test123';
if($ldap->authenticate($username,$password))
{
 echo "Authenticated";
}
else
{
    echo "Invalid Credentials";
}

搜索LDAP

use mikebywater\LDAP\LDAP as LDAP;
// Instantiate object
$ldap = new LDAP();
$username = "george.land";
// Method chaining allows us to bind to ldap, apply an ldap filter and get the first result
$entry = $ldap->bind()->filter("sAMAccountName=$username")->get()->first();

从条目中提取用户详细信息

通过使用LDAPUser类,我们可以从条目中获取用户详细信息

use mikebywater\LDAP\LDAPUser as LDAPUser;
// Instantiating the object requires you to pass your ldap connection and the entry
// from the previous example
$user = new LDAPUser($ldap->conn, $entry);
$name =  $user->getName(); //special function for display name
$email = $user->getEmail(); //special function foe mail attributes
$company= $user->__get('company')[0]; // any other attribute can be grabbed with magic get method (beware will return an array)
$description= $user->__get('description')[0];