2013-12-21 56 views
0

如何通過costum用戶提供程序獲取密碼eneterd。我發現這個問題:Symfony2需要發送密碼到API

Symfony Security/Custom User Provider : How to get the login password within the custom User Provider?

它說我將不得不過度溫升的loadUserByName方法,並將其作爲參數添加密碼,問題是,我無法找到他覆蓋文件:

security_listeners.xml 

此文件位於何處?

我發現:在DOAAuthenticationProvider

$user = $this->userProvider->loadUserByUsername($username); 

呼叫,我看到,該方法需要:

protected function retrieveUser($username, UsernamePasswordToken $token) 

爲增強部,我asume我需要通過密碼那裏,然後將它傳遞給loadUserByName,它調用我的costum userProvider方法。

任何有關如何實現這一點的幫助表示讚賞。

回答

0

你可以在你的包上創建一個AuthenticationHandler。並在成功登錄時從令牌中獲取密碼。

security.authentication.success_handler: 
     class: Wix\UserBundle\EventListener\AuthenticationHandler 
     arguments: ["@security.http_utils", {}] 
     tags: 
      - { name: 'monolog.logger', channel: 'security' } 

而且樣品類:

class AuthenticationHandler extends DefaultAuthenticationSuccessHandler 
{ 

/** 
* This is called when an interactive authentication attempt succeeds. This 
* is called by authentication listeners inheriting from 
* AbstractAuthenticationListener. 
* 
* @param Request $request 
* @param TokenInterface $token 
* 
* @return Response never null 
*/ 
public function onAuthenticationSuccess(Request $request, TokenInterface $token) 
{ 

    $response = new RedirectResponse('/'); 
    $response->setStatusCode(200); 

    return $response; 
} 

}

在services.yml