\Auth42

A simple abstract layer to use ldap in order to manage 42 authentications.

Summary

Methods
Properties
Constants
__construct()
bind()
search()
authenticate()
addOrReplaceDn()
removeDn()
getDn()
getBind()
getPassword()
getHandle()
setDn()
setBind()
setPassword()
setHandle()
No public properties found
serverUrl
bindOnHandle()
computeDn()
$dn
$bind
$password
$handle
N/A
No private methods found
No private properties found
N/A

Constants

serverUrl

serverUrl

Properties

$dn

$dn

$bind

$bind

$password

$password

$handle

$handle

Methods

__construct()

__construct(array $dn, string $password)

Will construct a new Auth42 object, wich is a ldap based search and authentication tool.

Parameters

array $dn

the dn to use. If no dn is provided, will use ou=2013,ou=people,dc=42,dc=fr as the default dn.

string $password

an optionnal password to connect with.

bind()

bind() : int

Will try to bind the ldap with the previously given dn and password.

At the end, will close the ldap_handle.

Throws

\Auth42Exception

Returns

int —

the binding result (0 on failure).

search()

search(string $query, string $login, string $password, string $filter) : array

Will try to search the given query on the ldap.

if a login and a password are supplied, will try to bind the ldap with theses id before the request. On failure, will throw an Auth42Exception. If no filter is supplied, the default filter ("dc=42,dc=fr") is applied.

Parameters

string $query

the query to execute, like 'uid=a*'.

string $login

an optionnal login to bind the server.

string $password

an optionnal password to bind the server.

string $filter

a filter to apply on the search request. Default: "dc=42,dc=fr".

Throws

\Auth42Exception

when the auth fail.

Returns

array —

the search result(s), or false on failure.

authenticate()

authenticate(string $login, string $password) : boolean

Will try to authenticate the user on the 42 ldap with the given password and username.

Parameters

string $login

the login (uid) of the student

string $password

the password of the student

Returns

boolean —

true on success, false otherwise.

addOrReplaceDn()

addOrReplaceDn(string $key, string|array $value)

Will add (or replace) the value of the given key with the given (new) value(s). If there is more than one value to add, use an array instead of a string.

Parameters

string $key

the key to add / replace.

string|array $value

the value(s) to add.

removeDn()

removeDn(string $key)

Remove the given dn key of the current instance.

Parameters

string $key

the dn to remove.

getDn()

getDn()

getBind()

getBind()

getPassword()

getPassword()

getHandle()

getHandle()

setDn()

setDn( $dn)

Parameters

$dn

setBind()

setBind( $bind)

Parameters

$bind

setPassword()

setPassword( $password)

Parameters

$password

setHandle()

setHandle( $handle)

Parameters

$handle

bindOnHandle()

bindOnHandle() : int

Will try to bind the ldap with the registered informations.

This function will not automatically close the ldap handle.

Throws

\Auth42Exception

Returns

int —

the binding result (0 on failure).

computeDn()

computeDn() : string

Will convert the arrays of dn into an undersandable string.

Returns

string —

a string with all the dn(s).