Skip to content
Snippets Groups Projects
Commit 8d66ec30 authored by surville's avatar surville
Browse files

Gestion des attributs liés au mot de passe

parent 80f41192
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ use UnicaenLdap\Entity\Entity; ...@@ -7,6 +7,7 @@ use UnicaenLdap\Entity\Entity;
use UnicaenLdap\Entity\People as PeopleEntity; use UnicaenLdap\Entity\People as PeopleEntity;
use UnicaenLdap\Entity\Structure as StructureEntity; use UnicaenLdap\Entity\Structure as StructureEntity;
use UnicaenLdap\Exception; use UnicaenLdap\Exception;
use Zend\Ldap\Attribute;
use Zend\Ldap\Dn; use Zend\Ldap\Dn;
use Zend\Ldap\Exception\LdapException; use Zend\Ldap\Exception\LdapException;
...@@ -71,10 +72,12 @@ class People extends Entity ...@@ -71,10 +72,12 @@ class People extends Entity
'loginShell', 'loginShell',
'mail', 'mail',
'mobile', 'mobile',
'ntPassword',
'pager', 'pager',
'postalAddress', 'postalAddress',
'preferredLanguage', 'preferredLanguage',
'rid', 'rid',
'sambaNTPassword',
'sambaSID', 'sambaSID',
'schacDateOfBirth', 'schacDateOfBirth',
'schacExpiryDate', 'schacExpiryDate',
...@@ -122,12 +125,14 @@ class People extends Entity ...@@ -122,12 +125,14 @@ class People extends Entity
'ucbnServicePapercut', 'ucbnServicePapercut',
'ucbnSiteLocalisation', 'ucbnSiteLocalisation',
'ucbnSousStructure', 'ucbnSousStructure',
'ucbnSquidHash',
'ucbnStatus', 'ucbnStatus',
'ucbnStructureRecherche', 'ucbnStructureRecherche',
'uidNumber',
'unicaenMonEtupass', 'unicaenMonEtupass',
'unicaenTermsOfUse', 'unicaenTermsOfUse',
'userCertificate', 'userCertificate',
'uidNumber', 'userPassword',
]; ];
/** /**
...@@ -153,9 +158,16 @@ class People extends Entity ...@@ -153,9 +158,16 @@ class People extends Entity
'eduPersonPrimaryAffiliation', 'eduPersonPrimaryAffiliation',
'eduPersonPrimaryOrgUnitDN', 'eduPersonPrimaryOrgUnitDN',
'eduPersonPrincipalName', 'eduPersonPrincipalName',
'gidNumber',
'givenName', 'givenName',
'homeDirectory',
'leoCode', 'leoCode',
'loginShell',
'ntPassword',
'preferredLanguage', 'preferredLanguage',
'rid',
'sambaNTPassword',
'sambaSID',
'schacDateOfBirth', 'schacDateOfBirth',
'schacExpiryDate', 'schacExpiryDate',
'sexe', 'sexe',
...@@ -167,12 +179,9 @@ class People extends Entity ...@@ -167,12 +179,9 @@ class People extends Entity
'supannEtuId', 'supannEtuId',
'supannListeRouge', 'supannListeRouge',
'telephoneNumber', 'telephoneNumber',
'rid', 'ucbnSquidHash',
'sambaSID',
'uidNumber', 'uidNumber',
'gidNumber', 'userPassword',
'loginShell',
'homeDirectory'
]; ];
/** /**
...@@ -1825,7 +1834,6 @@ class People extends Entity ...@@ -1825,7 +1834,6 @@ class People extends Entity
/** /**
* Attribut Ldap "loginShell" * Attribut Ldap "loginShell"
* @todo tester le format
* *
* @param array|string|null $value * @param array|string|null $value
* @param bool $append * @param bool $append
...@@ -1843,7 +1851,6 @@ class People extends Entity ...@@ -1843,7 +1851,6 @@ class People extends Entity
/** /**
* Attribut Ldap "homeDirectory" * Attribut Ldap "homeDirectory"
* @todo tester le format
* *
* @param array|string|null $value * @param array|string|null $value
* @param bool $append * @param bool $append
...@@ -1859,6 +1866,82 @@ class People extends Entity ...@@ -1859,6 +1866,82 @@ class People extends Entity
return $this; 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 * Retourne les structures auxquelles appartiennent la personne
* *
......
...@@ -93,6 +93,25 @@ class People extends BasePeople ...@@ -93,6 +93,25 @@ class People extends BasePeople
return ($prenomDabord ? $prenom . ' ' . $nom : $nom . ' ' . $prenom) . $civilite; 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 * Retourne le léocode associé à l'individu
* *
...@@ -234,6 +253,24 @@ class People extends BasePeople ...@@ -234,6 +253,24 @@ class People extends BasePeople
return $structureService->getBy($dn, 'dn'); 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". * Retourne true si l'argument est au format "supannRoleEntite".
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment