0

我试图实现这个包:https ://github.com/BorisMorel/LdapBundle

除了侦听器之外,我已经设置并工作了所有东西 - 它只是不会运行并且探查器显示以下内容:

Not Called Listeners

Event name  Listener
imag_ldap.security.authentication.pre_bind   LdapSecurityListener::onPreBind
kernel.exception     ExceptionListener::onKernelException
kernel.exception     ProfilerListener::onKernelException
kernel.exception     ExceptionListener::onKernelException
kernel.view  TemplateListener::onKernelView

这是我的 service.yml:

services:
    ldap.listener:
        class: Riviera\PlutusBundle\EventListener\LdapSecurityListener
        tags:
            - {name: kernel.event_listener, event: imag_ldap.security.authentication.pre_bind, method:onPreBind}

这是我的听众:

<?php

namespace Riviera\PlutusBundle\EventListener;

//use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use IMAG\LdapBundle\Event\LdapUserEvent;

/**
 * Performs logic before the user is found to LDAP
 */
    class LdapSecurityListener
    {

    /**
     * Modifies the User before binding data from LDAP
     *
     * @param \IMAG\LdapBundle\Event\LdapUserEvent $event
     */
    public function onPreBind(LdapUserEvent $event)
    {
        $user = $event->getUser();
        $config = $this->appContext->getConfig();

        throw new \Exception(sprintf('Username: %s', $user->getUsername()));
    }
}

我已经尝试了几个小时,并且一直在调试捆绑代码,并且可以 100% 说它连接到 LDAP 并且在以下情况下失败:

//IMAG\LdapBundle\Provider\LdapAuthenticationProvider.php
try {
     $this->dispatcher->dispatch(LdapEvents::PRE_BIND, $userEvent);
} catch (\Exception $expt) {
     if ($this->hideUserNotFoundExceptions) {
        throw new BadCredentialsException('Bad credentials', 0, $expt);
     }

     throw $expt;
}

有什么想法/想法吗?

编辑

根据下面的评论,没有调用监听器,我认为 ldap 功能依赖于调用监听器。

如果我die()在此之前放置一个语句,try{}catch{}我可以在浏览器中看到它,但是如果我将它放在 die 语句之后永远不会触发,这意味着它会抛出错误的凭据异常。

4

2 回答 2

0

事实证明,正在调用侦听器并且正在引发异常,但是 ldap 模块中的某些功能通过将引发的异常隐藏为错误的凭据异常来隐藏它。

这是由于$this->hideUserNotFoundExceptions等于真而发生的,据我所知,它在构造中设置为默认为真(看不到其他任何被调用的地方)

无论如何,我删除了侦听器中的异常,现在我已经通过了登录屏幕。但它似乎仍然没有设置登录凭据(安全下没有令牌),但这是一个不同的问题。

于 2013-04-26T12:35:40.907 回答
0

问题在这里:

当 ListenerClass 尝试访问 Config objetc 时失败。尝试在您的听众中对此发表评论。

    //这会抛出异常
    //$config = $this->appContext->getConfig();
    //$ldapConf = $config['ldap'];

    //if (!in_array($user->getUsername(), $ldapConf['allowed'])) {
    // throw new \Exception(sprintf('LDAP user %s not allowed', $user->getUsername()));
    //}

于 2013-04-30T00:15:25.020 回答