Commit 6734f54a authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Merge branch 'release_3.2.2'

parents 76e25e7e 25755b88
Pipeline #10070 passed with stage
in 17 seconds
CHANGELOG CHANGELOG
========= =========
3.2.2
-----
- L'URL de connexion accepte désormais role=ROLE_ID pour sélectionner automatiquement ce rôle une fois authentifié.
3.2.1 3.2.1
----- -----
- Modifications/améliorations pour faciliter le support d'autres modes d'authentification (ex: unicaen/auth-token). - Modifications/améliorations pour faciliter le support d'autres modes d'authentification (ex: unicaen/auth-token).
......
...@@ -9,10 +9,12 @@ use UnicaenApp\Exception\RuntimeException; ...@@ -9,10 +9,12 @@ use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Authentication\Adapter\Cas; use UnicaenAuth\Authentication\Adapter\Cas;
use UnicaenAuth\Authentication\Adapter\LocalAdapter; use UnicaenAuth\Authentication\Adapter\LocalAdapter;
use UnicaenAuth\Authentication\Adapter\Shib; use UnicaenAuth\Authentication\Adapter\Shib;
use UnicaenAuth\Entity\Db\Role;
use UnicaenAuth\Form\LoginForm; use UnicaenAuth\Form\LoginForm;
use UnicaenAuth\Options\Traits\ModuleOptionsAwareTrait; use UnicaenAuth\Options\Traits\ModuleOptionsAwareTrait;
use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\Traits\ShibServiceAwareTrait; use UnicaenAuth\Service\Traits\ShibServiceAwareTrait;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use UnicaenAuth\Service\Traits\UserServiceAwareTrait; use UnicaenAuth\Service\Traits\UserServiceAwareTrait;
use Zend\Http\Request; use Zend\Http\Request;
use Zend\Http\Response; use Zend\Http\Response;
...@@ -43,6 +45,7 @@ class AuthController extends AbstractActionController ...@@ -43,6 +45,7 @@ class AuthController extends AbstractActionController
use ShibServiceAwareTrait; use ShibServiceAwareTrait;
use UserServiceAwareTrait; use UserServiceAwareTrait;
use UserContextServiceAwareTrait;
use ModuleOptionsAwareTrait; use ModuleOptionsAwareTrait;
/** /**
...@@ -131,8 +134,12 @@ class AuthController extends AbstractActionController ...@@ -131,8 +134,12 @@ class AuthController extends AbstractActionController
} }
$redirect = $this->getRequestedRedirect(); $redirect = $this->getRequestedRedirect();
$queryParams = ['query' => ($redirect ? ['redirect' => $redirect] : [])]; $roleId = $this->params()->fromPost('role', $this->params()->fromQuery('role', false));
$url = $this->url()->fromRoute(null, [], $queryParams, true); $queryParams = array_filter([
'redirect' => $redirect ?: null,
'role' => $roleId ?: null,
]);
$url = $this->url()->fromRoute(null, [], ['query' => $queryParams], true);
$form->setAttribute('action', $url); $form->setAttribute('action', $url);
if (!$request->isPost()) { if (!$request->isPost()) {
...@@ -232,6 +239,7 @@ class AuthController extends AbstractActionController ...@@ -232,6 +239,7 @@ class AuthController extends AbstractActionController
$type = $this->params('type'); $type = $this->params('type');
$adapter = $this->zfcUserAuthentication()->getAuthAdapter(); $adapter = $this->zfcUserAuthentication()->getAuthAdapter();
$redirect = $this->params()->fromPost('redirect', $this->params()->fromQuery('redirect', false)); $redirect = $this->params()->fromPost('redirect', $this->params()->fromQuery('redirect', false));
$roleId = $this->params()->fromPost('role', $this->params()->fromQuery('role', false));
$request = $this->getRequest(); $request = $this->getRequest();
$request->getPost()->set('type', $type); $request->getPost()->set('type', $type);
...@@ -244,11 +252,19 @@ class AuthController extends AbstractActionController ...@@ -244,11 +252,19 @@ class AuthController extends AbstractActionController
$auth = $this->zfcUserAuthentication()->getAuthService()->authenticate($adapter); $auth = $this->zfcUserAuthentication()->getAuthService()->authenticate($adapter);
if ($roleId) {
$this->serviceUserContext->setNextSelectedIdentityRole($roleId);
}
if (!$auth->isValid()) { if (!$auth->isValid()) {
$message = $auth->getMessages()[0] ?? $this->failedLoginMessage; $message = $auth->getMessages()[0] ?? $this->failedLoginMessage;
$this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage($message); $this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage($message);
$adapter->resetAdapters(); $adapter->resetAdapters();
$url = $this->url()->fromRoute(null, [], ['query' => $redirect ? ['redirect' => $redirect] : []], true); $queryParams = array_filter([
'redirect' => $redirect ?: null,
'role' => $roleId ?: null,
]);
$url = $this->url()->fromRoute(null, [], ['query' => $queryParams], true);
return $this->redirect()->toUrl($url); return $this->redirect()->toUrl($url);
} }
......
...@@ -7,6 +7,7 @@ use UnicaenAuth\Form\LoginForm; ...@@ -7,6 +7,7 @@ use UnicaenAuth\Form\LoginForm;
use UnicaenAuth\Options\ModuleOptions; use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\ShibService; use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\User as UserService; use UnicaenAuth\Service\User as UserService;
use UnicaenAuth\Service\UserContext;
use ZfcUser\Controller\RedirectCallback; use ZfcUser\Controller\RedirectCallback;
class AuthControllerFactory class AuthControllerFactory
...@@ -23,6 +24,9 @@ class AuthControllerFactory ...@@ -23,6 +24,9 @@ class AuthControllerFactory
/* @var $userService UserService */ /* @var $userService UserService */
$userService = $container->get('unicaen-auth_user_service'); $userService = $container->get('unicaen-auth_user_service');
/* @var $userContextService UserContext */
$userContextService = $container->get(UserContext::class);
/** @var ModuleOptions $moduleOptions */ /** @var ModuleOptions $moduleOptions */
$moduleOptions = $container->get('unicaen-auth_module_options'); $moduleOptions = $container->get('unicaen-auth_module_options');
...@@ -32,6 +36,7 @@ class AuthControllerFactory ...@@ -32,6 +36,7 @@ class AuthControllerFactory
$controller = new AuthController(); $controller = new AuthController();
$controller->setShibService($shibService); $controller->setShibService($shibService);
$controller->setUserService($userService); $controller->setUserService($userService);
$controller->setServiceUserContext($userContextService);
$controller->setModuleOptions($moduleOptions); $controller->setModuleOptions($moduleOptions);
$controller->setRedirectCallback($redirectCallback); $controller->setRedirectCallback($redirectCallback);
......
...@@ -379,7 +379,7 @@ class UserContext extends AbstractService implements EventManagerAwareInterface ...@@ -379,7 +379,7 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
* *
* NB: seul l'id du rôle est mémorisé en session ; la durée de vie du stockage est de 1 requête seulement. * NB: seul l'id du rôle est mémorisé en session ; la durée de vie du stockage est de 1 requête seulement.
* *
* @param RoleInterface|string $role * @param RoleInterface|string $role Le ROLE_ID du rôle (string) ou une instance (RoleInterface)
* *
* @return \UnicaenAuth\Service\UserContext * @return \UnicaenAuth\Service\UserContext
*/ */
...@@ -396,12 +396,13 @@ class UserContext extends AbstractService implements EventManagerAwareInterface ...@@ -396,12 +396,13 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
unset($this->getSessionContainer()->nextSelectedIdentityRole); unset($this->getSessionContainer()->nextSelectedIdentityRole);
} }
$role = $this->getSelectableIdentityRoles()[$role]; $role = $this->getSelectableIdentityRoles()[$role] ?? null;
if ($role instanceof AbstractRole) { if ($role instanceof AbstractRole) {
$this->saveUserLastRole($role); $this->saveUserLastRole($role);
} }
if ($role) {
$this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role); $this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role);
}
return $this; return $this;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment