From f1eba1aa763efd39ad610438e1211a65f11bbe0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laurent=20L=C3=A9cluse?= <laurent.lecluse@unicaen.fr>
Date: Thu, 31 Aug 2017 09:05:07 +0000
Subject: [PATCH] =?UTF-8?q?Mise=20en=20place=20du=20mouchard=20sur=20la=20?=
 =?UTF-8?q?partie=20authentification=20(pour=20r=C3=A9cup=C3=A9rer=20l'ide?=
 =?UTF-8?q?ntit=C3=A9=20et=20le=20groupe=20de=20la=20personne=20qui=20a=20?=
 =?UTF-8?q?eu=20un=20dysfonctionement).?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

For more information, please contact laurent.lecluse@nsa.gov
---
 config/module.config.php                      |  4 +++
 .../Mouchard/MouchardCompleterAuth.php        | 31 +++++++++++++++++++
 .../Mouchard/MouchardCompleterAuthFactory.php | 30 ++++++++++++++++++
 3 files changed, 65 insertions(+)
 create mode 100644 src/UnicaenAuth/Mouchard/MouchardCompleterAuth.php
 create mode 100644 src/UnicaenAuth/Mouchard/MouchardCompleterAuthFactory.php

diff --git a/config/module.config.php b/config/module.config.php
index a5df943..e0b8030 100644
--- a/config/module.config.php
+++ b/config/module.config.php
@@ -369,6 +369,10 @@ return [
             'UnicaenAuth\Provider\Role\Username'       => 'UnicaenAuth\Provider\Role\UsernameServiceFactory',
             'BjyAuthorize\Service\Authorize'           => 'UnicaenAuth\Service\AuthorizeServiceFactory', // substituion
             'zfcuser_redirect_callback'                => 'UnicaenAuth\Authentication\RedirectCallbackFactory', // substituion
+            'MouchardCompleterAuth'        => 'UnicaenAuth\Mouchard\MouchardCompleterAuthFactory',
+        ],
+        'shared' => [
+            'MouchardCompleterAuth'        => false,
         ],
         'initializers'       => [
             'UnicaenAuth\Service\UserAwareInitializer',
diff --git a/src/UnicaenAuth/Mouchard/MouchardCompleterAuth.php b/src/UnicaenAuth/Mouchard/MouchardCompleterAuth.php
new file mode 100644
index 0000000..a310fd1
--- /dev/null
+++ b/src/UnicaenAuth/Mouchard/MouchardCompleterAuth.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace UnicaenAuth\Mouchard;
+
+use UnicaenApp\Mouchard\MouchardCompleterInterface;
+use UnicaenApp\Mouchard\MouchardMessage;
+use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
+use Zend\Mvc\Application;
+
+/**
+ * Interface MouchardCompleterInterface
+ *
+ * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
+ * @package UnicaenApp\Mouchard
+ */
+class MouchardCompleterAuth implements MouchardCompleterInterface
+{
+    use UserContextServiceAwareTrait;
+
+    /**
+     * @return $this
+     */
+    public function complete(MouchardMessage $message)
+    {
+        $message->setUser((string)$this->getServiceUserContext()->getDbUser()->getDisplayName());
+        $message->setRole((string)$this->getServiceUserContext()->getSelectedIdentityRole());
+
+        return $this;
+    }
+
+}
\ No newline at end of file
diff --git a/src/UnicaenAuth/Mouchard/MouchardCompleterAuthFactory.php b/src/UnicaenAuth/Mouchard/MouchardCompleterAuthFactory.php
new file mode 100644
index 0000000..bbbeeca
--- /dev/null
+++ b/src/UnicaenAuth/Mouchard/MouchardCompleterAuthFactory.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace UnicaenAuth\Mouchard;
+
+use Zend\ServiceManager\FactoryInterface;
+use Zend\ServiceManager\ServiceLocatorInterface;
+
+/**
+ * Description of MouchardCompleterAuthFactory
+ *
+ * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
+ */
+class MouchardCompleterAuthFactory implements FactoryInterface
+{
+    /**
+     * Create service
+     *
+     * @param ServiceLocatorInterface $serviceLocator
+     * @return MouchardCompleterAuth
+     */
+    public function createService(ServiceLocatorInterface $serviceLocator)
+    {
+        $mouchardCompleterAuth = new MouchardCompleterAuth();
+
+        $serviceUserContext = $serviceLocator->get('UnicaenAuth\Service\UserContext');
+        $mouchardCompleterAuth->setServiceUserContext($serviceUserContext);
+
+        return $mouchardCompleterAuth;
+    }
+}
\ No newline at end of file
-- 
GitLab