Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
ldap
Commits
72b11547
Commit
72b11547
authored
Jul 01, 2020
by
David Surville
Browse files
[Evolution] Développement UnicaenLdap WIP
parent
bce4412f
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/UnicaenLdap/Entity/Base/Group.php
View file @
72b11547
...
...
@@ -84,7 +84,7 @@ class Group extends Entity
{
return
sprintf
(
'uid=%s,%s'
,
self
::
MEMBER_NOBODY
,
$this
->
getS
ervice
()
->
getLdapSystemService
()
->
getBranches
()[
0
]
$this
->
s
ervice
->
getLdapSystemService
()
->
getBranches
()[
0
]
);
}
...
...
src/UnicaenLdap/Entity/Base/People.php
View file @
72b11547
...
...
@@ -730,12 +730,12 @@ class People extends Entity
:
sprintf
(
'%s%s'
,
$supannLabel
,
$matches
[
$part
]);
}
$prefixe
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
();
$prefixe
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
();
$affect
=
(
0
!==
strpos
(
$matches
[
'affect'
],
$prefixe
))
?
sprintf
(
'%s%s'
,
$structure_prefixe
,
$matches
[
'affect'
])
:
$matches
[
'affect'
];
$prefixe
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
$prefixe
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
preg_match
(
'/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/'
,
$matches
[
'etape'
],
$parts
);
$val
=
(
0
!==
strpos
(
$parts
[
'identifiant'
],
$prefixe
))
?
$prefixe
.
$parts
[
'identifiant'
]
...
...
@@ -852,7 +852,7 @@ class People extends Entity
if
(
is_string
(
$val
))
{
return
preg_match
(
self
::
$structure_pattern
,
$val
)
?
$val
:
null
;
}
elseif
(
$val
instanceof
StructureEntity
)
{
$val
=
sprintf
(
'%s;%s'
,
strtr
(
$val
->
get
(
'supannCodeEntite'
),
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
(),
''
),
$val
->
get
(
'description'
));
$val
=
sprintf
(
'%s;%s'
,
strtr
(
$val
->
get
(
'supannCodeEntite'
),
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
(),
''
),
$val
->
get
(
'description'
));
return
preg_match
(
self
::
$structure_pattern
,
$val
)
?
$val
:
null
;
}
else
{
return
null
;
...
...
@@ -878,8 +878,8 @@ class People extends Entity
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_map
(
function
(
$val
)
{
if
(
is_string
(
$val
))
{
if
(
0
!==
strpos
(
$val
,
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()))
{
$val
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()
.
$val
;
if
(
0
!==
strpos
(
$val
,
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()))
{
$val
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()
.
$val
;
}
return
$val
;
}
elseif
(
$val
instanceof
StructureEntity
)
{
...
...
@@ -908,8 +908,8 @@ class People extends Entity
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_map
(
function
(
$val
)
{
if
(
is_string
(
$val
))
{
if
(
0
!==
strpos
(
$val
,
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()))
{
$val
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()
.
$val
;
if
(
0
!==
strpos
(
$val
,
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()))
{
$val
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
()
.
$val
;
}
return
$val
;
}
elseif
(
$val
instanceof
StructureEntity
)
{
...
...
@@ -990,7 +990,7 @@ class People extends Entity
if
(
is_string
(
$val
))
{
return
preg_match
(
self
::
$structure_pattern
,
$val
)
?
$val
:
null
;
}
elseif
(
$val
instanceof
StructureEntity
)
{
$val
=
sprintf
(
'%s;%s'
,
strtr
(
$val
->
get
(
'supannCodeEntite'
),
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
(),
''
),
$val
->
get
(
'description'
));
$val
=
sprintf
(
'%s;%s'
,
strtr
(
$val
->
get
(
'supannCodeEntite'
),
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
(),
''
),
$val
->
get
(
'description'
));
return
preg_match
(
self
::
$structure_pattern
,
$val
)
?
$val
:
null
;
}
else
{
return
null
;
...
...
@@ -1018,7 +1018,7 @@ class People extends Entity
if
(
is_string
(
$val
))
{
return
preg_match
(
self
::
$structure_pattern
,
$val
)
?
$val
:
null
;
}
elseif
(
$val
instanceof
StructureEntity
)
{
$val
=
sprintf
(
'%s;%s'
,
strtr
(
$val
->
get
(
'supannCodeEntite'
),
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
(),
''
),
$val
->
get
(
'description'
));
$val
=
sprintf
(
'%s;%s'
,
strtr
(
$val
->
get
(
'supannCodeEntite'
),
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
(),
''
),
$val
->
get
(
'description'
));
return
preg_match
(
self
::
$structure_pattern
,
$val
)
?
$val
:
null
;
}
else
{
return
null
;
...
...
@@ -1041,7 +1041,7 @@ class People extends Entity
*/
public
function
setEduPersonPrincipalName
(
$value
=
null
,
$append
=
false
)
{
$universiteDomaine
=
$this
->
getS
ervice
()
->
getLdapRootService
()
->
getEtablissementDomain
();
$universiteDomaine
=
$this
->
s
ervice
->
getLdapRootService
()
->
getEtablissementDomain
();
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_map
(
function
(
$v
)
use
(
$universiteDomaine
)
{
list
(
$identifiant
,
$domaine
)
=
array_pad
(
explode
(
'@'
,
strtolower
(
$v
)),
2
,
null
);
...
...
@@ -1202,7 +1202,7 @@ class People extends Entity
:
sprintf
(
'%s%s'
,
$supannLabel
,
$matches
[
$part
]);
}
$prefixe
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeStructurePrefixe
();
$prefixe
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeStructurePrefixe
();
$code
=
(
0
!==
strpos
(
$matches
[
'code'
],
$prefixe
))
?
sprintf
(
'%s%s'
,
$prefixe
,
$matches
[
'code'
])
:
$matches
[
'code'
];
...
...
@@ -1281,7 +1281,7 @@ class People extends Entity
* @var string $etape
* @var string $adistance
*/
$prefixe
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
$prefixe
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
preg_match
(
'/^(?<etiquette>\{[\w\-:]+\})(?<identifiant>.+)$/'
,
$matches
[
'etape'
],
$parts
);
$val
=
(
0
!==
strpos
(
$parts
[
'identifiant'
],
$prefixe
))
?
$prefixe
.
$parts
[
'identifiant'
]
...
...
@@ -1653,7 +1653,7 @@ class People extends Entity
$value
=
array_map
(
function
(
$val
)
{
if
(
is_string
(
$val
))
{
if
(
preg_match
(
self
::
$attribute_with_label_pattern
,
$val
,
$matches
))
{
$prefixe
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
$prefixe
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
$val
=
(
0
!==
strpos
(
$matches
[
'identifiant'
],
$prefixe
))
?
$prefixe
.
$matches
[
'identifiant'
]
:
$matches
[
'identifiant'
];
...
...
@@ -1684,7 +1684,7 @@ class People extends Entity
$value
=
array_map
(
function
(
$val
)
{
if
(
is_string
(
$val
))
{
if
(
preg_match
(
self
::
$attribute_with_label_pattern
,
$val
,
$matches
))
{
$prefixe
=
$this
->
getS
ervice
()
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
$prefixe
=
$this
->
s
ervice
->
getLdapStructureService
()
->
getCodeModuleEnseignementPrefixe
();
$val
=
(
0
!==
strpos
(
$matches
[
'identifiant'
],
$prefixe
))
?
$prefixe
.
$matches
[
'identifiant'
]
:
$matches
[
'identifiant'
];
...
...
src/UnicaenLdap/Entity/Base/Structure.php
View file @
72b11547
...
...
@@ -110,8 +110,8 @@ class Structure extends Entity
$value
=
$this
->
preFormat
(
$value
);
$value
=
array_map
(
function
(
$val
)
{
if
(
is_string
(
$val
))
{
if
(
0
!==
strpos
(
$val
,
$this
->
getS
ervice
()
->
getCodeStructurePrefixe
()))
{
$val
=
$this
->
getS
ervice
()
->
getCodeStructurePrefixe
()
.
$val
;
if
(
0
!==
strpos
(
$val
,
$this
->
s
ervice
->
getCodeStructurePrefixe
()))
{
$val
=
$this
->
s
ervice
->
getCodeStructurePrefixe
()
.
$val
;
}
return
$val
;
}
elseif
(
$val
instanceof
StructureEntity
)
{
...
...
src/UnicaenLdap/Entity/Group.php
View file @
72b11547
...
...
@@ -48,7 +48,7 @@ class Group extends BaseGroup
*/
public
function
getMembres
(
$orderBy
=
null
)
{
$peopleService
=
$this
->
getS
ervice
()
->
getLdapPeopleService
();
$peopleService
=
$this
->
s
ervice
->
getLdapPeopleService
();
$result
=
$peopleService
->
getAllBy
(
$this
->
member
,
'dn'
,
$orderBy
);
return
$result
;
...
...
src/UnicaenLdap/Entity/People.php
View file @
72b11547
...
...
@@ -5,7 +5,9 @@ namespace UnicaenLdap\Entity;
use
DateTime
;
use
UnicaenLdap\Entity\Base\People
as
BasePeople
;
use
UnicaenLdap\Entity\Structure
as
StructureEntity
;
use
UnicaenLdap\Entity\System
as
SystemEntity
;
use
UnicaenLdap\Exception
;
use
Zend\Ldap\Dn
;
/**
* Classe de gestion des entités de la branche "people" de l'annuaire LDAP.
...
...
@@ -135,6 +137,28 @@ class People extends BasePeople
return
DateTime
::
createFromFormat
(
'Ymd h:i:s'
,
$this
->
schacExpiryDate
.
' 00:00:00'
);
}
/**
* Retourne le responsable de l'entrée Ldap
*
* @return People|SystemEntity|string|null
* @throws Exception
* @throws \Zend\Ldap\Exception\LdapException
*/
public
function
getParrain
()
{
$systemService
=
$this
->
service
->
getLdapSystemService
();
$node
=
$this
->
service
->
getLdap
()
->
getNode
(
$this
->
supannParrainDN
);
$branch
=
$node
->
getDn
()
->
get
(
1
);
switch
(
$branch
[
'ou'
])
{
case
strtolower
(
$this
->
service
->
getType
())
:
return
$this
->
service
->
getBy
(
$node
->
getDnString
(),
'dn'
);
case
strtolower
(
$systemService
->
getType
())
:
return
$systemService
->
getBy
(
$node
->
getDnString
(),
'dn'
);
default
:
return
$this
->
supannParrainDN
;
}
}
/**
* Retourne l'adresse postale professionnelle
*
...
...
@@ -281,30 +305,6 @@ class People extends BasePeople
return
$this
->
whichStatus
(
parent
::
STATUS_TEACHER
);
}
/**
* Établissement auquel appartient la personne
*
* @return StructureEntity|null
*/
public
function
getEtablissement
()
{
$rootService
=
$this
->
getService
()
->
getLdapRootService
();
$structureService
=
$this
->
getService
()
->
getLdapStructureService
();
$dn
=
$this
->
eduPersonOrgDN
;
if
(
empty
(
$dn
))
return
null
;
switch
(
$dn
)
{
case
$rootService
->
getEtablissementDN
()
:
return
$rootService
->
getStructureEntity
();
default
:
try
{
return
$structureService
->
getBy
(
$dn
,
'dn'
);
}
catch
(
Exception
$e
)
{
return
null
;
}
}
}
/**
* Retourne le léocode associé à l'individu
*
...
...
@@ -383,21 +383,27 @@ class People extends BasePeople
}
/**
*
Modifie l'ensemble des attributs liés au mot de pass
e
*
Établissement auquel appartient la personn
e
*
* @param string $value
* @return $this
* @throws \UnicaenLdap\Exception
* @throws \Zend\Ldap\Exception\LdapException
* @return StructureEntity|null
*/
public
function
s
et
Password
(
string
$value
)
public
function
g
et
Etablissement
(
)
{
parent
::
setUserPassword
(
$value
);
parent
::
setNtPassword
(
$value
);
parent
::
setSambaNTPassword
(
$value
);
parent
::
setUcbnSquidHash
(
$value
);
$rootService
=
$this
->
service
->
getLdapRootService
();
$structureService
=
$this
->
service
->
getLdapStructureService
();
$dn
=
$this
->
eduPersonOrgDN
;
return
$this
;
if
(
empty
(
$dn
))
return
null
;
switch
(
$dn
)
{
case
$rootService
->
getEtablissementDN
()
:
return
$rootService
->
getStructureEntity
();
default
:
try
{
return
$structureService
->
getBy
(
$dn
,
'dn'
);
}
catch
(
Exception
$e
)
{
return
null
;
}
}
}
/**
...
...
@@ -407,7 +413,7 @@ class People extends BasePeople
*/
public
function
getStructure
()
{
$structureService
=
$this
->
getS
ervice
()
->
getLdapStructureService
();
$structureService
=
$this
->
s
ervice
->
getLdapStructureService
();
$value
=
$this
->
eduPersonOrgUnitDN
;
if
(
empty
(
$value
))
return
null
;
...
...
@@ -422,7 +428,7 @@ class People extends BasePeople
*/
public
function
getStructurePrincipale
()
{
$structureService
=
$this
->
getS
ervice
()
->
getLdapStructureService
();
$structureService
=
$this
->
s
ervice
->
getLdapStructureService
();
$value
=
$this
->
eduPersonPrimaryOrgUnitDN
;
if
(
empty
(
$value
))
return
null
;
...
...
@@ -433,6 +439,41 @@ class People extends BasePeople
}
}
/**
* Vérifie l'appartenance d'une personne à une structure
*
* @param string|Dn|StructureEntity $value
* @return bool
* @throws Exception
* @throws \Zend\Ldap\Exception\LdapException
*/
public
function
isInStructure
(
$value
)
{
$structureService
=
$this
->
service
->
getLdapStructureService
();
$structurePrefixe
=
$structureService
->
getCodeStructurePrefixe
();
if
(
is_string
(
$value
))
{
if
(
Dn
::
checkDn
(
$value
))
{
$value
=
$structureService
->
getBy
(
$value
,
'dn'
);
}
else
{
if
(
0
!==
strpos
(
$value
,
$structurePrefixe
))
{
$value
=
$structurePrefixe
.
$value
;
}
$value
=
$structureService
->
get
(
$value
);
}
}
elseif
(
$value
instanceof
Dn
)
{
$value
=
$structureService
->
getBy
(
$value
->
toString
(),
'dn'
);
}
if
(
!
$value
instanceof
StructureEntity
)
{
return
false
;
}
$structures
=
$this
->
preFormat
(
$this
->
supannEntiteAffectation
);
return
in_array
(
$value
->
getId
(),
$structures
);
}
/**
* Retourne les étapes auxquelles appartient la personne
*
...
...
@@ -443,8 +484,8 @@ class People extends BasePeople
$value
=
$this
->
preFormat
(
$this
->
supannEtuEtape
);
if
(
empty
(
$value
))
return
null
;
$label
=
$this
->
getLabel
(
'UAI'
,
$this
->
getS
ervice
()
->
getLdapRootService
()
->
getEtablissementUAI
());
$structureService
=
$this
->
getS
ervice
()
->
getLdapStructureService
();
$label
=
$this
->
getLabel
(
'UAI'
,
$this
->
s
ervice
->
getLdapRootService
()
->
getEtablissementUAI
());
$structureService
=
$this
->
s
ervice
->
getLdapStructureService
();
list
(
$structureKey
)
=
Entity
::
getNodeParams
(
$structureService
->
getType
());
$structureBranch
=
$structureService
->
getBranches
()[
0
];
$value
=
array_map
(
function
(
$v
)
use
(
$label
,
$structureKey
,
$structureBranch
)
{
...
...
@@ -469,8 +510,8 @@ class People extends BasePeople
$value
=
$this
->
preFormat
(
$this
->
supannEtuElementPedagogique
);
if
(
empty
(
$value
))
return
null
;
$label
=
$this
->
getLabel
(
'UAI'
,
$this
->
getS
ervice
()
->
getLdapRootService
()
->
getEtablissementUAI
());
$structureService
=
$this
->
getS
ervice
()
->
getLdapStructureService
();
$label
=
$this
->
getLabel
(
'UAI'
,
$this
->
s
ervice
->
getLdapRootService
()
->
getEtablissementUAI
());
$structureService
=
$this
->
s
ervice
->
getLdapStructureService
();
list
(
$structureKey
)
=
Entity
::
getNodeParams
(
$structureService
->
getType
());
$structureBranch
=
$structureService
->
getBranches
()[
0
];
$value
=
array_map
(
function
(
$v
)
use
(
$label
,
$structureKey
,
$structureBranch
)
{
...
...
@@ -485,6 +526,36 @@ class People extends BasePeople
return
1
==
count
(
$value
)
?
array_shift
(
$value
)
:
$value
;
}
/**
* Retourne les inscriptions complètes d'un étudiant
*
* @return array
*/
public
function
getInscription
()
{
$value
=
$this
->
preFormat
(
$this
->
supannEtuInscription
);
if
(
empty
(
$value
))
return
null
;
$value
=
array_map
(
function
(
$v
)
{
preg_match
(
self
::
$inscription_pattern
,
$v
,
$matches
);
$affect
=
$matches
[
'affect'
];
$etape
=
str_replace
(
$this
->
getLabel
(
'UAI'
,
$this
->
service
->
getLdapRootService
()
->
getEtablissementUAI
()),
''
,
$matches
[
'etape'
]);
return
[
'etab'
=>
str_replace
(
$this
->
getLabel
(
'UAI'
),
''
,
$matches
[
'etab'
]),
'anneeinsc'
=>
$matches
[
'anneeinsc'
],
'regimeinsc'
=>
str_replace
(
$this
->
getLabel
(
'SISE'
),
''
,
$matches
[
'regimeinsc'
]),
'sectdisc'
=>
str_replace
(
$this
->
getLabel
(
'SISE'
),
''
,
$matches
[
'sectdisc'
]),
'typedip'
=>
str_replace
(
$this
->
getLabel
(
'SISE'
),
''
,
$matches
[
'typedip'
]),
'cursusann'
=>
str_replace
(
$this
->
getLabel
(
'SUPANN'
),
''
,
$matches
[
'cursusann'
]),
'affect'
=>
$this
->
service
->
getLdapStructureService
()
->
get
(
$affect
)
?:
$affect
,
'diplome'
=>
str_replace
(
$this
->
getLabel
(
'SISE'
),
''
,
$matches
[
'diplome'
]),
'etape'
=>
$this
->
service
->
getLdapStructureService
()
->
get
(
$etape
)
?:
$etape
,
];
},
$value
);
return
1
==
count
(
$value
)
?
array_shift
(
$value
)
:
$value
;
}
/**
* Retourne true si l'argument est au format "supannRoleEntite".
*
...
...
@@ -504,4 +575,22 @@ class People extends BasePeople
return
false
;
}
/**
* 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
;
}
}
\ No newline at end of file
src/UnicaenLdap/Entity/Structure.php
View file @
72b11547
...
...
@@ -22,7 +22,7 @@ class Structure extends BaseStructure
public
function
getParents
()
{
if
(
null
!==
(
$parentIds
=
$this
->
get
(
'supannCodeEntiteParent'
)))
{
return
$this
->
getS
ervice
()
->
getAll
(
$parentIds
);
return
$this
->
s
ervice
->
getAll
(
$parentIds
);
}
return
null
;
...
...
@@ -46,7 +46,7 @@ class Structure extends BaseStructure
$filter
=
Filter
::
andFilter
(
$childrenFilter
,
$filter
);
}
return
$this
->
getS
ervice
()
->
search
(
$filter
,
$orderBy
,
-
1
,
0
);
return
$this
->
s
ervice
->
search
(
$filter
,
$orderBy
,
-
1
,
0
);
}
/**
...
...
@@ -60,8 +60,8 @@ class Structure extends BaseStructure
{
$code
=
$this
->
getId
();
return
(
0
===
strpos
(
$code
,
$this
->
getS
ervice
()
->
getCodeStructurePrefixe
())
||
0
===
strpos
(
$code
,
$this
->
getS
ervice
()
->
getCodeModuleEnseignementPrefixe
()))
0
===
strpos
(
$code
,
$this
->
s
ervice
->
getCodeStructurePrefixe
())
||
0
===
strpos
(
$code
,
$this
->
s
ervice
->
getCodeModuleEnseignementPrefixe
()))
?
substr
(
$code
,
3
)
:
$code
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment