Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
auth
Commits
ea6cd554
Commit
ea6cd554
authored
Feb 18, 2021
by
Bertrand Gauthier
Browse files
[FIX] Usurpation d'un compte local en BDD
parent
098e285b
Pipeline
#9248
passed with stage
in 59 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG.md
View file @
ea6cd554
...
...
@@ -37,3 +37,7 @@ Première version officielle sous ZF3.
3.
1.2
-----
-
Aide de vue UserUsurpationHelper : ajout de la possibilité de dessiner un simple bouton.
3.
1.3
-----
-
[FIX] Usurpation d'un compte local en BDD
src/UnicaenAuth/Controller/UtilisateurController.php
View file @
ea6cd554
...
...
@@ -5,6 +5,7 @@ namespace UnicaenAuth\Controller;
use
UnicaenApp\Exception\RuntimeException
;
use
UnicaenApp\Mapper\Ldap\People
as
LdapPeopleMapper
;
use
UnicaenAuth\Entity\Db\AbstractUser
;
use
UnicaenAuth\Entity\Db\User
;
use
UnicaenAuth\Entity\Ldap\People
;
use
UnicaenAuth\Entity\Shibboleth\ShibUser
;
use
UnicaenAuth\Formatter\RoleFormatter
;
...
...
@@ -135,41 +136,54 @@ class UtilisateurController extends AbstractActionController
return
$this
->
redirect
()
->
toRoute
(
'home'
);
}
if
(
isset
(
$currentIdentity
[
'ldap'
]))
{
$username
=
null
;
if
(
$username
===
null
&&
isset
(
$currentIdentity
[
'db'
]))
{
/** @var AbstractUser $currentIdentity */
$identity
=
$currentIdentity
[
'db'
];
// vérif existence de l'utilisateur dans la base de données
$user
=
$this
->
getUserMapper
()
->
findByUsername
(
$newIdentity
);
if
(
$user
!==
null
)
{
$username
=
$user
->
getUsername
();
}
}
if
(
$username
===
null
&&
isset
(
$currentIdentity
[
'ldap'
]))
{
// si l'identifiant demandé contient un @, on estime qu'il s'agit d'un eppn shibboleth : on autorise pas le mélange des genres!
// todo: faire mieux
if
(
strpos
(
$newIdentity
,
'@'
)
!==
false
)
{
throw
new
RuntimeException
(
"Usurpation Shibboleth interdite depuis une authentification LDAP"
);
}
/** @var People $currentIdentity */
$
currentI
dentity
=
$currentIdentity
[
'ldap'
];
$
i
dentity
=
$currentIdentity
[
'ldap'
];
// vérif existence de l'individu dans l'annuaire LDAP
$ldapPeople
=
$this
->
getLdapPeopleMapper
()
->
findOneByUsername
(
$newIdentity
);
if
(
!
$ldapPeople
)
{
throw
new
RuntimeException
(
"Identifiant LDAP inconnu"
);
if
(
$ldapPeople
)
{
$username
=
$ldapPeople
->
getUsername
(
);
}
}
elseif
(
isset
(
$currentIdentity
[
'shib'
]))
{
}
if
(
$username
===
null
&&
isset
(
$currentIdentity
[
'shib'
]))
{
// si l'identifiant demandé ne contient pas @, on estime qu'il s'agit d'un identifiant LDAP : on autorise pas le mélange des genres!
// todo: faire mieux
if
(
strpos
(
$newIdentity
,
'@'
)
===
false
)
{
throw
new
RuntimeException
(
"Usurpation LDAP interdite depuis une authentification Shibboleth"
);
}
/** @var ShibUser $currentIdentity */
$currentIdentity
=
$currentIdentity
[
'shib'
];
$identity
=
$currentIdentity
[
'shib'
];
$username
=
$identity
->
getUsername
();
}
else
{
if
(
$username
===
null
)
{
return
$this
->
redirect
()
->
toRoute
(
'home'
);
}
// seuls les logins spécifiés dans la config sont habilités à usurper des identités
if
(
!
in_array
(
$
currentI
dentity
->
getUsername
(),
$this
->
options
->
getUsurpationAllowedUsernames
()))
{
if
(
!
in_array
(
$
i
dentity
->
getUsername
(),
$this
->
options
->
getUsurpationAllowedUsernames
()))
{
throw
new
RuntimeException
(
"Usurpation non explicitement autorisée"
);
}
// cuisine spéciale
pour
Shibboleth
if
(
$currentIdentity
instanceof
ShibUser
)
{
$fromShibUser
=
$currentIdentity
;
// cuisine spéciale
si l'utilisateur courant s'est authentifié via
Shibboleth
if
(
isset
(
$currentIdentity
[
'shib'
])
&&
$currentIdentity
[
'shib'
]
instanceof
ShibUser
)
{
$fromShibUser
=
$currentIdentity
[
'shib'
]
;
$toShibUser
=
$this
->
createShibUserFromUtilisateurUsername
(
$newIdentity
);
$this
->
shibService
->
activateUsurpation
(
$fromShibUser
,
$toShibUser
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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