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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
auth
Commits
3715ca70
Commit
3715ca70
authored
Feb 19, 2013
by
Bertrand Gauthier
Browse files
Options
Downloads
Patches
Plain Diff
Déplacement service User de unicaen-user vers unicaen-auth
parent
bb424736
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/User.php
+187
-0
187 additions, 0 deletions
src/UnicaenAuth/Service/User.php
with
187 additions
and
0 deletions
src/UnicaenAuth/Service/User.php
0 → 100644
+
187
−
0
View file @
3715ca70
<?php
namespace
UnicaenAuth\Service
;
use
Zend\ServiceManager\ServiceManager
;
use
UnicaenApp\Service\Ldap\People
as
LdapPeopleService
;
use
UnicaenAuth\Options\AuthenticationOptionsInterface
;
use
\ZfcUser\Authentication\Adapter\AdapterChainEvent
as
AuthEvent
;
/**
* Service d'enregistrement dans la table des utilisateurs de l'application
* de l'utilisateur authentifié avec succès.
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
User
implements
\Zend\ServiceManager\ServiceManagerAwareInterface
{
/**
* @var ServiceManager
*/
protected
$serviceManager
;
/**
* @var AuthenticationOptionsInterface
*/
protected
$options
;
/**
* @var \ZfcUser\Options\ModuleOptions
*/
protected
$zfcUserOptions
;
/**
* @var LdapPeopleService
*/
protected
$ldapPeopleService
;
/**
* Save authenticated user in database from LDAP data.
*
* @return bool
*/
public
function
userAuthenticated
(
AuthEvent
$e
)
{
if
(
!
$this
->
getOptions
()
->
getSaveLdapUserInDatabase
())
{
return
false
;
}
if
(
!
(
$username
=
$e
->
getIdentity
()))
{
return
false
;
}
if
(
is_int
(
$username
))
{
// c'est un id: l'utilisateur existe déjà dans la bdd (et pas dans le LDAP), rien à faire
return
true
;
}
if
(
!
is_string
(
$username
))
{
throw
new
\UnicaenApp\Exception
(
"Identité rencontrée inattendue."
);
}
// recherche de l'individu dans l'annuaire LDAP
$ldapPeople
=
$this
->
getLdapPeopleService
()
->
getMapper
()
->
findByUsername
(
$username
);
if
(
!
$ldapPeople
)
{
return
false
;
}
// update/insert de l'utilisateur dans la table de l'appli
$mapper
=
$this
->
getServiceManager
()
->
get
(
'zfcuser_user_mapper'
);
/* @var $mapper \ZfcUser\Mapper\User */
try
{
$entity
=
$mapper
->
findByUsername
(
$username
);
}
catch
(
\PDOException
$pdoe
)
{
throw
new
\UnicaenApp\Exception
(
"Erreur lors de la recherche de l'utilisateur '
$username
' dans la base de données : "
.
$pdoe
->
getMessage
(),
null
,
$pdoe
);
return
true
;
}
if
(
!
$entity
)
{
$entityClass
=
$this
->
getZfcUserOptions
()
->
getUserEntityClass
();
$entity
=
new
$entityClass
;
$entity
->
setUsername
(
$username
);
$method
=
'insert'
;
}
else
{
$method
=
'update'
;
}
$entity
->
setEmail
(
$ldapPeople
->
getMail
());
$entity
->
setDisplayName
(
$ldapPeople
->
getDisplayName
());
$entity
->
setPassword
(
'ldap'
);
$entity
->
setState
(
in_array
(
'deactivated'
,
ldap_explode_dn
(
$ldapPeople
->
getDn
(),
1
))
?
0
:
1
);
try
{
$mapper
->
$method
(
$entity
);
}
catch
(
\PDOException
$pdoe
)
{
throw
new
\UnicaenApp\Exception
(
"Erreur lors de l'enregistrement de l'utilisateur '
$username
' dans la base de données : "
.
$pdoe
->
getMessage
(),
null
,
$pdoe
);
return
true
;
}
return
true
;
}
/**
* Retrieve service manager instance
*
* @return ServiceManager
*/
public
function
getServiceManager
()
{
return
$this
->
serviceManager
;
}
/**
* Set service manager
*
* @param ServiceManager $serviceManager
*/
public
function
setServiceManager
(
ServiceManager
$serviceManager
)
{
$this
->
serviceManager
=
$serviceManager
;
}
/**
* get ldap people service
*
* @return LdapPeopleService
*/
public
function
getLdapPeopleService
()
{
if
(
null
===
$this
->
ldapPeopleService
)
{
$this
->
ldapPeopleService
=
$this
->
getServiceManager
()
->
get
(
'ldap_people_service'
);
}
return
$this
->
ldapPeopleService
;
}
/**
* set ldap people service
*
* @param LdapPeopleService $service
* @return User
*/
public
function
setLdapPeopleService
(
LdapPeopleService
$service
)
{
$this
->
ldapPeopleService
=
$service
;
return
$this
;
}
/**
* @param AuthenticationOptionsInterface2 $options
*/
public
function
setOptions
(
AuthenticationOptionsInterface
$options
)
{
$this
->
options
=
$options
;
}
/**
* @return AuthenticationOptionsInterface
*/
public
function
getOptions
()
{
if
(
!
$this
->
options
instanceof
AuthenticationOptionsInterface
)
{
$this
->
setOptions
(
$this
->
getServiceManager
()
->
get
(
'unicaen-user_module_options'
));
}
return
$this
->
options
;
}
/**
* @param \ZfcUser\Options\AuthenticationOptionsInterface $options
*/
public
function
setZfcUserOptions
(
\ZfcUser\Options\AuthenticationOptionsInterface
$options
)
{
$this
->
zfcUserOptions
=
$options
;
}
/**
* @return \ZfcUser\Options\AuthenticationOptionsInterface
*/
public
function
getZfcUserOptions
()
{
if
(
!
$this
->
zfcUserOptions
instanceof
\ZfcUser\Options\AuthenticationOptionsInterface
)
{
$this
->
setZfcUserOptions
(
$this
->
getServiceManager
()
->
get
(
'zfcuser_module_options'
));
}
return
$this
->
zfcUserOptions
;
}
}
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
sign in
to comment