Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\Security\Core\Security;

class DefaultController extends Controller
{
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(),
));
}

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;
}
Expand Down
10 changes: 6 additions & 4 deletions EventListener/LdapListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,7 +21,7 @@

class LdapListener extends AbstractAuthenticationListener
{
public function __construct(SecurityContextInterface $securityContext,
public function __construct(TokenStorageInterface $securityContext,
AuthenticationManagerInterface $authenticationManager,
SessionAuthenticationStrategyInterface $sessionStrategy,
HttpUtils $httpUtils,
Expand All @@ -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,
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 4 additions & 0 deletions Factory/LdapFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
5 changes: 3 additions & 2 deletions Manager/LdapManagerUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Resources/config/security_ldap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<service id="imag_ldap.security.authentication.listener" class="%imag_ldap.security.authentication.listener.class%" public="false">
<tag name="monolog.logger" channel="security" />
<argument type="service" id="security.context" />
<argument type="service" id="security.token_storage" />
<argument type="service" id="security.authentication.manager" />
<argument type="service" id="security.authentication.session_strategy" />
<argument type="service" id="security.http_utils" />
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"require": {
"php": ">=5.3.3",
"ext-ldap": "*",
"symfony/symfony": ">2.0"
"symfony/symfony": "3.2.*"
},
"autoload": {
"psr-0": { "IMAG\\LdapBundle": "" }
Expand Down