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
auth
Commits
f908e668
Commit
f908e668
authored
Jun 04, 2021
by
Bertrand Gauthier
Browse files
[FIX] Usurpation d'un compte local (db) depuis une authentification shib
parent
f3344ee8
Pipeline
#9965
passed with stage
in 17 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/UnicaenAuth/Authentication/Storage/Shib.php
View file @
f908e668
...
...
@@ -46,11 +46,10 @@ class Shib extends AbstractStorage
$sessionIdentity
=
$this
->
storage
->
read
();
$username
=
$sessionIdentity
->
getUsername
();
// // L'identité en session doit ressembler à un EPPN.
// $looksLikeEppn = strpos($username, '@') !== false;
// if (! $looksLikeEppn) {
// return null;
// }
// L'identité en session doit ressembler à un EPPN.
if
(
!
ShibUser
::
isEppn
(
$username
))
{
return
null
;
}
return
$this
->
shibService
->
getAuthenticatedUser
();
}
...
...
src/UnicaenAuth/Entity/Shibboleth/ShibUser.php
View file @
f908e668
...
...
@@ -3,6 +3,7 @@
namespace
UnicaenAuth\Entity\Shibboleth
;
use
UnicaenAuth\Entity\Db\AbstractUser
;
use
Webmozart\Assert\Assert
;
use
ZfcUser\Entity\UserInterface
;
class
ShibUser
implements
UserInterface
...
...
@@ -47,6 +48,41 @@ class ShibUser implements UserInterface
*/
protected
$state
=
1
;
/**
* Teste si une chaîne ressemble à un EPPN.
*
* @param string $username
* @return bool
*/
static
public
function
isEppn
(
string
$username
)
{
if
((
$pos
=
strpos
(
$username
,
'@'
))
===
false
)
{
return
false
;
}
$domain
=
substr
(
$username
,
$pos
+
1
);
if
(
filter_var
(
$domain
,
FILTER_VALIDATE_DOMAIN
,
FILTER_FLAG_HOSTNAME
)
===
false
)
{
return
false
;
}
return
true
;
}
/**
* Extrait le domaine de l'EPPN spécifié.
*
* @param string $eppn
* @return string
*/
static
public
function
extractDomainFromEppn
(
string
$eppn
)
{
Assert
::
true
(
static
::
isEppn
(
$eppn
),
"La chaîne suivante n'est pas un EPPN valide : "
.
$eppn
);
$parts
=
explode
(
'@'
,
$eppn
);
return
$parts
[
1
];
}
/**
* Retourne la partie domaine DNS de l'EPPN.
* Retourne par exemple "unicaen.fr" lorsque l'EPPN est "tartempion@unicaen.fr"
...
...
@@ -55,9 +91,7 @@ class ShibUser implements UserInterface
*/
public
function
getEppnDomain
()
{
$parts
=
explode
(
'@'
,
$this
->
getEppn
());
return
$parts
[
1
];
return
static
::
extractDomainFromEppn
(
$this
->
getEppn
());
}
/**
...
...
@@ -75,6 +109,8 @@ class ShibUser implements UserInterface
*/
public
function
setEppn
(
$eppn
)
{
Assert
::
true
(
static
::
isEppn
(
$eppn
),
"La chaîne suivante n'est pas un EPPN valide : "
.
$eppn
);
$this
->
setUsername
(
$eppn
);
}
...
...
src/UnicaenAuth/Service/ShibService.php
View file @
f908e668
...
...
@@ -319,6 +319,11 @@ EOS;
*/
public
function
activateUsurpation
(
ShibUser
$currentShibUser
,
AbstractUser
$utilisateurUsurpe
):
self
{
if
(
!
ShibUser
::
isEppn
(
$utilisateurUsurpe
->
getUsername
()))
{
// cas d'usurpation d'un compte local (db) depuis une authentification shib
return
$this
;
}
$toShibUser
=
new
ShibUser
();
$toShibUser
->
setEppn
(
$utilisateurUsurpe
->
getUsername
());
$toShibUser
->
setId
(
uniqid
());
// peut pas mieux faire pour l'instant
...
...
Write
Preview
Supports
Markdown
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