PHP Class SimpleSAML_Auth_LDAP, simplesamlphp

Author: Andreas Aakre Solberg, UNINETT AS. ([email protected])
Author: Anders Lund, UNINETT AS. ([email protected])
显示文件 Open project: simplesamlphp/simplesamlphp Class Usage Examples

Protected Properties

Property Type Description
$authz_id LDAP user: authz_id if SASL is in use, binding dn otherwise
$ldap resource LDAP link identifier.
$timeout integer Timeout value, in seconds.

Public Methods

Method Description
__construct ( $hostname, $enable_tls = true, $debug = false, $timeout, $port = 389, $referrals = true ) TODO: Flesh out documentation
asc2hex32 ( string $string ) : string Borrowed function from PEAR:LDAP.
bind ( string $dn, string $password, array $sasl_args = null ) : boolean Bind to LDAP with a specific DN and password. Simple wrapper around ldap_bind() with some additional logging.
escape_filter_value ( array $values = [], $singleValue = true ) : array Borrowed function from PEAR:LDAP.
getAttributes ( string $dn, string | array $attributes = null, integer $maxsize = null ) : array Search a given DN for attributes, and return the resulting associative array.
searchfordn ( string | array $base, string | array $attribute, string $value, boolean $allowZeroHits = false, $searchFilter = null ) : string Search for a DN.
searchformultiple ( string | array $bases, string | array $filters, string | array $attributes = [], boolean $and = true, boolean $escape = true ) : array This method was created specifically for the ldap:AttributeAddUsersGroups->searchActiveDirectory() method, but could be used for other LDAP search needs. It will search LDAP and return all the entries.
setOption ( $option, $value ) : void Applies an LDAP option to the current connection.
validate ( $config, $username, $password = null ) TODO: Documentation; only cleared up exception/log messages
whoami ( $searchBase, $searchAttributes ) ldap_exop_whoami accessor, if available. Use requested authz_id otherwise.

Private Methods

Method Description
authzid_to_dn ( $searchBase, $searchAttributes, $authz_id ) Convert SASL authz_id into a DN
makeException ( string $description, $type = null ) : Exception Convenience method to create an LDAPException as well as log the description.
search ( string $base, string | array $attribute, string $value, $searchFilter = null ) : string Search for DN from a single base.

Method Details

__construct() public method

TODO: Flesh out documentation
public __construct ( $hostname, $enable_tls = true, $debug = false, $timeout, $port = 389, $referrals = true )

asc2hex32() public static method

Converts all ASCII chars < 32 to "\HEX"
public static asc2hex32 ( string $string ) : string
$string string String to convert
return string

bind() public method

Bind to LDAP with a specific DN and password. Simple wrapper around ldap_bind() with some additional logging.
public bind ( string $dn, string $password, array $sasl_args = null ) : boolean
$dn string The DN used.
$password string The password used.
$sasl_args array Array of SASL options for SASL bind
return boolean Returns TRUE if successful, FALSE if LDAP_INVALID_CREDENTIALS, LDAP_X_PROXY_AUTHZ_FAILURE, LDAP_INAPPROPRIATE_AUTH, LDAP_INSUFFICIENT_ACCESS

escape_filter_value() public static method

Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters. Any control characters with an ACII code < 32 as well as the characters with special meaning in LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a backslash followed by two hex digits representing the hexadecimal value of the character.
public static escape_filter_value ( array $values = [], $singleValue = true ) : array
$values array Array of values to escape
return array Array $values, but escaped

getAttributes() public method

Search a given DN for attributes, and return the resulting associative array.
See also: http://no.php.net/manual/en/function.ldap-read.php
public getAttributes ( string $dn, string | array $attributes = null, integer $maxsize = null ) : array
$dn string The DN of an element.
$attributes string | array The names of the attribute(s) to retrieve. Defaults to NULL; that is, all available attributes. Note that this is not very effective.
$maxsize integer The maximum size of any attribute's value(s). If exceeded, the attribute will not be returned.
return array The array of attributes and their values.

searchfordn() public method

Search for a DN.
public searchfordn ( string | array $base, string | array $attribute, string $value, boolean $allowZeroHits = false, $searchFilter = null ) : string
$base string | array The base, or bases, which to search from.
$attribute string | array The attribute name(s) searched for.
$value string The attribute value searched for.
$allowZeroHits boolean Determines if the method will throw an exception if no hits are found. Defaults to FALSE.
return string The DN of the matching element, if found. If no element was found and $allowZeroHits is set to FALSE, an exception will be thrown; otherwise NULL will be returned.

searchformultiple() public method

This method was created specifically for the ldap:AttributeAddUsersGroups->searchActiveDirectory() method, but could be used for other LDAP search needs. It will search LDAP and return all the entries.
public searchformultiple ( string | array $bases, string | array $filters, string | array $attributes = [], boolean $and = true, boolean $escape = true ) : array
$bases string | array
$filters string | array Array of 'attribute' => 'values' to be combined into the filter, or a raw filter string
$attributes string | array Array of attributes requested from LDAP
$and boolean If multiple filters defined, then either bind them with & or |
$escape boolean Weather to escape the filter values or not
return array

setOption() public method

Applies an LDAP option to the current connection.
public setOption ( $option, $value ) : void
$option
$value
return void

validate() public method

TODO: Documentation; only cleared up exception/log messages
public validate ( $config, $username, $password = null )

whoami() public method

ldap_exop_whoami is not yet included in PHP. For reference, the feature request: http://bugs.php.net/bug.php?id=42060 And the patch against lastest PHP release: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/databases/php-ldap/files/ldap-ctrl-exop.patch
public whoami ( $searchBase, $searchAttributes )

Property Details

$authz_id protected_oe property

LDAP user: authz_id if SASL is in use, binding dn otherwise
protected $authz_id

$ldap protected_oe property

LDAP link identifier.
protected resource $ldap
return resource

$timeout protected_oe property

Timeout value, in seconds.
protected int $timeout
return integer