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
ca921e67
Commit
ca921e67
authored
Jan 08, 2019
by
David Surville
Browse files
Merge branch 'master' of
https://git.unicaen.fr/lib/unicaen/auth
parents
ebe17fd7
cb8ef280
Pipeline
#3154
failed with stages
in 2 minutes and 48 seconds
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/UnicaenAuth/Controller/UtilisateurController.php
View file @
ca921e67
...
...
@@ -50,10 +50,8 @@ class UtilisateurController extends AbstractActionController
}
if
(
$addFlashMessage
)
{
$message
=
sprintf
(
"Vous endossez à présent le profil utilisateur <strong>%s</strong>."
,
$this
->
getAuthUserContextService
()
->
getSelectedIdentityRole
()
->
getRoleId
()
);
$selectedRole
=
$this
->
getAuthUserContextService
()
->
getSelectedIdentityRoleToString
();
$message
=
sprintf
(
"Vous endossez à présent le profil utilisateur <strong>%s</strong>."
,
$selectedRole
);
$this
->
flashMessenger
()
->
setNamespace
(
'UnicaenAuth/success'
)
->
addMessage
(
$message
);
}
...
...
src/UnicaenAuth/Formatter/RoleFormatter.php
0 → 100644
View file @
ca921e67
<?php
namespace
UnicaenAuth\Formatter
;
use
Zend\Permissions\Rbac\RoleInterface
;
class
RoleFormatter
{
/**
* Retourne le rôle utilisateur spécifié au format littéral.
*
* @param $role
* @return string
*/
public
function
format
(
$role
)
{
return
$this
->
roleToString
(
$role
);
}
/**
* Retourne le rôle utilisateur spécifié au format littéral.
*
* @param object|RoleInterface|string $role
* @return string
*/
private
function
roleToString
(
$role
)
{
$string
=
'?'
;
if
(
is_object
(
$role
)
&&
method_exists
(
$role
,
'__toString'
))
{
$string
=
(
string
)
$role
;
}
elseif
(
$role
instanceof
RoleInterface
)
{
$string
=
$role
->
getRoleId
();
}
elseif
(
is_string
(
$role
))
{
$string
=
$role
;
}
return
$string
;
}
}
\ No newline at end of file
src/UnicaenAuth/Provider/Identity/Chain.php
View file @
ca921e67
<?php
namespace
UnicaenAuth\Provider\Identity
;
use
BjyAuthorize\Provider\Identity\ProviderInterface
;
...
...
@@ -76,7 +77,7 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan
// collecte des rôles
$this
->
getEventManager
()
->
trigger
(
'getIdentityRoles'
,
$e
);
$roles
=
$e
->
getRoles
();
$roles
=
$e
->
getRoles
();
/** @var RoleInterface[] $roles */
$authorizeService
=
$this
->
getServiceLocator
()
->
get
(
'BjyAuthorize\Service\Authorize'
);
/* @var $authorizeService Authorize */
...
...
@@ -88,14 +89,14 @@ class Chain implements ProviderInterface, ServiceLocatorAwareInterface, EventMan
}
// évite les doublons
if
(
!
$registry
->
has
(
$role
))
{
$role
=
$authorizeService
->
getAcl
()
->
getRole
(
$role
);
if
(
is_string
(
$role
))
{
$role
=
$authorizeService
->
getAcl
()
->
getRole
(
$role
);
}
$registry
->
add
(
$role
);
$this
->
roles
[
$role
->
getRoleId
()]
=
$role
;
}
}
// var_dump($this->roles);
return
$this
->
roles
;
}
...
...
src/UnicaenAuth/Service/UserContext.php
View file @
ca921e67
...
...
@@ -5,21 +5,21 @@ namespace UnicaenAuth\Service;
use
BjyAuthorize\Acl\Role
;
use
UnicaenApp\Exception\RuntimeException
;
use
UnicaenApp\Traits\SessionContainerTrait
;
use
UnicaenAuth\Acl\NamedRole
;
use
UnicaenAuth\Entity\Ldap\People
;
use
UnicaenAuth\Entity\Shibboleth\ShibUser
;
use
UnicaenAuth\Event\UserRoleSelectedEvent
;
use
UnicaenAuth\Formatter\RoleFormatter
;
use
UnicaenAuth\Provider\Identity\Chain
;
use
Zend\EventManager\EventManagerAwareInterface
;
use
Zend\
Session\Container
as
SessionContainer
;
use
Zend\
EventManager\EventManagerAwareTrait
;
use
Zend\Permissions\Acl\Role\RoleInterface
;
use
ZfcUser\Entity\UserInterface
;
use
UnicaenAuth\Entity\Ldap\People
;
use
UnicaenAuth\Acl\NamedRole
;
use
Zend\EventManager\EventManagerAwareTrait
;
/**
* Service centralisant des méthodes utiles concernant l'utilisateur authentifié.
*
* @author
Laurent LÉCLUSE <laurent.lecluse at u
nicaen
.fr>
* @author
U
nicaen
*/
class
UserContext
extends
AbstractService
implements
EventManagerAwareInterface
{
...
...
@@ -36,8 +36,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
*/
protected
$identityRoles
;
/**
* Retourne l'utilisateur BDD courant
*
...
...
@@ -54,8 +52,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
null
;
}
/**
* Retourne l'utilisateur LDAP courant
*
...
...
@@ -72,8 +68,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
null
;
}
/**
* Retourne l'éventuel utilisateur Shibboleth courant.
*
...
...
@@ -90,8 +84,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
null
;
}
/**
* Retourne les données d'identité correspondant à l'utilisateur courant.
*
...
...
@@ -109,7 +101,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
$this
->
identity
;
}
/**
* Retourne l'identifiant de connexion de l'utilisateur courant.
*
...
...
@@ -130,8 +121,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
null
;
}
/**
* @param string $roleId
*
...
...
@@ -147,8 +136,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
null
;
}
/**
* Retourne tous les rôles de l'utilisateur courant, pas seulement le rôle courant sélectionné.
*
...
...
@@ -164,15 +151,16 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
$roles
=
$this
->
getServiceAuthorize
()
->
getRoles
();
$identityProvider
=
$this
->
getIdentityProvider
();
if
(
$identityProvider
instanceof
Chain
)
{
$iRoles
=
$identityProvider
->
getAllIdentityRoles
();
$i
dentity
Roles
=
$identityProvider
->
getAllIdentityRoles
();
}
else
{
$iRoles
=
$identityProvider
->
getIdentityRoles
();
$i
dentity
Roles
=
$identityProvider
->
getIdentityRoles
();
}
foreach
(
$iRoles
as
$role
)
{
if
(
$role
instanceof
Role
)
{
foreach
(
$i
dentity
Roles
as
$role
)
{
if
(
$role
instanceof
Role
Interface
)
{
$this
->
identityRoles
[
$role
->
getRoleId
()]
=
$role
;
}
elseif
(
isset
(
$roles
[
$role
]))
{
$role
=
$roles
[
$role
];
}
elseif
(
is_string
(
$role
)
&&
isset
(
$roles
[
$role
]))
{
$role
=
$roles
[
$role
];
/** @var RoleInterface $role */
$this
->
identityRoles
[
$role
->
getRoleId
()]
=
$role
;
}
}
...
...
@@ -181,7 +169,23 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
$this
->
identityRoles
;
}
/**
* Retourne tous les rôles de l'utilisateur courant au format littéral.
*
* @return array
* @see getIdentityRoles()
*/
public
function
getIdentityRolesToString
()
{
$f
=
new
RoleFormatter
();
$rolesToStrings
=
[];
foreach
(
$this
->
getIdentityRoles
()
as
$identityRole
)
{
$rolesToStrings
[
$identityRole
->
getRoleId
()]
=
$f
->
format
(
$identityRole
);
}
return
$rolesToStrings
;
}
/**
* Retourne parmi tous les rôles de l'utilisateur courant ceux qui peuvent être sélectionnés.
...
...
@@ -198,8 +202,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
$roles
;
}
/**
* Si un utilisateur est authentifié, retourne le rôle utilisateur sélectionné,
* ou alors le premier sélectionnable si aucun n'a été sélectionné.
...
...
@@ -207,11 +209,10 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
* NB: Si un rôle est spécifié en session comme devant être le prochain rôle sélectionné,
* c'est lui qui est pris en compte.
*
* @return
mixed
* @return
RoleInterface
*/
public
function
getSelectedIdentityRole
()
{
if
(
$this
->
getNextSelectedIdentityRole
())
{
$this
->
getSessionContainer
()
->
selectedIdentityRole
=
$this
->
getNextSelectedIdentityRole
();
}
...
...
@@ -222,10 +223,9 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
}
$roleId
=
$this
->
getSessionContainer
()
->
selectedIdentityRole
;
if
(
$roleId
)
{
$roles
=
$this
->
get
ServiceAuthorize
()
->
getRoles
();
// Récupération de tous les rôles du provider
// $roles = $this->getServiceAuthorize()->getRoles(); // Récupération de tous les rôles du provider
$roles
=
$this
->
get
IdentityRoles
();
if
(
isset
(
$roles
[
$roleId
]))
{
$role
=
$roles
[
$roleId
];
}
else
{
...
...
@@ -240,7 +240,24 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
null
;
}
/**
* Retourne le rôle utilisateur sélectionné éventuel au format littéral.
*
* @return string
* @see getSelectedIdentityRole()
*/
public
function
getSelectedIdentityRoleToString
()
{
$role
=
$this
->
getSelectedIdentityRole
();
if
(
!
$role
)
{
return
null
;
}
$f
=
new
RoleFormatter
();
return
$f
->
format
(
$role
);
}
/**
* Mémorise en session le rôle spécifié comme étant le rôle courant de l'utilisateur.
...
...
@@ -271,8 +288,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
$this
;
}
/**
* Retourne l'éventuel rôle spécifié en session devant être le prochain rôle sélectionné.
*
...
...
@@ -283,8 +298,6 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
$this
->
getSessionContainer
()
->
nextSelectedIdentityRole
;
}
/**
* Mémorise en session le rôle devant être le prochain rôle sélectionné.
*
...
...
@@ -352,16 +365,15 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
return
false
;
}
/**
*
* @return
\UnicaenAuth\Provider\Identity\
Chain
* @return Chain
*/
private
function
getIdentityProvider
()
{
return
$this
->
getServiceAuthorize
()
->
getIdentityProvider
();
/* @var $identityProvider \UnicaenAuth\Provider\Identity\Chain */
}
/* @var $identityProvider Chain */
$identityProvider
=
$this
->
getServiceAuthorize
()
->
getIdentityProvider
();
return
$identityProvider
;
}
}
\ No newline at end of file
src/UnicaenAuth/View/Helper/UserProfile.php
View file @
ca921e67
<?php
namespace
UnicaenAuth\View\Helper
;
use
Zend\Permissions\Acl\Role\RoleInterface
;
namespace
UnicaenAuth\View\Helper
;
/**
* Aide de vue permettant d'afficher le profil de l'utilisateur connecté.
...
...
@@ -15,17 +14,12 @@ class UserProfile extends UserAbstract
*/
protected
$userProfileSelectable
=
false
;
/**
* @var array
*/
protected
$identityRoles
;
/**
* Point d'entrée.
*
* @param bool $userProfileSelectable Spécifie s'il faut afficher les profils
* de l'utilisateur sous forme d'une liste déroulante ou de boutons radios,
permettant
* ainsi à l'utilisateur de changer de profil courant.
*
de l'utilisateur sous forme d'une liste déroulante ou de boutons radios,
*
permettant
ainsi à l'utilisateur de changer de profil courant.
* @return self
*/
public
function
__invoke
(
$userProfileSelectable
=
false
)
...
...
@@ -62,8 +56,7 @@ class UserProfile extends UserAbstract
if
(
$this
->
userProfileSelectable
)
{
$html
.
=
$this
->
getView
()
->
userProfileSelect
(
false
);
}
else
{
}
else
{
$html
.
=
$this
->
getView
()
->
htmlList
(
$roles
);
}
...
...
@@ -80,19 +73,6 @@ class UserProfile extends UserAbstract
return
$this
->
render
();
}
/**
* Retourne les rôles de l'utilisateur courant.
*
* @return array
*/
protected
function
getIdentityRoles
()
{
if
(
null
===
$this
->
identityRoles
)
{
$this
->
identityRoles
=
$this
->
getUserContext
()
->
getIdentityRoles
();
}
return
$this
->
identityRoles
;
}
/**
* Retourne les rôles de l'utilisateur courant.
*
...
...
@@ -100,27 +80,7 @@ class UserProfile extends UserAbstract
*/
protected
function
getIdentityRolesAsOptions
()
{
$identityRoles
=
$this
->
getIdentityRoles
();
$roles
=
[];
foreach
(
$identityRoles
as
$id
=>
$role
)
{
$lib
=
'?'
;
if
(
is_object
(
$role
)
&&
method_exists
(
$role
,
'__toString'
))
{
$lib
=
(
string
)
$role
;
}
elseif
(
$role
instanceof
RoleInterface
)
{
$lib
=
$role
->
getRoleId
();
}
elseif
(
is_string
(
$role
))
{
$lib
=
$role
;
}
if
(
$this
->
getTranslator
())
{
$lib
=
$this
->
getTranslator
()
->
translate
(
$lib
,
$this
->
getTranslatorTextDomain
());
}
$roles
[
$id
]
=
$lib
;
}
return
$roles
;
return
$this
->
getUserContext
()
->
getIdentityRolesToString
();
}
/**
...
...
@@ -134,6 +94,7 @@ class UserProfile extends UserAbstract
public
function
setUserProfileSelectable
(
$userProfileSelectable
=
true
)
{
$this
->
userProfileSelectable
=
$userProfileSelectable
;
return
$this
;
}
}
\ No newline at end of file
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