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
=========
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
-----
- Modifications/améliorations pour faciliter le support d'autres modes d'authentification (ex: unicaen/auth-token).
......
......@@ -9,10 +9,12 @@ use UnicaenApp\Exception\RuntimeException;
use UnicaenAuth\Authentication\Adapter\Cas;
use UnicaenAuth\Authentication\Adapter\LocalAdapter;
use UnicaenAuth\Authentication\Adapter\Shib;
use UnicaenAuth\Entity\Db\Role;
use UnicaenAuth\Form\LoginForm;
use UnicaenAuth\Options\Traits\ModuleOptionsAwareTrait;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\Traits\ShibServiceAwareTrait;
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;
use UnicaenAuth\Service\Traits\UserServiceAwareTrait;
use Zend\Http\Request;
use Zend\Http\Response;
......@@ -43,6 +45,7 @@ class AuthController extends AbstractActionController
use ShibServiceAwareTrait;
use UserServiceAwareTrait;
use UserContextServiceAwareTrait;
use ModuleOptionsAwareTrait;
/**
......@@ -131,8 +134,12 @@ class AuthController extends AbstractActionController
}
$redirect = $this->getRequestedRedirect();
$queryParams = ['query' => ($redirect ? ['redirect' => $redirect] : [])];
$url = $this->url()->fromRoute(null, [], $queryParams, true);
$roleId = $this->params()->fromPost('role', $this->params()->fromQuery('role', false));
$queryParams = array_filter([
'redirect' => $redirect ?: null,
'role' => $roleId ?: null,
]);
$url = $this->url()->fromRoute(null, [], ['query' => $queryParams], true);
$form->setAttribute('action', $url);
if (!$request->isPost()) {
......@@ -232,6 +239,7 @@ class AuthController extends AbstractActionController
$type = $this->params('type');
$adapter = $this->zfcUserAuthentication()->getAuthAdapter();
$redirect = $this->params()->fromPost('redirect', $this->params()->fromQuery('redirect', false));
$roleId = $this->params()->fromPost('role', $this->params()->fromQuery('role', false));
$request = $this->getRequest();
$request->getPost()->set('type', $type);
......@@ -244,11 +252,19 @@ class AuthController extends AbstractActionController
$auth = $this->zfcUserAuthentication()->getAuthService()->authenticate($adapter);
if ($roleId) {
$this->serviceUserContext->setNextSelectedIdentityRole($roleId);
}
if (!$auth->isValid()) {
$message = $auth->getMessages()[0] ?? $this->failedLoginMessage;
$this->flashMessenger()->setNamespace('zfcuser-login-form')->addMessage($message);
$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);
}
......
......@@ -7,6 +7,7 @@ use UnicaenAuth\Form\LoginForm;
use UnicaenAuth\Options\ModuleOptions;
use UnicaenAuth\Service\ShibService;
use UnicaenAuth\Service\User as UserService;
use UnicaenAuth\Service\UserContext;
use ZfcUser\Controller\RedirectCallback;
class AuthControllerFactory
......@@ -23,6 +24,9 @@ class AuthControllerFactory
/* @var $userService UserService */
$userService = $container->get('unicaen-auth_user_service');
/* @var $userContextService UserContext */
$userContextService = $container->get(UserContext::class);
/** @var ModuleOptions $moduleOptions */
$moduleOptions = $container->get('unicaen-auth_module_options');
......@@ -32,6 +36,7 @@ class AuthControllerFactory
$controller = new AuthController();
$controller->setShibService($shibService);
$controller->setUserService($userService);
$controller->setServiceUserContext($userContextService);
$controller->setModuleOptions($moduleOptions);
$controller->setRedirectCallback($redirectCallback);
......
......@@ -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.
*
* @param RoleInterface|string $role
* @param RoleInterface|string $role Le ROLE_ID du rôle (string) ou une instance (RoleInterface)
*
* @return \UnicaenAuth\Service\UserContext
*/
......@@ -396,12 +396,13 @@ class UserContext extends AbstractService implements EventManagerAwareInterface
unset($this->getSessionContainer()->nextSelectedIdentityRole);
}
$role = $this->getSelectableIdentityRoles()[$role];
$role = $this->getSelectableIdentityRoles()[$role] ?? null;
if ($role instanceof AbstractRole) {
$this->saveUserLastRole($role);
}
$this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role);
if ($role) {
$this->triggerUserRoleSelectedEvent(UserRoleSelectedEvent::POST_SELECTION, $role);
}
return $this;
}
......
Markdown is supported
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