本文整理汇总了PHP中ldap_get_attributes函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_get_attributes函数的具体用法?PHP ldap_get_attributes怎么用?PHP ldap_get_attributes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_get_attributes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAttributes
/**
* @return array
* @throws ValueRetrievalFailureException
*/
public function getAttributes()
{
if (!($attributes = ldap_get_attributes($this->link, $this->entry))) {
throw new ValueRetrievalFailureException(ldap_error($this->link), ldap_errno($this->link));
}
return $attributes;
}
示例2: fetchEntry
/**
* @return mixed resource
*/
public function fetchEntry()
{
if (!$this->result_resource) {
return null;
}
if (null === $this->entry_resource) {
$this->entry_resource = ldap_first_entry($this->resource, $this->result_resource);
} else {
$this->entry_resource = ldap_next_entry($this->resource, $this->entry_resource);
}
if (!$this->entry_resource) {
return null;
}
$dn = ldap_get_dn($this->resource, $this->entry_resource);
$rawAttributes = ldap_get_attributes($this->resource, $this->entry_resource);
$count = $rawAttributes['count'];
$attributes = array();
for ($i = 0; $i < $count; $i++) {
$attribute = $rawAttributes[$i];
$values = array();
$subCount = $rawAttributes[$attribute]['count'];
for ($j = 0; $j < $subCount; $j++) {
$values[] = $rawAttributes[$attribute][$j];
}
$attributes[$attribute] = $values;
}
$object = new Object($dn, $attributes);
return $object;
}
示例3: ldap
/**
* Authenticates a user to LDAP
*
* @param $username
* @param $password
* @param bool|false $returnUser
* @return bool true if the username and/or password provided are valid
* false if the username and/or password provided are invalid
* array of ldap_attributes if $returnUser is true
*/
function ldap($username, $password, $returnUser = false)
{
$ldaphost = Setting::getSettings()->ldap_server;
$ldaprdn = Setting::getSettings()->ldap_uname;
$ldappass = Crypt::decrypt(Setting::getSettings()->ldap_pword);
$baseDn = Setting::getSettings()->ldap_basedn;
$filterQuery = Setting::getSettings()->ldap_auth_filter_query . $username;
$ldapversion = Setting::getSettings()->ldap_version;
// Connecting to LDAP
$connection = ldap_connect($ldaphost) or die("Could not connect to {$ldaphost}");
// Needed for AD
ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldapversion);
try {
if ($connection) {
// binding to ldap server
$ldapbind = ldap_bind($connection, $ldaprdn, $ldappass);
if (($results = @ldap_search($connection, $baseDn, $filterQuery)) != false) {
$entry = ldap_first_entry($connection, $results);
if (($userDn = @ldap_get_dn($connection, $entry)) !== false) {
if (($isBound = ldap_bind($connection, $userDn, $password)) == "true") {
return $returnUser ? array_change_key_case(ldap_get_attributes($connection, $entry), CASE_LOWER) : true;
}
}
}
}
} catch (Exception $e) {
LOG::error($e->getMessage());
}
ldap_close($connection);
return false;
}
示例4: findAndBindUserLdap
/**
* Binds/authenticates the user to LDAP, and returns their attributes.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v3.0]
* @param $username
* @param $password
* @param bool|false $user
* @return bool true if the username and/or password provided are valid
* false if the username and/or password provided are invalid
* array of ldap_attributes if $user is true
*
*/
static function findAndBindUserLdap($username, $password)
{
$settings = Setting::getSettings();
$connection = Ldap::connectToLdap();
$ldap_username_field = $settings->ldap_username_field;
$baseDn = $settings->ldap_basedn;
if ($settings->is_ad == '1') {
// In case they haven't added an AD domain
if ($settings->ad_domain == '') {
$userDn = $username . '@' . $settings->email_domain;
} else {
$userDn = $username . '@' . $settings->ad_domain;
}
} else {
$userDn = $ldap_username_field . '=' . $username . ',' . $settings->ldap_basedn;
}
$filterQuery = $settings->ldap_auth_filter_query . $username;
if (!($ldapbind = @ldap_bind($connection, $userDn, $password))) {
return false;
}
if (!($results = ldap_search($connection, $baseDn, $filterQuery))) {
throw new Exception('Could not search LDAP: ');
}
if (!($entry = ldap_first_entry($connection, $results))) {
return false;
}
if (!($user = array_change_key_case(ldap_get_attributes($connection, $entry), CASE_LOWER))) {
return false;
}
return $user;
}
示例5: readFromLdapEntry
private static function readFromLdapEntry($ldapconn, $entry)
{
$newUser = new User();
$newUser->dn = ldap_get_dn($ldapconn, $entry);
// Load attributes
$att = ldap_get_attributes($ldapconn, $entry);
if (isset($att['cn']) && $att['cn']['count'] == 1) {
$newUser->cn = $att['cn'][0];
}
if (isset($att['mail']) && $att['mail']['count'] == 1) {
$newUser->mail = $att['mail'][0];
}
if (isset($att['displayName']) && $att['displayName']['count'] == 1) {
$newUser->displayName = $att['displayName'][0];
}
if (isset($att['sn']) && $att['sn']['count'] == 1) {
$newUser->sn = $att['sn'][0];
}
if (isset($att['givenName']) && $att['givenName']['count'] == 1) {
$newUser->givenName = $att['givenName'][0];
}
$groups = [];
if (isset($att['memberOf'])) {
for ($i = 0; $i < $att['memberOf']['count']; $i++) {
$groups[] = $att['memberOf'][$i];
}
}
$newUser->group_dns = $groups;
$newUser->ldapconn = $ldapconn;
return $newUser;
}
示例6: get_user_old_ldap
function get_user_old_ldap($email)
{
$attributes = ["uid" => "uid", "mail" => "mail", "givenName" => "firstname", "sn" => "lastname", "displayName" => "nick", "gender" => "gender", "birthdate" => "dob", "o" => "organization", "c" => "country", "l" => "location"];
$this->load_library("ldap_lib", "ldap");
$ds = $this->ldap->get_link();
$dn = "dc=felicity,dc=iiit,dc=ac,dc=in";
$filter = '(&(mail=' . $email . '))';
$sr = ldap_search($ds, $dn, $filter, array_keys($attributes));
$entry = ldap_first_entry($ds, $sr);
if (!$entry) {
return false;
}
$entry_data = ldap_get_attributes($ds, $entry);
$user_data = [];
foreach ($attributes as $key => $value) {
if (isset($entry_data[$key]) && isset($entry_data[$key][0])) {
$user_data[$value] = $entry_data[$key][0];
}
}
if (isset($user_data["dob"])) {
$date = date_create_from_format('d/m/Y', $user_data["dob"]);
if ($date) {
$user_data["dob"] = date_format($date, "Y-m-d");
}
}
if (isset($user_data["firstname"]) && isset($user_data["lastname"])) {
$user_data["name"] = implode(" ", [$user_data["firstname"], $user_data["lastname"]]);
unset($user_data["firstname"]);
unset($user_data["lastname"]);
}
if (isset($user_data["gender"])) {
$user_data["gender"] = strtolower($user_data["gender"]);
}
return $user_data;
}
示例7: readAttribute
/**
* @brief reads a given attribute for an LDAP record identified by a DN
* @param $dn the record in question
* @param $attr the attribute that shall be retrieved
* @returns the values in an array on success, false otherwise
*
* Reads an attribute from an LDAP entry
*/
public function readAttribute($dn, $attr)
{
if (!$this->checkConnection()) {
\OCP\Util::writeLog('user_ldap', 'No LDAP Connector assigned, access impossible for readAttribute.', \OCP\Util::WARN);
return false;
}
$cr = $this->connection->getConnectionResource();
if (!is_resource($cr)) {
//LDAP not available
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
return false;
}
$rr = @ldap_read($cr, $dn, 'objectClass=*', array($attr));
if (!is_resource($rr)) {
\OCP\Util::writeLog('user_ldap', 'readAttribute ' . $attr . ' failed for DN ' . $dn, \OCP\Util::DEBUG);
//in case an error occurs , e.g. object does not exist
return false;
}
$er = ldap_first_entry($cr, $rr);
//LDAP attributes are not case sensitive
$result = \OCP\Util::mb_array_change_key_case(ldap_get_attributes($cr, $er), MB_CASE_LOWER, 'UTF-8');
$attr = mb_strtolower($attr, 'UTF-8');
if (isset($result[$attr]) && $result[$attr]['count'] > 0) {
$values = array();
for ($i = 0; $i < $result[$attr]['count']; $i++) {
$values[] = $this->resemblesDN($attr) ? $this->sanitizeDN($result[$attr][$i]) : $result[$attr][$i];
}
return $values;
}
\OCP\Util::writeLog('user_ldap', 'Requested attribute ' . $attr . ' not found for ' . $dn, \OCP\Util::DEBUG);
return false;
}
示例8: setEntry
private function setEntry($entry)
{
if ($entry) {
$this->_current_entry = $entry;
$row = ldap_get_attributes($this->_link, $entry);
$row["dn"] = ldap_get_dn($this->_link, $entry);
return $row;
}
}
示例9: current
/**
* Fetches the current entry.
*
* @return Entry
*/
public function current()
{
$attributes = ldap_get_attributes($this->connection, $this->current);
if (false === $attributes) {
throw new LdapException(sprintf('Could not fetch attributes: %s', ldap_error($this->connection)));
}
$dn = ldap_get_dn($this->connection, $this->current);
if (false === $dn) {
throw new LdapException(sprintf('Could not fetch DN: %s', ldap_error($this->connection)));
}
return new Entry($dn, $attributes);
}
示例10: getAttributes
/**
* Retrieves entry attributes
*
* @return array(attribute => array(values))
*/
public function getAttributes()
{
$data = @ldap_get_attributes($this->connection, $this->entry);
$result = array();
for ($i = 0; $i < $data['count']; $i++) {
$key = $data[$i];
$result[$key] = array();
for ($j = 0; $j < $data[$key]['count']; $j++) {
$result[$key][] = $data[$key][$j];
}
}
return $result;
}
示例11: getSingleEntry
private function getSingleEntry($con, $current)
{
$attributes = ldap_get_attributes($con, $current);
if (false === $attributes) {
throw new LdapException(sprintf('Could not fetch attributes: %s', ldap_error($con)));
}
$attributes = $this->cleanupAttributes($attributes);
$dn = ldap_get_dn($con, $current);
if (false === $dn) {
throw new LdapException(sprintf('Could not fetch DN: %s', ldap_error($con)));
}
return new Entry($dn, $attributes);
}
示例12: get_attributes
/**
* fetches all attributes
*
* @return array NodeAttributes
*/
public final function get_attributes()
{
if ($this->get_changed()) {
$this->refresh_entry();
}
$data = ldap_get_attributes($this->get_ldapconn()->get_conn(), $this->get_entry());
$result = array();
for ($i = 0; $i < $data['count']; $i++) {
$key = $data[$i];
$result[] = $this->get_attribute($key);
}
return $result;
}
示例13: readAttribute
/**
* @brief reads a given attribute for an LDAP record identified by a DN
* @param $dn the record in question
* @param $attr the attribute that shall be retrieved
* if empty, just check the record's existence
* @returns an array of values on success or an empty
* array if $attr is empty, false otherwise
*
* Reads an attribute from an LDAP entry or check if entry exists
*/
public function readAttribute($dn, $attr, $filter = 'objectClass=*')
{
if (!$this->checkConnection()) {
\OCP\Util::writeLog('user_ldap', 'No LDAP Connector assigned, access impossible for readAttribute.', \OCP\Util::WARN);
return false;
}
$cr = $this->connection->getConnectionResource();
if (!is_resource($cr)) {
//LDAP not available
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
return false;
}
$dn = $this->DNasBaseParameter($dn);
$rr = @ldap_read($cr, $dn, $filter, array($attr));
if (!is_resource($rr)) {
if (!empty($attr)) {
//do not throw this message on userExists check, irritates
\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG);
}
//in case an error occurs , e.g. object does not exist
return false;
}
if (empty($attr)) {
\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG);
return array();
}
$er = ldap_first_entry($cr, $rr);
if (!is_resource($er)) {
//did not match the filter, return false
return false;
}
//LDAP attributes are not case sensitive
$result = \OCP\Util::mb_array_change_key_case(ldap_get_attributes($cr, $er), MB_CASE_LOWER, 'UTF-8');
$attr = mb_strtolower($attr, 'UTF-8');
if (isset($result[$attr]) && $result[$attr]['count'] > 0) {
$values = array();
for ($i = 0; $i < $result[$attr]['count']; $i++) {
if ($this->resemblesDN($attr)) {
$values[] = $this->sanitizeDN($result[$attr][$i]);
} elseif (strtolower($attr) == 'objectguid' || strtolower($attr) == 'guid') {
$values[] = $this->convertObjectGUID2Str($result[$attr][$i]);
} else {
$values[] = $result[$attr][$i];
}
}
return $values;
}
\OCP\Util::writeLog('user_ldap', 'Requested attribute ' . $attr . ' not found for ' . $dn, \OCP\Util::DEBUG);
return false;
}
示例14: search
protected function search($ldap, $user)
{
$srch = ldap_search($ldap, 'DC=' . implode(',DC=', explode('.', $this->domain)), '(&(objectclass=person)(|(userprincipalname=' . $user . ')(distinguishedname=' . $user . '))(!(userAccountControl:1.2.840.113556.1.4.803:=2)))');
$data = ldap_first_entry($ldap, $srch);
if (!$data) {
return null;
}
$temp = [];
foreach (ldap_get_attributes($ldap, $data) as $k => $v) {
if ($v && isset($v['count']) && $v['count'] === 1) {
$temp[$k] = $v[0];
}
}
return $temp;
}
示例15: ldap_flatresults
function ldap_flatresults($ad, $sr, $key = false)
{
for ($entry = ldap_first_entry($ad, $sr); $entry != false; $entry = ldap_next_entry($ad, $entry)) {
$user = array();
$attributes = ldap_get_attributes($ad, $entry);
for ($i = $attributes['count']; $i-- > 0;) {
$user[strtolower($attributes[$i])] = $attributes[$attributes[$i]][0];
}
if ($key && $user[$key]) {
$users[strtolower($user[$key])] = $user;
} else {
$users[] = $user;
}
}
return $users;
}