Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
auth
Commits
ea78ac99
Commit
ea78ac99
authored
11 years ago
by
Bertrand Gauthier
Browse files
Options
Downloads
Patches
Plain Diff
Correction : aucun rôle sélectionné si aucun utilisateur authentifié.
parent
1d9253b3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/UnicaenAuth/Service/UserContext.php
+45
-8
45 additions, 8 deletions
src/UnicaenAuth/Service/UserContext.php
with
45 additions
and
8 deletions
src/UnicaenAuth/Service/UserContext.php
+
45
−
8
View file @
ea78ac99
...
@@ -5,8 +5,10 @@ namespace UnicaenAuth\Service;
...
@@ -5,8 +5,10 @@ namespace UnicaenAuth\Service;
use
Zend\ServiceManager\ServiceLocatorAwareInterface
;
use
Zend\ServiceManager\ServiceLocatorAwareInterface
;
use
Zend\ServiceManager\ServiceLocatorAwareTrait
;
use
Zend\ServiceManager\ServiceLocatorAwareTrait
;
use
Zend\Session\Container
as
SessionContainer
;
use
Zend\Session\Container
as
SessionContainer
;
use
Zend\Permissions\Acl\Role\RoleInterface
;
use
ZfcUser\Entity\UserInterface
;
use
ZfcUser\Entity\UserInterface
;
use
UnicaenAuth\Entity\Ldap\People
;
use
UnicaenAuth\Entity\Ldap\People
;
use
UnicaenAuth\Acl\NamedRole
;
/**
/**
* Service centralisant des méthodes utiles concernant l'utilisateur authentifié.
* Service centralisant des méthodes utiles concernant l'utilisateur authentifié.
...
@@ -44,6 +46,7 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -44,6 +46,7 @@ class UserContext implements ServiceLocatorAwareInterface
return
$identity
[
'db'
];
return
$identity
[
'db'
];
}
}
}
}
return
null
;
return
null
;
}
}
...
@@ -59,15 +62,16 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -59,15 +62,16 @@ class UserContext implements ServiceLocatorAwareInterface
return
$identity
[
'ldap'
];
return
$identity
[
'ldap'
];
}
}
}
}
return
null
;
return
null
;
}
}
/**
/**
* Retourne l'identité correspondant à l'utilisateur courant.
* Retourne l
es données d
'identité correspondant à l'utilisateur courant.
*
*
* @return mixed
* @return mixed
*/
*/
p
rotected
function
getIdentity
()
p
ublic
function
getIdentity
()
{
{
if
(
null
===
$this
->
identity
)
{
if
(
null
===
$this
->
identity
)
{
$authenticationService
=
$this
->
getServiceLocator
()
->
get
(
'Zend\Authentication\AuthenticationService'
);
$authenticationService
=
$this
->
getServiceLocator
()
->
get
(
'Zend\Authentication\AuthenticationService'
);
...
@@ -75,6 +79,7 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -75,6 +79,7 @@ class UserContext implements ServiceLocatorAwareInterface
$this
->
identity
=
$authenticationService
->
getIdentity
();
$this
->
identity
=
$authenticationService
->
getIdentity
();
}
}
}
}
return
$this
->
identity
;
return
$this
->
identity
;
}
}
...
@@ -90,6 +95,7 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -90,6 +95,7 @@ class UserContext implements ServiceLocatorAwareInterface
$identityProvider
=
$authorize
->
getIdentityProvider
();
$identityProvider
=
$authorize
->
getIdentityProvider
();
$this
->
identityRoles
=
$identityProvider
->
getIdentityRoles
();
$this
->
identityRoles
=
$identityProvider
->
getIdentityRoles
();
}
}
return
$this
->
identityRoles
;
return
$this
->
identityRoles
;
}
}
...
@@ -102,20 +108,24 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -102,20 +108,24 @@ class UserContext implements ServiceLocatorAwareInterface
{
{
return
array_filter
(
return
array_filter
(
$this
->
getIdentityRoles
(),
$this
->
getIdentityRoles
(),
function
(
$r
)
{
return
!
(
$r
instanceof
\UnicaenAuth\Acl\
NamedRole
&&
!
$r
->
getSelectable
());
});
function
(
$r
)
{
return
!
(
$r
instanceof
NamedRole
&&
!
$r
->
getSelectable
());
});
}
}
/**
/**
* Retourne le rôle utilisateur sélectionné, ou le premier sélectionnable si aucun n'a été sléectionné.
* 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é.
*
*
* @return mixed
* @return mixed
*/
*/
public
function
getSelectedIdentityRole
()
public
function
getSelectedIdentityRole
()
{
{
if
(
null
===
$this
->
getSessionContainer
()
->
selectedIdentityRole
)
{
if
(
null
===
$this
->
getSessionContainer
()
->
selectedIdentityRole
)
{
if
(
$this
->
getIdentity
())
{
$roles
=
$this
->
getSelectableIdentityRoles
();
$roles
=
$this
->
getSelectableIdentityRoles
();
$this
->
getSessionContainer
()
->
selectedIdentityRole
=
reset
(
$roles
)
?:
null
;
$this
->
getSessionContainer
()
->
selectedIdentityRole
=
reset
(
$roles
)
?:
null
;
}
}
}
return
$this
->
getSessionContainer
()
->
selectedIdentityRole
;
return
$this
->
getSessionContainer
()
->
selectedIdentityRole
;
}
}
...
@@ -131,14 +141,39 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -131,14 +141,39 @@ class UserContext implements ServiceLocatorAwareInterface
if
(
!
$this
->
isRoleValid
(
$role
))
{
if
(
!
$this
->
isRoleValid
(
$role
))
{
throw
new
\Common\Exception\RuntimeException
(
"Rôle spécifié invalide."
);
throw
new
\Common\Exception\RuntimeException
(
"Rôle spécifié invalide."
);
}
}
$this
->
getSessionContainer
()
->
selectedIdentityRole
=
$role
;
$this
->
getSessionContainer
()
->
selectedIdentityRole
=
$this
->
normalizedIdentityRole
(
$role
)
;
}
}
else
{
else
{
unset
(
$this
->
getSessionContainer
()
->
selectedIdentityRole
);
unset
(
$this
->
getSessionContainer
()
->
selectedIdentityRole
);
}
}
return
$this
;
return
$this
;
}
}
/**
* Recherche le role spécifié parmi les rôles connus au format objets.
*
* @param mixed $role
* @return mixed Role trouvé au format objet dans la mesure du possible
*/
protected
function
normalizedIdentityRole
(
$role
)
{
if
(
is_object
(
$role
))
{
return
$role
;
}
foreach
(
$this
->
getIdentityRoles
()
as
$r
)
{
if
(
$r
instanceof
RoleInterface
&&
$role
===
$r
->
getRoleId
())
{
return
$r
;
}
if
(
$role
===
$r
)
{
return
$r
;
}
}
return
$role
;
}
/**
/**
* Teste si le rôle spécifié fait partie des rôles disponibles.
* Teste si le rôle spécifié fait partie des rôles disponibles.
*
*
...
@@ -148,13 +183,14 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -148,13 +183,14 @@ class UserContext implements ServiceLocatorAwareInterface
protected
function
isRoleValid
(
$role
)
protected
function
isRoleValid
(
$role
)
{
{
foreach
(
$this
->
getIdentityRoles
()
as
$r
)
{
foreach
(
$this
->
getIdentityRoles
()
as
$r
)
{
if
(
$r
instanceof
\Zend\Permissions\Acl\Role\
RoleInterface
)
{
if
(
$r
instanceof
RoleInterface
)
{
$r
=
$r
->
getRoleId
();
$r
=
$r
->
getRoleId
();
}
}
if
(
$role
===
$r
)
{
if
(
$role
===
$r
)
{
return
true
;
return
true
;
}
}
}
}
return
false
;
return
false
;
}
}
...
@@ -169,6 +205,7 @@ class UserContext implements ServiceLocatorAwareInterface
...
@@ -169,6 +205,7 @@ class UserContext implements ServiceLocatorAwareInterface
if
(
null
===
$this
->
sessionContainer
)
{
if
(
null
===
$this
->
sessionContainer
)
{
$this
->
sessionContainer
=
new
SessionContainer
(
get_class
());
$this
->
sessionContainer
=
new
SessionContainer
(
get_class
());
}
}
return
$this
->
sessionContainer
;
return
$this
->
sessionContainer
;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment