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

[Evolution] Développement UnicaenLdap WIP

parent 08b0d71f
Loading
Loading
Loading
Loading
+189 −0
Original line number Diff line number Diff line
<?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
+0 −2
Original line number Diff line number Diff line
@@ -94,8 +94,6 @@ class Group extends Entity
     * @param array|string|null $value
     * @param bool $append
     * @return self
     * @throws Exception
     * @throws LdapException
     */
    public function setDescription($value = null, $append = false)
    {
+55 −10
Original line number Diff line number Diff line
@@ -72,21 +72,21 @@ class People extends Entity
        'objectClass',
        // Attributes
        'cn',
        'displayName',
        'dateDeNaissance',
        'eduPersonPrincipalName',
        'eduPersonNickname', // no getter and setter
        'dateFinInscription',
        'displayName',
        'eduPersonAffiliation',
        'eduPersonPrimaryAffiliation',
        'eduPersonNickname',
        'eduPersonOrgDN',
        'eduPersonOrgUnitDN',
        'eduPersonPrimaryAffiliation',
        'eduPersonPrimaryOrgUnitDN',
        'dateFinInscription',
        'facsimileTelephoneNumber', // no getter and setter
        'eduPersonPrincipalName',
        'facsimileTelephoneNumber',
        'gidNumber',
        'givenName',
        'homeDirectory',
        'labeledURI', // no getter and setter
        'labeledURI',
        'leoCode',
        'loginShell',
        'mail',
@@ -131,7 +131,7 @@ class People extends Entity
        'supannRefId',
        'supannTypeEntiteAffectation',
        'telephoneNumber',
        'title', // no getter and setter
        'title',
        'ucbnAnneePostBac',
        'ucbnCodeEtape',
        'ucbnEtuComplementInscription',
@@ -198,6 +198,8 @@ class People extends Entity
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
        'ucbnServiceADE',
        'ucbnServicePapercut',
        'ucbnSquidHash',
        'uidNumber',
        'userPassword',
@@ -275,8 +277,15 @@ class People extends Entity
        '\[affect=(?<affect>[\w\-]+)\]' .
        '\[diplome=(?<diplome>\{[\w\-:]+\}\w+)\]' .
        '\[etape=(?<etape>\{[\w\-:]+\}.+)\]$/';
    static protected $inscription_complement_pattern = '/^\[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 $inscription_complement_pattern = 
        '/^\[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>.+)$/';


@@ -577,6 +586,24 @@ class People extends Entity
        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"
     *
@@ -595,6 +622,24 @@ class People extends Entity
        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"
     *
+3 −3
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ class Root extends Entity
    public function setEduOrgHomePageURI($value = null, $append = false)
    {
        $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);

        return $this;
@@ -132,7 +132,7 @@ class Root extends Entity
    public function setEduOrgSuperiorURI($value = null, $append = false)
    {
        $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);

        return $this;
@@ -150,7 +150,7 @@ class Root extends Entity
    public function setEduOrgWhitePagesURI($value = null, $append = false)
    {
        $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);

        return $this;
+97 −0
Original line number Diff line number Diff line
<?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
Loading