2012-08-15 55 views
1

我的代碼如下因素片斷然而,檢查使用角色,它返回我一個爲什麼我沒有收到身份驗證令牌錯誤?

安全上下文不包含身份驗證令牌。一個可能的原因可能是沒有爲此URL配置防火牆。

public function loginAction(){ 
     $request = $this->getRequest(); 
     $session = $request->getSession(); 
     var_dump($this->get("security.context")->isGranted('ROLE_ADMIN')); 
     $response = new Response(); 
     $response -> setContent("login facebook"); 
     $response->send(); 
     return array('name'=>'login facebook'); 
    } 

爲什麼我得到這個錯誤,我該如何解決這個問題?

回答

3

異常消息非常明確:One possible reason may be that there is no firewall configured for this URL。要檢查用戶角色,您需要一個包含用戶的標記(匿名或不包含)。默認情況下,如果您未爲給定路徑配置身份驗證提供程序,則不會獲得任何安全上下文。

此處的解決方案是添加身份驗證提供程序。