I have the following script presented to me:
- Authentication with AD
- AD server returns the identification string "foo \ bar"
- Upon successful authentication, the LOGIN_SUCCESS event is fired with an identification string and an adapter as parameters
Once this event is fired, there are several triggers.
- The first listener checks to see if a user row exists in the database with the matching "line foo \ bar". If not, User-Row will be created.
- Each time you log in, another Listener will update the User-Metadata provided by the adapter.
- I would like to have a third listener that changes the identity string "foo \ bar" to a user object from User-Row to DB
Currently mine AuthenticationServicelooks like this:
if ($result->isValid()) {
$currentIdentity = $result->getIdentity();
$eventManager = new EventManager(__CLASS__);
$eventResult = $eventManager->trigger(self::DUIT_USER_LOGIN_SUCCESSFUL, $this, [
'identity' => $currentIdentity,
'adapter' => $adapter
]);
if ($eventResult->last() instanceof EventInterface) {
$identityObject = $eventResult->last()->getParam('identity');
if ($identityObject instanceof User) {
$this->getStorage()->write($identityObject);
return $result;
}
}
$this->getStorage()->write($result->getIdentity());
}
As you can see, I am doing this here, which does not actually belong AuthenticationService. Is there a way Eventthis can change parameter(in this case identity) so that the parameter value is changed in the background?
I really don't want to do this event check in AuthenticationService. This assumption simply should not be, but I really see no other way to do something.
//Edit
Currently, the trigger does this in the background:
public function handleWorkflow(EventInterface $event)
{
$identityString = $event->getParam('identity');
$userObject = $this->userService->findByActiveDirectoryId($identityString);
if ($userObject instanceof User) {
return $event->setParam('identity', $userObject);
}
return $event->setParam('identity', $identityString);
}
source
share