diff --git a/Controller/DefaultController.php b/Controller/DefaultController.php index ca5e760..e284448 100644 --- a/Controller/DefaultController.php +++ b/Controller/DefaultController.php @@ -12,7 +12,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\Security\Core\Security; class DefaultController extends Controller { @@ -20,8 +20,8 @@ public function loginAction() { $error = $this->getAuthenticationError(); - return $this->render('IMAGLdapBundle:Default:login.html.twig', array( - 'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME), + return $this->render('@IMAGLdapBundle\Default\login.html.twig', array( + 'last_username' => $this->get('request_stack')->getCurrentRequest()->get(Security::LAST_USERNAME), 'error' => $error, 'token' => $this->generateToken(), )); @@ -29,17 +29,17 @@ public function loginAction() protected function getAuthenticationError() { - if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { - return $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR); + if ($this->get('request_stack')->getCurrentRequest()->attributes->has(Security::AUTHENTICATION_ERROR)) { + return $this->get('request_stack')->getCurrentRequest()->attributes->get(Security::AUTHENTICATION_ERROR); } - return $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR); + return $this->get('request_stack')->getCurrentRequest()->getSession()->get(Security::AUTHENTICATION_ERROR); } protected function generateToken() { - $token = $this->get('form.csrf_provider') - ->generateCsrfToken('authenticate'); + $token = $this->get('security.csrf.token_manager') + ->getToken('authenticate'); return $token; } diff --git a/EventListener/LdapListener.php b/EventListener/LdapListener.php index 41978b0..2bbbb4b 100644 --- a/EventListener/LdapListener.php +++ b/EventListener/LdapListener.php @@ -9,7 +9,9 @@ Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface, Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken, Symfony\Component\Security\Core\Exception\InvalidCsrfTokenException, - Symfony\Component\Security\Core\SecurityContextInterface, + Symfony\Component\Security\Core\Security, + Symfony\Component\Security\Csrf\CsrfTokenManagerInterface, + Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface, Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface, Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface, Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener, @@ -19,7 +21,7 @@ class LdapListener extends AbstractAuthenticationListener { - public function __construct(SecurityContextInterface $securityContext, + public function __construct(TokenStorageInterface $securityContext, AuthenticationManagerInterface $authenticationManager, SessionAuthenticationStrategyInterface $sessionStrategy, HttpUtils $httpUtils, @@ -29,7 +31,7 @@ public function __construct(SecurityContextInterface $securityContext, array $options = array(), LoggerInterface $logger = null, EventDispatcherInterface $dispatcher = null, - CsrfProviderInterface $csrfProvider = null) + CsrfTokenManagerInterface $csrfProvider = null) { parent::__construct( $securityContext, @@ -86,7 +88,7 @@ public function attemptAuthentication(Request $request) $username = trim($request->get($this->options['username_parameter'], null, true)); $password = $request->get($this->options['password_parameter'], null, true); - $request->getSession()->set(SecurityContextInterface::LAST_USERNAME, $username); + $request->getSession()->set(Security::LAST_USERNAME, $username); return $this->authenticationManager->authenticate(new UsernamePasswordToken($username, $password, $this->providerKey)); } diff --git a/Factory/LdapFactory.php b/Factory/LdapFactory.php index 8eacecc..2dcb0d1 100644 --- a/Factory/LdapFactory.php +++ b/Factory/LdapFactory.php @@ -54,6 +54,10 @@ protected function createAuthProvider(ContainerBuilder $container, $id, $config, ->replaceArgument(2, $id) ; + if ($container->hasDefinition('security.user_checker')) { + $definition->replaceArgument(1, new Reference('security.user_checker.'.$id)); + } + $provider = 'imag_ldap.security.authentication.provider.'.$id; $container ->setDefinition($provider, new DefinitionDecorator('imag_ldap.security.authentication.provider')) diff --git a/Manager/LdapManagerUser.php b/Manager/LdapManagerUser.php index 6ba8953..3d3409e 100644 --- a/Manager/LdapManagerUser.php +++ b/Manager/LdapManagerUser.php @@ -203,8 +203,9 @@ private function addLdapRoles() } $this->ldapUser['roles'] = array(); - - if (true === $this->params['client']['skip_roles']) { + + $skipRoles = !empty($this->params['client']['skip_roles']) ? $this->params['client']['skip_roles'] : false; + if ($skipRoles) { $this->ldapUser['roles'] = array('ROLE_USER_DEFAULT'); return; diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index cbc2ea8..846a2cd 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,11 +1,11 @@ login: - pattern: /login + path: /login defaults: { _controller: IMAGLdapBundle:Default:login } requirements: _method: GET login_check: - pattern: /login_check + path: /login_check logout: - pattern: /logout + path: /logout diff --git a/Resources/config/security_ldap.xml b/Resources/config/security_ldap.xml index bf7cba1..5b9cdc0 100644 --- a/Resources/config/security_ldap.xml +++ b/Resources/config/security_ldap.xml @@ -45,7 +45,7 @@ - + diff --git a/composer.json b/composer.json index 4504db8..7230301 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "require": { "php": ">=5.3.3", "ext-ldap": "*", - "symfony/symfony": ">2.0" + "symfony/symfony": "3.2.*" }, "autoload": { "psr-0": { "IMAG\\LdapBundle": "" }