2017-08-28 6 views
0

ユーザー(成功)がhttp_basic_ldapでログインした後にコードを実行するにはどうすればよいですか?symfony 3.3 http_basic_ldapログイン(成功)のイベントですか?

http://symfony.com/doc/3.3/security/ldap.html#configuration-example-for-http-basic
(つまりEasy LoginのLDAPを作るための開発者への賛辞!)

https://symfony.com/doc/3.3/components/security/authentication.html#authentication-events
私はAuthenticationEvents::AUTHENTICATION_SUCCESSSecurityEvents::INTERACTIVE_LOGINと試みたが、私のコードは間違っている、またはそれらのイベントがhttp_basic_ldapのために解雇されていないのいずれか。

私のテストsrc/AppBundle/EventSubscriber/LoginSubscriber.php

namespace AppBundle\EventSubscriber; 

use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
use Symfony\Component\Security\Core\AuthenticationEvents; 
use Symfony\Component\Security\Http\SecurityEvents; 

class LoginSubscriber implements EventSubscriberInterface 
{ 
    public function onUserLogin ($dunno) 
    { 
     file_put_contents("/tmp/dunno.log", "yay, got called!\n", FILE_APPEND); 
    } 

    public static function getSubscribedEvents() 
    { 
     return [ 
      AuthenticationEvents::AUTHENTICATION_SUCCESS => 'onUserLogin', 
      SecurityEvents::INTERACTIVE_LOGIN => 'onUserLogin', 
     ]; 
    } 
} 

PS。私の目標は、symfonyのデータベース/エンティティからユーザの役割をロードすることです(しかし、常にldapを使ってログインします)。

答えて

0

上記のコードはhttp_basic_ldapで機能します!

問題はdebian9が今/tmp/dunno.logへの書き込みはありませんので、apache2の通じ、PHPで/tmp/dunno.logへの書き込み、apache2のサービスのためのPrivateTmp=true持っているということでした(そして一度だけログイン後、でも、両方のイベントに思える)、それに/tmp/some-long-random-string/tmp/dunno.log ...

これが私たちの(仮想)のdevのマシンであるとして、私はそのようなことに気をいけないので、それを無効にする方法をHERESに:

sudo -i 
cat <<- 'EOF' > /etc/systemd/system/apache2.service.d/override.conf 
[Service] 
PrivateTmp=false 
EOF 
systemctl daemon-reload 
systemctl restart apache2 

PS。私は

...、または 「ディレクトリ名ではなく systemd-private-c23fc69cc5ae4f89bcf2e1317081f152-apache2.service-ZfVyIgapache2.service-systemd-private-c23fc69cc5ae4f89bcf2e1317081f152-ZfVyIgだった場合、私はおそらくそれが簡単に発見したかもしれないが」「私もPrivateTmpが存在していた機能を知らなかった」 のような言い訳を作ることができます
関連する問題