Commit 8d66ec30 authored by surville's avatar surville
Browse files

Gestion des attributs liés au mot de passe

parent 80f41192
Loading
Loading
Loading
Loading
+91 −8
Changes for src/UnicaenLdap/Entity/Base/People.php: 91 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Entity\People as PeopleEntity;
use UnicaenLdap\Entity\Structure as StructureEntity;
use UnicaenLdap\Exception;
use Zend\Ldap\Attribute;
use Zend\Ldap\Dn;
use Zend\Ldap\Exception\LdapException;

@@ -71,10 +72,12 @@ class People extends Entity
        'loginShell',
        'mail',
        'mobile',
        'ntPassword',
        'pager',
        'postalAddress',
        'preferredLanguage',
        'rid',
        'sambaNTPassword',
        'sambaSID',
        'schacDateOfBirth',
        'schacExpiryDate',
@@ -122,12 +125,14 @@ class People extends Entity
        'ucbnServicePapercut',
        'ucbnSiteLocalisation',
        'ucbnSousStructure',
        'ucbnSquidHash',
        'ucbnStatus',
        'ucbnStructureRecherche',
        'uidNumber',
        'unicaenMonEtupass',
        'unicaenTermsOfUse',
        'userCertificate',
        'uidNumber',
        'userPassword',
    ];

    /**
@@ -153,9 +158,16 @@ class People extends Entity
        'eduPersonPrimaryAffiliation',
        'eduPersonPrimaryOrgUnitDN',
        'eduPersonPrincipalName',
        'gidNumber',
        'givenName',
        'homeDirectory',
        'leoCode',
        'loginShell',
        'ntPassword',
        'preferredLanguage',
        'rid',
        'sambaNTPassword',
        'sambaSID',
        'schacDateOfBirth',
        'schacExpiryDate',
        'sexe',
@@ -167,12 +179,9 @@ class People extends Entity
        'supannEtuId',
        'supannListeRouge',
        'telephoneNumber',
        'rid',
        'sambaSID',
        'ucbnSquidHash',
        'uidNumber',
        'gidNumber',
        'loginShell',
        'homeDirectory'
        'userPassword',
    ];

    /**
@@ -1825,7 +1834,6 @@ class People extends Entity

    /**
     * Attribut Ldap "loginShell"
     * @todo tester le format
     *
     * @param array|string|null $value
     * @param bool $append
@@ -1843,7 +1851,6 @@ class People extends Entity

    /**
     * Attribut Ldap "homeDirectory"
     * @todo tester le format
     *
     * @param array|string|null $value
     * @param bool $append
@@ -1859,6 +1866,82 @@ class People extends Entity
        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;
    }

    /**
     * Attribut Ldap "ntPassword"
     *
     * @param string $value
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setNtPassword(string $value)
    {
        $uni = '';
        $value = (string)$value;
        for ($i = 0; $i < strlen($value); $i++) {
            $a = ord($value{$i}) << 8;
            $uni .= sprintf('%X', $a);
        }
        $nthash = hash("md4", pack('H*', $uni), true);
        $this->appendOrNot('ntPassword', strtoupper(bin2hex($nthash)), false);

        return $this;
    }

    /**
     * Attribut Ldap "sambaNTPassword"
     * @see setNtPassword
     *
     * @param string $value
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setSambaNTPassword(string $value)
    {
        $uni = '';
        $value = (string)$value;
        for ($i = 0; $i < strlen($value); $i++) {
            $a = ord($value{$i}) << 8;
            $uni .= sprintf('%X', $a);
        }
        $nthash = hash("md4", pack('H*', $uni), true);
        $this->appendOrNot('sambaNTPassword', strtoupper(bin2hex($nthash)), false);

        return $this;
    }

    /**
     * Attribut Ldap "ucbnSquidHash"
     *
     * @param string $value
     * @param bool $append
     * @return $this
     * @throws Exception
     * @throws LdapException
     */
    public function setUcbnSquidHash(string $value)
    {
        $value = "Unicaen:" . md5(sprintf('%s:Unicaen:%s', $this->get('supannAliasLogin'), $value));
        $this->appendOrNot('ucbnSquidHash', $value, false);

        return $this;
    }

    /**
     * Retourne les structures auxquelles appartiennent la personne
     *
+37 −0
Changes for src/UnicaenLdap/Entity/People.php: 37 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -93,6 +93,25 @@ class People extends BasePeople
        return ($prenomDabord ? $prenom . ' ' . $nom : $nom . ' ' . $prenom) . $civilite;
    }

    /**
     * Retourne l'identifiant Octopus de l'individu
     *
     * @return string|null
     */
    public function getOctopusId()
    {
        $attributeValues = $this->preFormat($this->supannRefId);
        $label = $this->getLabel('OCTOPUS', 'ID');

        $value = array_filter($attributeValues, function ($v) use ($label) {
            return preg_match("/^$label(?<identifiant>.+)$/", $v);
        });

        return !empty($value)
            ? str_replace($label, '', array_values($value)[0])
            : null;
    }

    /**
     * Retourne le léocode associé à l'individu
     *
@@ -234,6 +253,24 @@ class People extends BasePeople
        return $structureService->getBy($dn, 'dn');
    }

    /**
     * Modifie l'ensemble des attributs liés au mot de passe
     *
     * @param string $value
     * @return $this
     * @throws \UnicaenLdap\Exception
     * @throws \Zend\Ldap\Exception\LdapException
     */
    public function setPassword(string $value)
    {
        parent::setUserPassword($value);
        parent::setNtPassword($value);
        parent::setSambaNTPassword($value);
        parent::setUcbnSquidHash($value);

        return $this;
    }

    /**
     * Retourne true si l'argument est au format "supannRoleEntite".
     *