Commit 679e9cf0 authored by surville's avatar surville
Browse files

[Evolution] Développement UnicaenLdap WIP

parent 08b0d71f
<?php
namespace UnicaenLdap\Entity\Base;
use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Exception;
use Zend\Ldap\Attribute;
use Zend\Ldap\Exception\LdapException;
/**
* Classe mère des entités de la branche "generic" de l'annuaire LDAP.
*
* @author David Surville <david.surville@unicaen.fr>
*/
class Generic extends Entity
{
/**
* @var string
*/
protected $type = 'Generic';
/**
* Liste des classes d'objet nécessaires à la création d'une adresse générique
*
* @var array
*/
protected $objectClass = [
'top',
'inetOrgPerson',
'organizationalPerson',
'person',
];
/**
* Liste des attributs autorisés pour une entité "Generic"
*
* @var array
*/
protected $authorizedAttributes = [
// Attributes classes
'objectClass',
// Attributes
'cn',
'description',
'mail',
'sn',
'supannAliasLogin',
'ucbnServiceIMAP',
'userPassword',
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected $dateTimeAttributes = [
];
/**
* Liste des attributs monovalués
*
* @var array
*/
protected $monoValuedAttributes = [
'supannALiasLogin',
'ucbnServiceIMAP',
'userPassword',
];
/**
* Attribut Ldap "cn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setCn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('cn', $value, $append);
return $this;
}
/**
* Attribut Ldap "description"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setDescription($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('description', $value, $append);
return $this;
}
/**
* Attribut Ldap "mail"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setMail($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_EMAIL));
$this->appendOrNot('mail', $value, $append);
return $this;
}
/**
* Attribut Ldap "sn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setSn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('sn', $value, $append);
return $this;
}
/**
* Attribut Ldap "supannALiasLogin"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setSupannAliasLogin($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map('strtolower', $value);
$value = array_filter($value, function ($v) {
return preg_match('/^[0-9a-z\-]+$/', $v);
});
$this->appendOrNot('supannAliasLogin', $value, $append);
return $this;
}
/**
* Attribut Ldap "ucbnServiceIMAP"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setUcbnServiceIMAP($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map([$this, 'formatBoolean'], $value);
$this->appendOrNot('ucbnServiceIMAP', $value, $append);
return $this;
}
/**
* Attribut Ldap "userPassword"
*
* @param string $value
* @return self
* @throws LdapException
*/
public function setUserPassword(string $value)
{
$this->getNode()->setPasswordAttribute($value, Attribute::PASSWORD_HASH_SHA, 'userPassword');
return $this;
}
}
\ No newline at end of file
...@@ -94,8 +94,6 @@ class Group extends Entity ...@@ -94,8 +94,6 @@ class Group extends Entity
* @param array|string|null $value * @param array|string|null $value
* @param bool $append * @param bool $append
* @return self * @return self
* @throws Exception
* @throws LdapException
*/ */
public function setDescription($value = null, $append = false) public function setDescription($value = null, $append = false)
{ {
......
...@@ -72,21 +72,21 @@ class People extends Entity ...@@ -72,21 +72,21 @@ class People extends Entity
'objectClass', 'objectClass',
// Attributes // Attributes
'cn', 'cn',
'displayName',
'dateDeNaissance', 'dateDeNaissance',
'eduPersonPrincipalName', 'dateFinInscription',
'eduPersonNickname', // no getter and setter 'displayName',
'eduPersonAffiliation', 'eduPersonAffiliation',
'eduPersonPrimaryAffiliation', 'eduPersonNickname',
'eduPersonOrgDN', 'eduPersonOrgDN',
'eduPersonOrgUnitDN', 'eduPersonOrgUnitDN',
'eduPersonPrimaryAffiliation',
'eduPersonPrimaryOrgUnitDN', 'eduPersonPrimaryOrgUnitDN',
'dateFinInscription', 'eduPersonPrincipalName',
'facsimileTelephoneNumber', // no getter and setter 'facsimileTelephoneNumber',
'gidNumber', 'gidNumber',
'givenName', 'givenName',
'homeDirectory', 'homeDirectory',
'labeledURI', // no getter and setter 'labeledURI',
'leoCode', 'leoCode',
'loginShell', 'loginShell',
'mail', 'mail',
...@@ -131,7 +131,7 @@ class People extends Entity ...@@ -131,7 +131,7 @@ class People extends Entity
'supannRefId', 'supannRefId',
'supannTypeEntiteAffectation', 'supannTypeEntiteAffectation',
'telephoneNumber', 'telephoneNumber',
'title', // no getter and setter 'title',
'ucbnAnneePostBac', 'ucbnAnneePostBac',
'ucbnCodeEtape', 'ucbnCodeEtape',
'ucbnEtuComplementInscription', 'ucbnEtuComplementInscription',
...@@ -198,6 +198,8 @@ class People extends Entity ...@@ -198,6 +198,8 @@ class People extends Entity
'supannEtuId', 'supannEtuId',
'supannListeRouge', 'supannListeRouge',
'telephoneNumber', 'telephoneNumber',
'ucbnServiceADE',
'ucbnServicePapercut',
'ucbnSquidHash', 'ucbnSquidHash',
'uidNumber', 'uidNumber',
'userPassword', 'userPassword',
...@@ -275,8 +277,15 @@ class People extends Entity ...@@ -275,8 +277,15 @@ class People extends Entity
'\[affect=(?<affect>[\w\-]+)\]' . '\[affect=(?<affect>[\w\-]+)\]' .
'\[diplome=(?<diplome>\{[\w\-:]+\}\w+)\]' . '\[diplome=(?<diplome>\{[\w\-:]+\}\w+)\]' .
'\[etape=(?<etape>\{[\w\-:]+\}.+)\]$/'; '\[etape=(?<etape>\{[\w\-:]+\}.+)\]$/';
static protected $inscription_complement_pattern = '/^\[anneeinsc=(?<anneeinsc>\d{4})\]\[etape=(?<etape>\{[\w\-:]+\}.+)\]\[adistance=(?<adistance>\{[\w\-:]+\}\w{1})\]$/'; static protected $inscription_complement_pattern =
static protected $role_pattern = '/^\[role=(?<role>\{SUPANN\}[\w\-]+)\]\[type=(?<type>\{SUPANN\}[\w\-]+)\]\[code=(?<code>[\w\-]+)\]\[libelle=(?<libelle>.+)\]$/'; '/^\[anneeinsc=(?<anneeinsc>\d{4})\]' .
'\[etape=(?<etape>\{[\w\-:]+\}.+)\]' .
'\[adistance=(?<adistance>\{[\w\-:]+\}\w{1})\]$/';
static protected $role_pattern =
'/^\[role=(?<role>\{SUPANN\}[\w\-]+)\]' .
'\[type=(?<type>\{SUPANN\}[\w\-]+)\]' .
'\[code=(?<code>[\w\-]+)\]' .
'\[libelle=(?<libelle>.+)\]$/';
static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/'; static protected $role_src_pattern = '/^(?<code>\d{4});(?<libelle>.+)$/';
...@@ -577,6 +586,24 @@ class People extends Entity ...@@ -577,6 +586,24 @@ class People extends Entity
return $this; return $this;
} }
/**
* Attribut Ldap "mail"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setMail($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_filter(filter_var_array($value, FILTER_VALIDATE_EMAIL));
$this->appendOrNot('mail', $value, $append);
return $this;
}
/** /**
* Attribut Ldap "mobile" * Attribut Ldap "mobile"
* *
...@@ -595,6 +622,24 @@ class People extends Entity ...@@ -595,6 +622,24 @@ class People extends Entity
return $this; return $this;
} }
/**
* Attribut Ldap "pager"
*
* @param array|string|null $value
* @param bool $append
* @return self
* @throws Exception
* @throws LdapException
*/
public function setPager($value = null, $append = false)
{
$value = $this->preFormat($value);
$value = array_map([$this, 'formatTel'], $value);
$this->appendOrNot('pager', $value, $append);
return $this;
}
/** /**
* Attribut Ldap "preferredLanguage" * Attribut Ldap "preferredLanguage"
* *
......
...@@ -97,7 +97,7 @@ class Root extends Entity ...@@ -97,7 +97,7 @@ class Root extends Entity
public function setEduOrgHomePageURI($value = null, $append = false) public function setEduOrgHomePageURI($value = null, $append = false)
{ {
$value = $this->preFormat($value); $value = $this->preFormat($value);
$value = filter_var_array($value, FILTER_VALIDATE_URL); $value = array_filter(filter_var_array($value, FILTER_VALIDATE_URL));
$this->appendOrNot('eduOrgHomePageURI', $value, $append); $this->appendOrNot('eduOrgHomePageURI', $value, $append);
return $this; return $this;
...@@ -132,7 +132,7 @@ class Root extends Entity ...@@ -132,7 +132,7 @@ class Root extends Entity
public function setEduOrgSuperiorURI($value = null, $append = false) public function setEduOrgSuperiorURI($value = null, $append = false)
{ {
$value = $this->preFormat($value); $value = $this->preFormat($value);
$value = filter_var_array($value, FILTER_VALIDATE_URL); $value = array_filter(filter_var_array($value, FILTER_VALIDATE_URL));
$this->appendOrNot('eduOrgSuperiorURI', $value, $append); $this->appendOrNot('eduOrgSuperiorURI', $value, $append);
return $this; return $this;
...@@ -150,7 +150,7 @@ class Root extends Entity ...@@ -150,7 +150,7 @@ class Root extends Entity
public function setEduOrgWhitePagesURI($value = null, $append = false) public function setEduOrgWhitePagesURI($value = null, $append = false)
{ {
$value = $this->preFormat($value); $value = $this->preFormat($value);
$value = filter_var_array($value, FILTER_VALIDATE_URL); $value = array_filter(filter_var_array($value, FILTER_VALIDATE_URL));
$this->appendOrNot('eduOrgWhitePagesURI', $value, $append); $this->appendOrNot('eduOrgWhitePagesURI', $value, $append);
return $this; return $this;
......
<?php
namespace UnicaenLdap\Entity\Base;
use UnicaenLdap\Entity\Entity;
use Zend\Ldap\Attribute;
use Zend\Ldap\Exception\LdapException;
/**
* Classe mère des entités de la branche "system" de l'annuaire LDAP.
*
* @author David Surville <david.surville@unicaen.fr>
*/
class System extends Entity
{
protected $type = 'System';
/**
* Liste des classes d'objet nécessaires à la création d'un compte système
*
* @var string[]
*/
protected $objectClass = [
'top',
'inetOrgPerson',
'organizationalPerson',
'person',
'supannPerson',
'ucbnEmp',
];
/**
* Liste des attributs autorisés pour une entité "Generic"
*
* @var array
*/
protected $authorizedAttributes = [
// Attributes classes
'objectClass',
// Attributes
'cn',
'sn',
'userPassword',
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected $dateTimeAttributes = [
];
/**
* Attribut Ldap "cn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setCn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('cn', $value, $append);
return $this;
}
/**
* Attribut Ldap "sn"
*
* @param array|string|null $value
* @param bool $append
* @return self
*/
public function setSn($value = null, $append = false)
{
$value = $this->preFormat($value);
$this->appendOrNot('sn', $value, $append);
return $this;
}
/**
* Attribut Ldap "userPassword"
*
* @param string $value
* @return self
* @throws LdapException
*/
public function setUserPassword(string $value)
{
$this->getNode()->setPasswordAttribute($value, Attribute::PASSWORD_HASH_SHA, 'userPassword');
return $this;
}
}
\ No newline at end of file
...@@ -2,34 +2,12 @@ ...@@ -2,34 +2,12 @@
namespace UnicaenLdap\Entity; namespace UnicaenLdap\Entity;
use UnicaenLdap\Entity\Base\Generic as BaseGeneric;
/** /**
* Classe mère des adresses génériques de l'annuaire LDAP. * Classe de gestion des entités de la branche "generic" de l'annuaire LDAP.
* *
* @author Laurent Lécluse <laurent.lecluse at unicaen.fr> * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
*/ */
class Generic extends Entity class Generic extends BaseGeneric
{ {}
protected $type = 'Generic'; \ No newline at end of file
/**
* Liste des classes d'objet nécessaires à la création d'une adresse générique
*
* @var string[]
*/
protected $objectClass = [
'top',
'inetOrgPerson',
'organizationalPerson',
'person',
'supannPerson',
'ucbnEmp',
];
/**
* Liste des attributs contenant des dates
*
* @var string[]
*/
protected $dateTimeAttributes = [
];
}
\ No newline at end of file
...@@ -162,11 +162,19 @@ class People extends BasePeople ...@@ -162,11 +162,19 @@ class People extends BasePeople
/** /**
* Retourne l'adresse postale professionnelle * Retourne l'adresse postale professionnelle
* *
* @return array * @param string $type type de l'adresse : 'professionnelle' ou 'personnelle'
* @return array|null
*/ */
public function getAdressePostale() public function getAdressePostale($type = 'professionnelle')
{ {
$value = $this->preFormat($this->postalAddress); if(!in_array($type, ['professionnelle', 'personnelle'])) {
return null;
}
$attributes = ($type == 'professionnelle')
? $this->postalAddress
: [$this->ucbnPrivateAddress, $this->ucbnPrivateAddressBis];
$value = $this->preFormat($attributes);
$value = array_map(function ($val) { $value = array_map(function ($val) {
return explode('$', $val); return explode('$', $val);
}, $value); }, $value);
...@@ -440,7 +448,29 @@ class People extends BasePeople ...@@ -440,7 +448,29 @@ class People extends BasePeople
} }
/** /**
* Vérifie l'appartenance d'une personne à une structure * Retourne les structures recherche auxquelles appartient la personne
*
* @return StructureEntity[]|null
*/
public function getStructureRecherche()
{
$structureService = $this->service->getLdapStructureService();
$structurePrefixe = $structureService->getCodeStructurePrefixe();
$value = $this->preFormat($this->ucbnStructureRecherche);
if (empty($value)) return null;
$value = array_map(function ($v) use ($structurePrefixe) {
preg_match(self::$structure_pattern, $v, $matches);
return $structurePrefixe . $matches['code'];
}, $value);
$value = $structureService->getAllBy($value, 'supannCodeEntite');
return 1 == count($value) ? array_shift($value) : $value;
}
/**
* Vérifie l'appartenance d'une personne à une structure (structures recherche incluses)
* *
* @param string|Dn|StructureEntity $value * @param string|Dn|StructureEntity $value
* @return bool * @return bool
...@@ -471,13 +501,21 @@ class People extends BasePeople ...@@ -471,13 +501,21 @@ class People extends BasePeople
} }
$structures = $this->preFormat($this->supannEntiteAffectation); $structures = $this->preFormat($this->supannEntiteAffectation);
return in_array($value->getId(), $structures); $structuresRecherche = $this->preFormat($this->ucbnStructureRecherche);
$structuresRecherche = array_map(function ($v) use ($structurePrefixe) {
preg_match(self::$structure_pattern, $v, $matches);
return $structurePrefixe . $matches['code'];
}, $structuresRecherche);
return in_array($value->getId(), array_merge($structures, $structuresRecherche));
} }
/** /**
* Retourne les étapes auxquelles appartient la personne * Retourne les étapes auxquelles appartient l'étudiant
* *
* @return StructureEntity[]|null * @return mixed|StructureEntity[]|null