Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
utilisateur
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
utilisateur
Commits
cde2e75c
Commit
cde2e75c
authored
2 years ago
by
Jean-Philippe Metivier
Browse files
Options
Downloads
Patches
Plain Diff
Parametrage de la récup du username en fonction de config
parent
599c17da
No related branches found
No related tags found
No related merge requests found
Pipeline
#17589
passed
2 years ago
Stage: release
Stage: publish
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/UnicaenUtilisateur/Service/User/UserService.php
+30
-20
30 additions, 20 deletions
src/UnicaenUtilisateur/Service/User/UserService.php
src/UnicaenUtilisateur/Service/User/UserServiceFactory.php
+6
-1
6 additions, 1 deletion
src/UnicaenUtilisateur/Service/User/UserServiceFactory.php
with
36 additions
and
21 deletions
src/UnicaenUtilisateur/Service/User/UserService.php
+
30
−
20
View file @
cde2e75c
...
...
@@ -3,8 +3,8 @@
namespace
UnicaenUtilisateur\Service\User
;
use
Doctrine\ORM\EntityRepository
;
use
Doctrine\ORM\NonUniqueResultException
;
use
Doctrine\ORM\ORMException
;
use
InvalidArgumentException
;
use
Ramsey\Uuid\Uuid
;
use
UnicaenApp\Entity\Ldap\People
;
use
UnicaenApp\Service\EntityManagerAwareTrait
;
...
...
@@ -29,19 +29,24 @@ class UserService implements RechercheIndividuServiceInterface
use
RoleServiceAwareTrait
;
use
MailServiceAwareTrait
;
/**
* @var string
*/
private
$userEntityClass
;
private
?string
$userEntityClass
=
null
;
private
?array
$authentificationConfig
=
null
;
/**
* @var AuthenticationService
*/
private
$authenticationService
;
public
function
getAuthentificationConfig
():
?array
{
return
$this
->
authentificationConfig
;
}
public
function
setAuthentificationConfig
(
?array
$authentificationConfig
):
void
{
$this
->
authentificationConfig
=
$authentificationConfig
;
}
private
?AuthenticationService
$authenticationService
;
private
$renderer
;
public
function
setRenderer
(
$renderer
)
{
$this
->
renderer
=
$renderer
;}
private
$appname
;
private
?string
$appname
=
null
;
public
function
setAppname
(
$appname
)
{
$this
->
appname
=
$appname
;}
...
...
@@ -49,19 +54,18 @@ class UserService implements RechercheIndividuServiceInterface
* @param string $userEntityClass
* @return void
*/
public
function
setUserEntityClass
(
$userEntityClass
)
public
function
setUserEntityClass
(
string
$userEntityClass
)
:
void
{
if
(
!
class_exists
(
$userEntityClass
)
||
!
in_array
(
UserInterface
::
class
,
class_implements
(
$userEntityClass
)))
{
throw
new
InvalidArgumentException
(
"L'entité associée aux utilisateurs doit implémenter "
.
UserInterface
::
class
);
}
$this
->
userEntityClass
=
$userEntityClass
;
}
/**
* @return string
*/
public
function
getEntityClass
()
public
function
getEntityClass
()
:
?string
{
return
$this
->
userEntityClass
;
}
...
...
@@ -71,7 +75,7 @@ class UserService implements RechercheIndividuServiceInterface
*
* @return UserInterface
*/
public
function
getEntityInstance
()
public
function
getEntityInstance
()
:
UserInterface
{
return
new
$this
->
userEntityClass
;
}
...
...
@@ -346,19 +350,25 @@ class UserService implements RechercheIndividuServiceInterface
return
$qb
->
getQuery
()
->
getResult
();
}
/**
* @return UserInterface
*/
public
function
getConnectedUser
()
public
function
getConnectedUser
()
:
?UserInterface
{
$identity
=
$this
->
authenticationService
->
getIdentity
();
if
(
$identity
)
{
$username
=
null
;
if
(
isset
(
$identity
[
'ldap'
]))
{
/** @var People $userIdentity */
$userIdentity
=
$identity
[
'ldap'
];
switch
(
$this
->
getAuthentificationConfig
()[
'local'
][
'ldap'
][
'username'
])
{
case
'uid'
:
$username
=
$userIdentity
->
getUid
();
break
;
case
'supannaliaslogin'
:
$username
=
$userIdentity
->
getSupannAliasLogin
();
break
;
default
:
throw
new
RuntimeException
(
"La clef de config [unicaen-auth][loca][ldap][username] n'est pas défini ou à une valeur non attendue."
);
}
$user
=
$this
->
findByUsername
(
$username
);
return
$user
;
...
...
This diff is collapsed.
Click to expand it.
src/UnicaenUtilisateur/Service/User/UserServiceFactory.php
+
6
−
1
View file @
cde2e75c
...
...
@@ -5,6 +5,8 @@ namespace UnicaenUtilisateur\Service\User;
use
Doctrine\ORM\EntityManager
;
use
Interop\Container\ContainerInterface
;
use
Laminas\View\Renderer\PhpRenderer
;
use
Psr\Container\ContainerExceptionInterface
;
use
Psr\Container\NotFoundExceptionInterface
;
use
UnicaenAuthentification\Service\UserContext
;
use
UnicaenMail\Service\Mail\MailService
;
use
UnicaenUtilisateur\Entity\Db\User
;
...
...
@@ -20,8 +22,10 @@ class UserServiceFactory
* @param string $requestedName
* @param array|null $options
* @return UserService
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public
function
__invoke
(
ContainerInterface
$container
,
$requestedName
,
array
$options
=
null
)
public
function
__invoke
(
ContainerInterface
$container
,
$requestedName
,
array
$options
=
null
)
:
UserService
{
/**
* @var EntityManager $entityManager
...
...
@@ -43,6 +47,7 @@ class UserServiceFactory
$service
->
setRoleService
(
$roleService
);
$service
->
setServiceUserContext
(
$userContext
);
$service
->
setUserEntityClass
(
$allConfig
[
'zfcuser'
][
'user_entity_class'
]
??
User
::
class
);
$service
->
setAuthentificationConfig
(
$allConfig
[
'unicaen-auth'
]);
$service
->
setAuthenticationService
(
$authenticationService
);
/* @var PhpRenderer $renderer */
...
...
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