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
2e7eafcc
Commit
2e7eafcc
authored
Nov 29, 2016
by
Bertrand Gauthier
Browse files
Ajout filtrage people.
Déplacement config de Module vers module.config.php. Dépoussiérage. Code style.
parent
df1a06d4
Changes
28
Hide whitespace changes
Inline
Side-by-side
Module.php
View file @
2e7eafcc
...
...
@@ -4,16 +4,9 @@ namespace UnicaenLdap;
use
Zend\ModuleManager\Feature\AutoloaderProviderInterface
;
use
Zend\ModuleManager\Feature\ConfigProviderInterface
;
use
Zend\ModuleManager\Feature\ServiceProviderInterface
;
/**
*
*
* @author Laurent LECLUSE <laurent.lecluse at unicaen.fr>
*/
class
Module
implements
ConfigProviderInterface
,
ServiceProviderInterface
class
Module
implements
ConfigProviderInterface
{
/**
*
* @return array
...
...
@@ -42,39 +35,4 @@ class Module implements ConfigProviderInterface, ServiceProviderInterface
),
);
}
/**
*
* @return array
* @see ServiceProviderInterface
*/
public
function
getServiceConfig
()
{
$services
=
array
(
'Generic'
,
'Group'
,
'People'
,
'Structure'
,
'System'
);
$processus
=
array
(
);
$factories
=
array
(
'ldap'
=>
'UnicaenLdap\LdapFactory'
,
'ldapOptions'
=>
'UnicaenLdap\Options\ModuleOptionsFactory'
,
);
foreach
(
$services
as
$service
){
$factories
[
'ldapService'
.
$service
]
=
function
(
$sm
)
use
(
$service
){
$className
=
'UnicaenLdap\\Service\\'
.
$service
;
return
new
$className
;
};
}
foreach
(
$processus
as
$proc
){
$factories
[
'ldapProcessus'
.
$proc
]
=
function
(
$sm
)
use
(
$proc
){
$className
=
'UnicaenLdap\\Processus\\'
.
$proc
;
return
new
$className
;
};
}
return
array
(
'factories'
=>
$factories
,
);
}
}
}
\ No newline at end of file
config/module.config.php
View file @
2e7eafcc
<?php
$settings
=
array
(
);
use
UnicaenLdap\LdapFactory
;
use
UnicaenLdap\Options\ModuleOptionsFactory
;
use
UnicaenLdap\Service\Generic
as
GenericService
;
use
UnicaenLdap\Service\Group
as
GroupService
;
use
UnicaenLdap\Service\People
as
PeopleService
;
use
UnicaenLdap\Service\Structure
as
StructureService
;
use
UnicaenLdap\Service\System
as
SystemService
;
return
array
(
'unicaen-ldap'
=>
$settings
'unicaen-ldap'
=>
[
],
'service_manager'
=>
[
'invokables'
=>
[
'LdapServiceGeneric'
=>
GenericService
::
class
,
'LdapServiceGroup'
=>
GroupService
::
class
,
'LdapServicePeople'
=>
PeopleService
::
class
,
'LdapServiceStructure'
=>
StructureService
::
class
,
'LdapServiceSystem'
=>
SystemService
::
class
,
],
'factories'
=>
[
'Ldap'
=>
LdapFactory
::
class
,
'LdapOptions'
=>
ModuleOptionsFactory
::
class
,
],
],
);
src/UnicaenLdap/Collection.php
View file @
2e7eafcc
...
...
@@ -5,20 +5,16 @@ namespace UnicaenLdap;
use
Countable
;
use
Iterator
;
use
UnicaenLdap\Service\Service
;
use
UnicaenLdap\Service\
Abstract
Service
;
use
UnicaenLdap\Entity\Entity
;
/**
* Liste d'entités
*/
class
Collection
implements
Iterator
,
Countable
{
/**
*
*
* @var Service
* @var AbstractService
*/
private
$service
;
...
...
@@ -30,21 +26,18 @@ class Collection implements Iterator, Countable
private
$data
;
/**
*
* @var integer
*/
private
$index
=
0
;
/**
* Constructor.
*
* @param Service $service
* @param string[] $data
* @param
Abstract
Service $service
* @param string[]
$data
*/
public
function
__construct
(
Service
$service
,
array
$data
)
public
function
__construct
(
Abstract
Service
$service
,
array
$data
)
{
$this
->
service
=
$service
;
$this
->
data
=
$data
;
...
...
@@ -71,6 +64,7 @@ class Collection implements Iterator, Countable
public
function
current
()
{
$current
=
$this
->
data
[
$this
->
index
];
return
$this
->
service
->
get
(
$current
);
}
...
...
@@ -98,8 +92,6 @@ class Collection implements Iterator, Countable
/**
* Rewind the Iterator to the first result item
* Implements Iterator
*
* @throws Exception\LdapException
*/
public
function
rewind
()
{
...
...
src/UnicaenLdap/Entity/Entity.php
View file @
2e7eafcc
<?php
namespace
UnicaenLdap\Entity
;
use
UnicaenLdap\Node
;
use
UnicaenLdap\Exception
;
use
UnicaenLdap\Service\Service
;
use
UnicaenLdap\Service\
Abstract
Service
;
/**
* Classe mère des entrées de l'annuaire LDAP.
...
...
@@ -12,18 +13,17 @@ use UnicaenLdap\Service\Service;
*/
abstract
class
Entity
{
/**
* Type d'entité
*
*
* @var string
*/
protected
$type
;
/**
* Service qui gère l'entité
*
* @var Service
*
* @var
Abstract
Service
*/
protected
$service
;
...
...
@@ -31,54 +31,53 @@ abstract class Entity
* @var Node
*/
protected
$node
;
/**
* Liste des classes d'objet nécessaires à la création de l'entité
*
* @var string[]
*
* @var string[]
*/
protected
$objectClass
=
array
(
protected
$objectClass
=
[
)
;
]
;
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected
$dateTimeAttributes
=
array
(
);
protected
$dateTimeAttributes
=
[
];
public
static
function
getNodeParams
(
$type
)
{
$params
=
array
(
'Generic'
=>
array
(
'uid'
,
'UnicaenLdap\\Entity\\Generic'
),
'Group'
=>
array
(
'cn'
,
'UnicaenLdap\\Entity\\Group'
),
'People'
=>
array
(
'uid'
,
'UnicaenLdap\\Entity\\People'
),
'Structure'
=>
array
(
'supannCodeEntite'
,
'UnicaenLdap\\Entity\\Structure'
),
'System'
=>
array
(
'uid'
,
'UnicaenLdap\\Entity\\System'
),
);
if
(
!
isset
(
$params
[
$type
]))
throw
new
Exception
(
'Paramètres de "'
.
$type
.
'" non trouvés'
);
$params
=
[
'Generic'
=>
[
'uid'
,
'UnicaenLdap\\Entity\\Generic'
],
'Group'
=>
[
'cn'
,
'UnicaenLdap\\Entity\\Group'
],
'People'
=>
[
'uid'
,
'UnicaenLdap\\Entity\\People'
],
'Structure'
=>
[
'supannCodeEntite'
,
'UnicaenLdap\\Entity\\Structure'
],
'System'
=>
[
'uid'
,
'UnicaenLdap\\Entity\\System'
],
];
if
(
!
isset
(
$params
[
$type
]))
throw
new
Exception
(
'Paramètres de "'
.
$type
.
'" non trouvés'
);
return
$params
[
$type
];
}
/**
* Construit une entrée.
*
* @param Service $service Service qui gèrera la future entité
* @param Node|Dn|array|string $data Noeud si Node, sinon DN
* @param
Abstract
Service
$service Service qui gèrera la future entité
* @param Node|Dn|array|string $data
Noeud si Node, sinon DN
*/
public
function
__construct
(
Service
$service
,
$data
)
public
function
__construct
(
Abstract
Service
$service
,
$data
)
{
$this
->
service
=
$service
;
if
(
$data
instanceof
Node
){
$this
->
setNode
(
$data
);
}
else
{
$this
->
setNode
(
Node
::
create
(
$data
,
$this
->
objectClass
)
);
if
(
$data
instanceof
Node
)
{
$this
->
setNode
(
$data
);
}
else
{
$this
->
setNode
(
Node
::
create
(
$data
,
$this
->
objectClass
));
}
}
...
...
@@ -94,8 +93,8 @@ abstract class Entity
/**
* Retourne le service qui gère l'entité
*
* @return Service
*
* @return
Abstract
Service
*/
public
function
getService
()
{
...
...
@@ -114,10 +113,10 @@ abstract class Entity
/**
* Affecte un nœud de base
*
*
* @param Node $node
*/
public
function
setNode
(
Node
$node
)
public
function
setNode
(
Node
$node
)
{
$this
->
node
=
$node
;
}
...
...
@@ -140,6 +139,7 @@ abstract class Entity
public
function
getId
()
{
list
(
$key
)
=
self
::
getNodeParams
(
$this
->
type
);
return
$this
->
get
(
$key
);
}
...
...
@@ -170,22 +170,24 @@ abstract class Entity
*/
public
function
toArray
()
{
$result
=
array
()
;
$result
=
[]
;
$attrsList
=
$this
->
getAttributesList
();
foreach
(
$attrsList
as
$attrName
){
foreach
(
$attrsList
as
$attrName
)
{
$result
[
$attrName
]
=
$this
->
get
(
$attrName
);
}
return
$result
;
}
/**
* Mise à jour de l'entité
*
*
* @return self
*/
public
function
update
()
{
$this
->
getNode
()
->
update
();
return
$this
;
}
...
...
@@ -197,17 +199,19 @@ abstract class Entity
public
function
delete
()
{
$this
->
getNode
()
->
delete
();
return
$this
;
}
/**
* Insertion de l'entité
*
*
* @return self
*/
public
function
insert
()
{
$this
->
getNode
()
->
attachLdap
(
$this
->
service
->
getLdap
());
return
$this
;
}
...
...
@@ -219,16 +223,17 @@ abstract class Entity
*/
public
function
get
(
$attrName
)
{
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
)){
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
))
{
$value
=
$this
->
getNode
()
->
getDateTimeAttribute
(
$attrName
);
}
else
{
}
else
{
$value
=
$this
->
getNode
()
->
getAttribute
(
$attrName
);
}
if
(
empty
(
$value
)){
if
(
empty
(
$value
))
{
$value
=
null
;
}
elseif
(
1
==
count
(
$value
)){
}
elseif
(
1
==
count
(
$value
))
{
$value
=
$value
[
0
];
}
return
$value
;
}
...
...
@@ -236,16 +241,17 @@ abstract class Entity
* Affecte une nouvelle valeur à un attribut
*
* @param string $attrName
* @param mixed $value
* @param mixed
$value
* @return self
*/
public
function
set
(
$attrName
,
$value
)
{
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
)){
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
))
{
$this
->
getNode
()
->
setDateTimeAttribute
(
$attrName
,
$value
,
true
);
}
else
{
}
else
{
$this
->
getNode
()
->
setAttribute
(
$attrName
,
$value
);
}
return
$this
;
}
...
...
@@ -253,7 +259,7 @@ abstract class Entity
* Retourne <code>true</code> si l'attribut $param possède la valeur $value, <code>false</code> sinon.
*
* @param string $attrName
* @param mixed $value
* @param mixed
$value
* @return boolean
*/
public
function
has
(
$attrName
,
$value
)
...
...
@@ -265,16 +271,17 @@ abstract class Entity
* Ajoute une valeur à un attribut
*
* @param string $attrName
* @param mixed $value
* @param mixed
$value
* @return self
*/
public
function
add
(
$attrName
,
$value
)
{
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
)){
if
(
in_array
(
$attrName
,
$this
->
dateTimeAttributes
))
{
$this
->
getNode
()
->
appendToDateTimeAttribute
(
$attrName
,
$value
);
}
else
{
}
else
{
$this
->
getNode
()
->
appendToAttribute
(
$attrName
,
$value
);
}
return
$this
;
}
...
...
@@ -288,6 +295,7 @@ abstract class Entity
public
function
remove
(
$attrName
,
$value
)
{
$this
->
getNode
()
->
removeFromAttribute
(
$attrName
,
$value
);
return
$this
;
}
...
...
@@ -306,7 +314,7 @@ abstract class Entity
* Méthode magique...
*
* @param string $attrName
* @param mixed $value
* @param mixed
$value
* @return self
*/
public
function
__set
(
$attrName
,
$value
)
...
...
@@ -317,18 +325,19 @@ abstract class Entity
/**
* Methode magique ...
*
* @param string $method Nom de la méthode à appeler
* @param array $arguments Tableau de paramètres
* @param string $method
Nom de la méthode à appeler
* @param array
$arguments Tableau de paramètres
* @return mixed
*/
public
function
__call
(
$method
,
array
$arguments
)
{
$methods
=
array
(
'get'
,
'set'
,
'has'
,
'add'
,
'remove'
);
foreach
(
$methods
as
$methodName
){
if
(
0
===
strpos
(
$method
,
$methodName
)){
$attrName
=
lcfirst
(
substr
(
$method
,
strlen
(
$methodName
)
));
$arguments
=
array_merge
(
(
array
)
$attrName
,
$arguments
);
return
call_user_func_array
(
array
(
$this
,
$methodName
),
$arguments
);
$methods
=
[
'get'
,
'set'
,
'has'
,
'add'
,
'remove'
];
foreach
(
$methods
as
$methodName
)
{
if
(
0
===
strpos
(
$method
,
$methodName
))
{
$attrName
=
lcfirst
(
substr
(
$method
,
strlen
(
$methodName
)));
$arguments
=
array_merge
((
array
)
$attrName
,
$arguments
);
return
call_user_func_array
([
$this
,
$methodName
],
$arguments
);
}
}
}
...
...
src/UnicaenLdap/Entity/Generic.php
View file @
2e7eafcc
<?php
namespace
UnicaenLdap\Entity
;
/**
...
...
@@ -8,28 +9,27 @@ namespace UnicaenLdap\Entity;
*/
class
Generic
extends
Entity
{
protected
$type
=
'Generic'
;
/**
* Liste des classes d'objet nécessaires à la création d'une adresse générique
*
* @var string[]
*
* @var string[]
*/
protected
$objectClass
=
array
(
'top'
,
'inetOrgPerson'
,
'organizationalPerson'
,
'person'
,
'supannPerson'
,
'ucbnEmp'
)
;
protected
$objectClass
=
[
'top'
,
'inetOrgPerson'
,
'organizationalPerson'
,
'person'
,
'supannPerson'
,
'ucbnEmp'
,
]
;
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected
$dateTimeAttributes
=
array
(
)
;
protected
$dateTimeAttributes
=
[
]
;
}
\ No newline at end of file
src/UnicaenLdap/Entity/Group.php
View file @
2e7eafcc
<?php
namespace
UnicaenLdap\Entity
;
use
DateTime
;
...
...
@@ -10,52 +11,52 @@ use DateTime;
*/
class
Group
extends
Entity
{
protected
$type
=
'Group'
;
/**
* Liste des classes d'objet nécessaires à la création d'un groupe
*
* @var string[]
*
* @var string[]
*/
protected
$objectClass
=
array
(
'groupOfNames'
,
'supannGroupe'
)
;
protected
$objectClass
=
[
'groupOfNames'
,
'supannGroupe'
,
]
;
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected
$dateTimeAttributes
=
array
(
protected
$dateTimeAttributes
=
[
'supannGroupeDateFin'
,
);
];
/**
* Détermine si un groupe est valide ou non, c'est-à-dire si sa date de fin de validité n'est pas antérieure à la date testée
* Détermine si un groupe est valide ou non, c'est-à-dire si sa date de fin de validité n'est pas antérieure à la
* date testée
*
* @param DateTime $dateObservation
* @return bool
*/
public
function
isValid
(
DateTime
$dateObservation
=
null
)
public
function
isValid
(
DateTime
$dateObservation
=
null
)
{
if
(
empty
(
$dateObservation
))
$dateObservation
=
new
DateTime
;
$dateControle
=
$this
->
supannGroupeDateFin
;
return
empty
(
$dateControle
)
||
(
$dateControle
>=
$dateObservation
->
getTimestamp
());
}
/**
* Détermine si un groupe est obsolète ou non, c'est-à-dire si sa date de fin de validité est antérieure à la date testée
* Détermine si un groupe est obsolète ou non, c'est-à-dire si sa date de fin de validité est antérieure à la date
* testée
*
* @param DateTime $dateObservation
* @return bool
*/
public
function
isObsolete
(
DateTime
$dateObservation
=
null
)
public
function
isObsolete
(
DateTime
$dateObservation
=
null
)
{
return
!
$this
->
isValid
();
return
!
$this
->
isValid
();
}
/**
...
...
@@ -64,10 +65,14 @@ class Group extends Entity
* @param string $orderBy Champ de tri (au besoin)
* @return People[]
*/
public
function
getPeople
(
$orderBy
=
null
)
public
function
getPeople
(
$orderBy
=
null
)
{
/* @var $people \UnicaenLdap\Service\People */
$people
=
$this
->
getService
()
->
getServiceManager
()
->
get
(
'ldapServicePeople'
);
return
$people
->
getAllBy
(
$this
->
get
(
'member'
),
'dn'
,
$orderBy
);
/** @var People[] $result */
$result
=
$people
->
getAllBy
(
$this
->
get
(
'member'
),
'dn'
,
$orderBy
);
return
$result
;
}
}
\ No newline at end of file
src/UnicaenLdap/Entity/People.php
View file @
2e7eafcc
<?php
namespace
UnicaenLdap\Entity
;
use
UnicaenLdap\Entity\Group
;
use
UnicaenLdap\Entity\Structure
;
use
DateTime
;
/**
* Classe mère des people de l'annuaire LDAP.
*
...
...
@@ -14,48 +12,48 @@ use DateTime;
*/
class
People
extends
Entity
{
protected
$role_pattern
=
'/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'
;
static
protected
$role_pattern
=
'/^\[role={SUPANN}(.*)\]\[type={SUPANN}(.*)\]\[code=(.*)\]\[libelle=(.*)\]$/'
;
/**
* Liste des rôles existants
*
*
* @var string[]
*/
public
static
$roles_list
=
array
(
'DIRECTEUR'
=>
'D30'
,