Note that there are some explanatory texts on larger screens.

plurals
  1. POAuthentication in functional tests in Symfony 2.1
    primarykey
    data
    text
    <p>I am currently in the process of migrating a 2.0.* project to the current 2.1 beta of Symfony.</p> <p>In my functional tests i currently have this code to create a client with authentication:</p> <pre><code>$client = // create a normal test client $role = 'ROLE_USER'; $firewallName = 'main'; $user = // pull a user from db $client-&gt;getCookieJar()-&gt;set(new \Symfony\Component\BrowserKit\Cookie(session_name(), true)); $token = new UsernamePasswordToken($user, null, $firewallName, array($role)); self::$kernel-&gt;getContainer()-&gt;get('session')-&gt;set('_security_' . $firewallName, serialize($token)); </code></pre> <p>this works as expected in 2.0.* but not in 2.1, the data does not get set in the session.</p> <p>Any ideas?</p> <p><strong>Edit (adding more info):</strong></p> <p>it seems that the problem lies in the file "<strong>Symfony\Component\Security\Http\Firewall\ContextListener</strong>" in the method "<strong>onKernelResponse</strong>". There is this code:</p> <pre><code>if ((null === $token = $this-&gt;context-&gt;getToken()) || ($token instanceof AnonymousToken)) { $session-&gt;remove('_security_'.$this-&gt;contextKey); } else { $session-&gt;set('_security_'.$this-&gt;contextKey, serialize($token)); } </code></pre> <p>in my case the if "$token instanceof AnonymousToken" is true, and because of that the session key gets removed. if i comment out that code everything works as expected.</p> <p>So i guess my new question is: What can i do to make the token not anonymous?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload