Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
ldap
Commits
d7dd5347
Commit
d7dd5347
authored
Nov 28, 2018
by
David Surville
Browse files
- Développement d'interfaces autour des fonctions
- Refonte Css/Html de l'application - Formatage de code
parent
0af6a8e2
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
config/unicaen-ldap.local.php.dist
View file @
d7dd5347
<?php
return
array
(
'unicaen-ldap'
=>
array
(
'host'
=>
'host.domain.fr'
,
'port'
=>
389
,
'version'
=>
3
,
'baseDn'
=>
"
ou=xxxxxxxxxxx,
dc=domain,dc=fr"
,
'bindRequiresDn'
=>
true
,
'username'
=>
"uid=xxxxxxxxx,ou=xxxxxxxxxx,dc=domain,dc=fr"
,
'password'
=>
"xxxxxxxxxxxx"
,
'accountFilterFormat'
=>
"(&(objectClass=posixAccount)(supannAliasLogin=%s))"
,
)
)
;
return
[
'unicaen-ldap'
=>
[
'host'
=>
'host.domain.fr'
,
'port'
=>
389
,
'version'
=>
3
,
'baseDn'
=>
"dc=domain,dc=fr"
,
// racine de l'annuaire
'bindRequiresDn'
=>
true
,
'username'
=>
"uid=xxxxxxxxx,ou=xxxxxxxxxx,dc=domain,dc=fr"
,
'password'
=>
"xxxxxxxxxxxx"
,
'accountFilterFormat'
=>
"(&(objectClass=posixAccount)(supannAliasLogin=%s))"
,
]
]
;
src/UnicaenLdap/Entity/Base/People.php
View file @
d7dd5347
This diff is collapsed.
Click to expand it.
src/UnicaenLdap/Entity/Base/Structure.php
0 → 100644
View file @
d7dd5347
<?php
namespace
UnicaenLdap\Entity\Base
;
use
UnicaenLdap\Entity\Entity
;
/**
* Classe mère des entités de la branche "structures" de l'annuaire LDAP.
*
* @author David Surville <david.surville@unicaen.fr>
*/
class
Structure
extends
Entity
{
protected
$type
=
'Structure'
;
/**
* Liste des classes d'objet nécessaires à la création d'une structure
*
* @var string[]
*/
protected
$objectClass
=
[
'top'
,
'organizationalUnit'
,
'supannEntite'
,
'ucbnEntite'
,
];
/**
* Liste des attributs contenant des dates
*
* @var array
*/
protected
$dateTimeAttributes
=
[];
/**
* Liste des attributs monovalués
*
* @var array
*/
protected
$monoValuedAttributes
=
[];
}
\ No newline at end of file
src/UnicaenLdap/Entity/Entity.php
View file @
d7dd5347
...
...
@@ -5,6 +5,7 @@ namespace UnicaenLdap\Entity;
use
UnicaenLdap\Node
;
use
UnicaenLdap\Exception
;
use
UnicaenLdap\Service\AbstractService
;
use
UnicaenLdap\Util
;
use
Zend\Ldap\Dn
;
use
Zend\Ldap\Exception\LdapException
;
...
...
@@ -15,6 +16,8 @@ use Zend\Ldap\Exception\LdapException;
*/
abstract
class
Entity
{
static
protected
$etablissement_domaine
=
'unicaen.fr'
;
/**
* Type d'entité
*
...
...
@@ -42,37 +45,18 @@ abstract class Entity
protected
$objectClass
=
[];
/**
* Liste des
labels utilisés dans les différent
s at
tribut
s
* Liste des
attributs contenant de
s
d
at
e
s
*
* @var array
*/
// protected $labels = [
// 'AUTRE' => 'AUTRE', // Texte libre
// 'BAP' => 'BAP', // Branche d'Activité Professionnelle REFERENS
// 'CNRS' => 'CNRS', // LABINTEL (CNRS)
// 'CNU' => 'CNU', // Section CNU
// 'INRA' => 'INRA', // INRA
// 'INRIA' => 'INRIA', // INRIA
// 'INSERM' => 'INSERM', // INSERM
// 'NCORPS' => 'NCORPS', // BCN: code issu de la colonne “CORPS” de la table “N_CORPS” du domaine “Gestion du personnel”
// 'REFERENS' => 'REFERENS', // Emploi-type REFERENS
// 'SAML' => 'SAML', // Fédération d'identités
// 'SILLAND' => 'SILLAND', // Fonction SILLAND
// 'SIRET' => 'SIRET', // SIRET (INSEE)
// 'SISE' => 'SISE', // BCN: valeur “DIPLOME SISE” de la table N_DIPLOME_SISE
// 'SUPANN' => 'SUPANN', // Label nomenclatures SupAnn
// 'TVA' => 'TVA', // Union Européenne
// 'UAI' => 'UAI', // Unité Administrative Immatriculée (UAI)
// 'UAI_ETABLISSEMENT' => 'UAI:%s',
//
// ];
protected
$dateTimeAttributes
=
[];
/**
* Liste des attributs
c
on
tenant des date
s
* Liste des attributs
m
on
ovalué
s
*
* @var array
*/
protected
$
dateTime
Attributes
=
[];
protected
$
monoValued
Attributes
=
[];
/**
...
...
@@ -113,7 +97,7 @@ abstract class Entity
}
/**
* Retourne le type d
u service
* Retourne le type d
e l'entité
*
* @return string
*/
...
...
@@ -152,17 +136,6 @@ abstract class Entity
$this
->
node
=
$node
;
}
/**
* Retourne un label en fonction d'une clé
*
* @param $key
* @return null|string
*/
// public function getLabel($key)
// {
// return $this->labels[$key];
// }
/**
* Retourne le Dn de l'entité sous forme de chaîne de caractères
*
...
...
@@ -174,7 +147,7 @@ abstract class Entity
}
/**
* Retourne la clé primaire correspondant à l'entité
* Retourne
le nom de
la clé primaire correspondant à l'entité
*
* @return mixed
* @throws Exception
...
...
@@ -196,6 +169,17 @@ abstract class Entity
return
$this
->
get
(
$this
->
getKey
());
}
/**
* Retourne l'attribut "objectClass"
*
* @return array|int|mixed|null
* @throws LdapException
*/
public
function
getObjectClass
()
{
return
$this
->
get
(
'objectClass'
);
}
/**
* Retourne la liste des attributs de l'entité
*
...
...
@@ -206,6 +190,27 @@ abstract class Entity
return
array_keys
(
$this
->
getNode
()
->
getAttributes
());
}
/**
* Retourne un label constitué des différentes clés passées en paramètre
* Format : {$key1:$key2:$key3:...}
*
* @param string ...$key
* @return string
*/
public
function
getLabel
(...
$key
)
{
$label
=
''
;
$c
=
0
;
foreach
(
$key
as
$k
)
{
if
(
is_string
(
$k
))
{
$label
.
=
(
$c
==
0
)
?
$k
:
":
$k
"
;
}
$c
++
;
}
return
sprintf
(
'{%s}'
,
$label
);
}
/**
* Exporte sous forme de tableau le contenu de l'entité
*
...
...
@@ -252,10 +257,17 @@ abstract class Entity
* @param string $attrName
* @param mixed $value
* @return self
* @throws Exception
* @throws LdapException
*/
public
function
set
(
$attrName
,
$value
)
{
if
(
is_array
(
$value
)
&&
count
(
$value
)
>
1
&&
in_array
(
$attrName
,
$this
->
monoValuedAttributes
))
{
throw
new
Exception
(
sprintf
(
"L'attribut Ldap '%s' est monovalué et ne doit contenir qu'une seule valeur."
,
$attrName
));
}
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
))
{
$this
->
getNode
()
->
setDateTimeAttribute
(
$attrName
,
$value
,
true
);
}
else
{
...
...
@@ -279,21 +291,28 @@ abstract class Entity
/**
* Ajoute une valeur à un attribut
* Si l'attribut est monovalué, la valeur actuelle est remplacée par la nouvelle valeur
*
* @param string $attrName
* @param mixed $value
* @return self
* @throws Exception
* @throws LdapException
*/
public
function
add
(
$attrName
,
$value
)
{
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
))
{
$this
->
getNode
()
->
appendToDateTimeAttribute
(
$attrName
,
$value
);
}
else
{
$this
->
getNode
()
->
appendToAttribute
(
$attrName
,
$value
);
if
(
in_array
(
$attrName
,
$this
->
monoValuedAttributes
))
{
$this
->
set
(
$attrName
,
$value
);
}
else
{
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
))
{
$this
->
getNode
()
->
appendToDateTimeAttribute
(
$attrName
,
$value
);
}
else
{
$this
->
getNode
()
->
appendToAttribute
(
$attrName
,
$value
);
}
return
$this
;
return
$this
;
}
}
/**
...
...
@@ -394,13 +413,70 @@ abstract class Entity
}
/**
*
Retourne l'attribut "objectClass"
*
Formate un nom ou un prénom
*
* @return array|int|mixed|null
* @throws LdapException
* @param string $name
* @param bool $removeAccents remplace les caractères avec un signe diacritique
* @return mixed|null|string|string[]
*/
p
ublic
function
getObjectClass
(
)
p
rotected
function
formatName
(
$name
,
$removeAccents
=
false
)
{
return
$this
->
get
(
'objectClass'
);
$name
=
preg_replace
(
'/[[:blank:]]+/'
,
' '
,
trim
(
$name
));
if
(
$removeAccents
)
{
$name
=
Util
::
removeAccents
(
$name
);
}
return
mb_convert_case
(
$name
,
MB_CASE_TITLE
,
"UTF-8"
);
}
/**
* Formate un numéro de téléphone (0XXXXXXXXX) au format international (+33 X XX XX XX XX)
*
* @param string $num
* @return string
*/
protected
function
formatTel
(
$num
)
{
if
(
is_null
(
$num
))
{
return
null
;
}
$num
=
preg_replace
(
'/\s+/'
,
''
,
$num
);
return
preg_match
(
"/0\d
{
9
}
/"
,
$num
)
?
preg_replace
(
"/0(\d
{
1})(\d{2})(\d{2})(\d{2})(\d{2
}
)/"
,
"+33 $1 $2 $3 $4 $5"
,
$num
)
:
$num
;
}
/**
* Formate les données sources correspondant à un booléen
*
* @param mixed $value
* @return string
*/
protected
function
formatBoolean
(
$value
)
{
if
(
!
is_bool
(
$value
)
&&
$value
===
null
)
{
return
null
;
}
if
(
is_string
(
$value
))
{
$value
=
strtolower
(
$value
);
}
switch
(
true
)
{
case
$value
===
false
;
case
$value
===
0
:
case
$value
===
'n'
:
return
'FALSE'
;
case
$value
===
true
:
case
$value
===
1
:
case
$value
===
'o'
:
case
$value
===
'y'
:
return
'TRUE'
;
default
:
return
null
;
}
}
}
\ No newline at end of file
src/UnicaenLdap/Entity/People.php
View file @
d7dd5347
...
...
@@ -6,15 +6,14 @@ use UnicaenLdap\Entity\Base\People as BasePeople;
use
DateTime
;
/**
* Classe
mère des
people de l'annuaire LDAP.
* Classe
de gestion des entités de la branche "
people
"
de l'annuaire LDAP.
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
* @author David SURVILLE <david.surville@unicaen.fr>
*/
class
People
extends
BasePeople
{
static
protected
$role_pattern
=
'/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'
;
/**
* Liste des rôles existants
*
...
...
@@ -87,7 +86,7 @@ class People extends BasePeople
*/
public
function
getOu
()
{
if
(
$result
=
$this
->
getNode
()
->
getDn
()
->
get
(
1
))
{
if
(
$result
=
$this
->
getDn
()
->
get
(
1
))
{
return
$result
[
'ou'
];
}
...
...
src/UnicaenLdap/Entity/Structure.php
View file @
d7dd5347
...
...
@@ -2,38 +2,18 @@
namespace
UnicaenLdap\Entity
;
use
UnicaenLdap\Entity\Base\Structure
as
BaseStructure
;
use
UnicaenLdap\Filter\Filter
;
use
Zend\Ldap\Exception\LdapException
;
/**
* Classe
mère des
structures de l'annuaire LDAP.
* Classe
de gestion des entités de la branche "
structures
"
de l'annuaire LDAP.
*
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
* @author David SURVILLE <david.surville@unicaen.fr>
*/
class
Structure
extends
Entity
class
Structure
extends
BaseStructure
{
protected
$type
=
'Structure'
;
/**
* Liste des classes d'objet nécessaires à la création d'une structure
*
* @var string[]
*/
protected
$objectClass
=
[
'top'
,
'organizationalUnit'
,
'supannEntite'
,
'ucbnEntite'
,
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected
$dateTimeAttributes
=
[
];
/**
* Retourne la structure parente, si elle existe
*
...
...
@@ -70,17 +50,14 @@ class Structure extends Entity
}
/**
* Retourne le code
Harpèg
e
* Retourne le code
de la base sourc
e
*
* @return string
* @throws LdapException
*/
public
function
getCode
Harpeg
e
()
public
function
getCode
Sourc
e
()
{
$code
=
$this
->
get
(
'supannCodeEntite'
);
if
(
0
===
strpos
(
$code
,
'HS_'
))
{
return
substr
(
$code
,
3
);
}
else
{
return
null
;
// Ne retourne rien si le code ne correspond pas à la nomenclature Harpège
}
return
(
0
===
strpos
(
$code
,
'HS_'
))
?
substr
(
$code
,
3
)
:
$code
;
}
}
\ No newline at end of file
src/UnicaenLdap/Service/AbstractService.php
View file @
d7dd5347
...
...
@@ -8,8 +8,6 @@ use UnicaenLdap\Exception;
use
UnicaenLdap\Collection
;
use
UnicaenLdap\Filter\Filter
;
use
Zend\ServiceManager\ServiceLocatorAwareTrait
;
use
Zend\ServiceManager\ServiceManager
;
use
Zend\ServiceManager\ServiceManagerAwareInterface
;
use
Zend\Ldap\Filter\AbstractFilter
;
use
Zend\Ldap\Dn
;
use
Zend\Stdlib\ErrorHandler
;
...
...
@@ -39,6 +37,7 @@ abstract class AbstractService
protected
$ldap
;
/**
* Type de l'entité
*
* @var string
*/
...
...
@@ -47,25 +46,24 @@ abstract class AbstractService
/**
* Organizational Units
*
* @var
string[]
* @var
array
*/
protected
$ou
=
array
()
;
protected
$ou
=
[]
;
/**
* Préfixe utilisé pour le code des structures
*
* @var
integer
* @var
string
*/
protected
$co
unt
;
protected
$co
de_structure_prefixe
=
'HS_'
;
/**
*
Retourne le type du servic
e
*
* @
return string
*
Compteur utilisé dans la recherch
e
*
* @
var integer
*/
public
function
getType
()
{
return
$this
->
type
;
}
protected
$count
;
/**
* Retourne l'objet d'accès à l'annuaire LDAP.
...
...
@@ -92,10 +90,20 @@ abstract class AbstractService
return
$this
;
}
/**
* Retourne le type du service
*
* @return string
*/
public
function
getType
()
{
return
$this
->
type
;
}
/**
* Retourne la liste des organizational units
*
* @return
string[]
* @return
array
*/
public
function
getOu
()
{
...
...
@@ -103,17 +111,28 @@ abstract class AbstractService
}
/**
* Re
définie
la liste des organizational units
* Re
tourne la liste des branches liées à
la liste des organizational units
*
* @param string[] $ou
* @return AbstractService
* @return array
*/
public
function
s
et
Ou
(
array
$ou
)
public
function
g
et
Branches
(
)
{
$this
->
ou
=
$ou
;
return
$this
;
return
array_map
(
function
(
$v
)
{
return
sprintf
(
'ou=%s,%s'
,
$v
,
$this
->
getLdap
()
->
getBaseDn
());
},
$this
->
ou
);
}
/**
* Retourne le préfixe utilisé pour les codes des structures
*
* @return string
*/
public
function
getCodeStructurePrefixe
()
{
return
$this
->
code_structure_prefixe
;
}
/**
* Retourne la liste de toutes les entités correspondantes
*
...
...
@@ -142,7 +161,7 @@ abstract class AbstractService
if
(
$limit
<
0
)
$limit
=
3999999999
;
// Limite maximum à 4 milliard...
if
(
$offset
<
0
)
$offset
=
0
;
// Moins de zéro = impossible
list
(
$resource
,
$search
)
=
$this
->
__searchBegin
(
$filter
,
$this
->
ou
,
array
(
$key
,
$orderBy
)
);
list
(
$resource
,
$search
)
=
$this
->
__searchBegin
(
$filter
,
$this
->
ou
,
[
$key
,
$orderBy
]
);
ErrorHandler
::
start
(
E_WARNING
);
$this
->
count
=
ldap_count_entries
(
$resource
,
$search
);
...
...
src/UnicaenLdap/Service/Structure.php
View file @
d7dd5347
...
...
@@ -2,6 +2,9 @@
namespace
UnicaenLdap\Service
;
use
UnicaenLdap\Entity\Entity
;
use
UnicaenLdap\Entity\Structure
as
StructureEntity
;
/**
* Classe regroupant les opérations de recherche de structures dans l'annuaire LDAP.
*
...
...
@@ -9,17 +12,34 @@ namespace UnicaenLdap\Service;
*/
class
Structure
extends
AbstractService
{
/**
* Type de l'entité
*
* @var string
*/
protected
$type
=
'Structure'
;
protected
$ou
=
array
(
'structures'
);
/**
* Organizational Units
*
* @var array
*/
protected
$ou
=
[
'structures'
];
/**
* Code de la structure interne mère
*
* @var string
*/
protected
$codeStructureMere
=
'HS_UNIV'
;
/**
* Retourne la structure mère : Université
*
* @return
\UnicaenLdap\Entity\Structure
* @return
StructureEntity|Entity
*/
public
function
get
Univ
()
public
function
get
StructureMere
()
{
return
$this
->
get
(
'HS_UNIV'
);
return
$this
->
get
(
$this
->
codeStructureMere
);
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment