-
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into composer-proxies
# Conflicts: # src/Kernel.php
- Loading branch information
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\DependencyInjection\CompilerPass; | ||
|
||
use Packeton\Security\CheckLdapCredentialsListener; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class LdapServicesPass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$serviceId = 'security.listener.form_login_ldap.main'; | ||
if (!$container->hasDefinition($serviceId)) { | ||
return; | ||
} | ||
|
||
$container->getDefinition($serviceId)->setClass(CheckLdapCredentialsListener::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Packeton\Security; | ||
|
||
use Packeton\Entity\User; | ||
use Symfony\Component\Ldap\Security\CheckLdapCredentialsListener as SfCheckLdapCredentialsListener; | ||
use Symfony\Component\Ldap\Security\LdapBadge; | ||
use Symfony\Component\Security\Core\Exception\BadCredentialsException; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials; | ||
use Symfony\Component\Security\Http\Event\CheckPassportEvent; | ||
|
||
/** | ||
* Decorate default LdapCredentialsListener. If LDAP password login is failed, | ||
* then try to use next default system user CheckCredentialsListener if user was loaded from a database | ||
*/ | ||
class CheckLdapCredentialsListener extends SfCheckLdapCredentialsListener | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function onCheckPassport(CheckPassportEvent $event): void | ||
{ | ||
$passport = $event->getPassport(); | ||
|
||
try { | ||
parent::onCheckPassport($event); | ||
} catch (BadCredentialsException $e) { | ||
$user = $passport->getUser(); | ||
|
||
// Only if user exists in the local database, fallback to CheckCredentialsListener | ||
if ($user instanceof User && $passport->hasBadge(LdapBadge::class) && $passport->hasBadge(PasswordCredentials::class)) { | ||
if ($passport->getBadge(PasswordCredentials::class)->isResolved()) { | ||
throw new \LogicException('LDAP authentication password verification cannot be completed because something else has already resolved the PasswordCredentials.'); | ||
} | ||
|
||
$ldapBadge = $passport->getBadge(LdapBadge::class); | ||
$ldapBadge->markResolved(); | ||
return; | ||
} | ||
|
||
throw $e; | ||
} | ||
} | ||
} |