2015-01-07 6 views
2

목표는 Symfony2에서 인증 성공 후 무엇인가를하는 것입니다.Symfony2 로그인 후 성공 핸들러가 작동하지 않음

이렇게하기 위해 나는 그 성공 처리자가되기 위해 양식 로그인을위한 서비스를 만드는 AuthenticationSuccessHandlerInterface을 확장했습니다.

namespace Foo\UserBundle\Component\Authentication\Handler; 

use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface; 
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
use Symfony\Component\Security\Core\SecurityContext; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\Routing\Router; 

class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface 
{ 

    protected $router; 
    protected $security; 

    public function __construct(Router $router, SecurityContext $security) 
    { 
     $this->router = $router; 
     $this->security = $security; 
    } 

    public function onAuthenticationSuccess(Request $request, TokenInterface $token) 
    { 
     $referer_url = $request->headers->get('referer');      
     $response = new RedirectResponse($referer_url); 

     return $response; 
    } 
} 

그리고 :

여기
firewalls: 
    main: 
     pattern: ^/ 
     form_login: 
      check_path: fos_user_security_check 
      provider: fos_userbundle 
      csrf_provider: form.csrf_provider 
      success_handler: foo_user.component.authentication.handler.login_success_handler 
     logout:  true 
     anonymous: true 

합니다 (UserBundle에서 만든)이 LoginSuccessHandler 서비스 : 여기

는 (성공 핸들러가 선언)을 security.yml 파일에있는 방화벽입니다 다음은 UserBundle의 services.xml입니다.

<?xml version="1.0" encoding="utf-8"?> 

<container xmlns="http://symfony.com/schema/dic/services" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://symfony.com/schema/dic/services 
http://symfony.com/schema/dic/services/services-1.0.xsd"> 
    <parameters> 
     <parameter key="foo_user.component.authentication.handler.login_success_handler.class"> 
      Foo\UserBundle\Component\Authentication\Handler\LoginSuccessHandler 
     </parameter> 
    </parameters> 
    <services> 
     <service id="foo_user.component.authentication.handler.login_success_handler" 
     class="%foo_user.component.authentication.handler.login_success_handler.class%"> 
      <tag name="monolog.logger" channel="security"/> 
      <argument type="service" id="router"/> 
      <argument type="service" id="security.context"/> 
      <argument type="service" id="service_container"/> 
     </service> 
    </services> 
</container> 

LoginSuccessHandler 생성자가 호출되고 오류 메시지가 표시되지 않습니다.

내가 가지고있는 문제는 로그인 성공 후 onAuthenticationSuccess이 호출되지 않는다는 것입니다. 내가 뭔가 빠진 것일까?

public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) 
    { 
     $user = $event->getAuthenticationToken()->getUser(); 
    } 

도이 방법을 구현하는 시도 : 내 작업 솔루션에서

+0

글쎄, 나는 서비스 태그'monolog.logger'를 제외하고 모든 것이 잘 보입니다. 그것이 원인 일 수 있습니까? –

+0

나는 그것을 제거하려고 노력했지만 문제는 동일하게 유지됩니다. – rfc1484

답변

2

나는 나의 청취자의 방법을 onSecurityInteractiveLogin을 구현합니다.

동일한 구성 (security.yml 및 서비스 정의)을 가지고 있지만 fosuserbunde를 사용하지 않았습니다.

희망이 도움말

관련 문제