Hallo,
ich versuche einen eigenen Authenticator einzusetzen.
Dabei mache ich offensichtlich was falsch, hoffe nur eine Kleinigkeit.
So schaut es aus:
- src
- ContaoManager
- Security
Plugin.php
PHP-Code:
<?php
declare(strict_types=1);
namespace App\ContaoManager;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ContainerBuilder;
use Contao\ManagerPlugin\Config\ExtensionPluginInterface;
use App\Security\MyAuthenticator;
class Plugin implements BundlePluginInterface, ExtensionPluginInterface
{
public function getBundles(ParserInterface $parser): array
{
return null;
}
public function getExtensionConfig($extensionName, array $extensionConfigs, ContainerBuilder $container): array
{
if ('security' !== $extensionName) {
return $extensionConfigs;
}
foreach ($extensionConfigs as &$extensionConfig) {
if (isset($extensionConfig['firewalls'], $extensionConfig['firewalls']['contao_frontend'])) {
$extensionConfig['firewalls']['contao_frontend']['anonymous'] = 'lazy';
$extensionConfig['firewalls']['contao_frontend']['guard']['authenticators'][] = MyAuthenticator::class;
}
}
return $extensionConfigs;
}
}
MyAuthenticator.php
PHP-Code:
<?php
declare(strict_types=1);
namespace App\Security;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\Date;
use Contao\MemberModel;
use Contao\StringUtil;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpFoundation\IpUtils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
class MyAuthenticator extends AbstractGuardAuthenticator
{
/** @var Security */
private $security;
/** @var ContaoFramework */
private $framework;
/** @var string|null */
private $requestCondition;
public function __construct(Security $security, ContaoFramework $framework, ?string $requestCondition)
{
$this->security = $security;
$this->framework = $framework;
$this->requestCondition = $requestCondition;
}
public function supports(Request $request): bool
{
// If there already is a user logged in, don't to anything
if ($this->security->getUser()) {
return false;
}
}
public function getCredentials(Request $request): string
{
return null;
}
public function getUser($credentials, UserProviderInterface $userProvider): ?UserInterface
{
return null;
}
public function checkCredentials($credentials, UserInterface $user): bool
{
// LDAP-Elemente zur Authentifizierung
$ldaprdn = 'CN='.$credentials->username;
$ldappass = $credentials->password;
System::log('Test 8', __METHOD__, TL_ACCESS);
// Verbinden mit dem LDAP-Server
$ldapconn = ldap_connect("ldap://unternehmerverbaende.de")
or die("Keine Verbindung zum LDAP-Server möglich.");
if ($ldapconn) {
// Anmelden am LDAP-Server (als Member)
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
// Überprüfung der Authentifizierung
if ($ldapbind) {
return true;
} else {
return false;
}
}
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response
{
return null;
}
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
return null;
}
public function supportsRememberMe(): bool
{
return false;
}
public function start(Request $request, AuthenticationException $authException = null): ?Response
{
return null;
}
}
wird nicht geladen, kein Logeintrag bei Loginversuch, dieser sollte doch feuern bei jeden versuch ab Erfolg oder nicht?
root composer.json
Code:
...
"autoload": {
"psr-4": {
"App\\": "src/",
"AppBundle\\": "src/AppBundle/"
}
}
AppBundle ist für eine andere Erweiterung, welche unbekannte User schon bestens abfängt nach meinen Anpassungen.
Vielen Dank
Lesezeichen