title: Symfony2 > Use Security Context in Public Route (possible alternative)
body: <p>I have a function <code>UserController:saveUserAction()</code>. This function is being used throughout my system WHENEVER a User Entity needs to be created or modified. This can happen from three places:</p>
  
  <p>1) Admin Panel &rarr; User Administration (System Admin can create/modify users).<br>
  2) Members Dashboard &rarr; My Details (User can edit his own details).<br>
  3) Registration (Non-users can sign up and a user is created for them).</p>
  
  <p>Now there are certain fields that may ONLY be set by an administrator, for instance, the USER_ROLE. (I do not want someone who is registering 'hacking' the system and signing themselves up as an administrator). Normally <code>if ($this-&gt;get('security.context')-&gt;isGranted('ROLE_ADMIN'))</code> works fine to determine if the user is an administrator, but seeing as the route to <code>saveUser()</code> is public (in order to facilicate public registrations), I am getting the error:</p>
  
  <p><code>The security context contains no authentication token. One possible reason may be that there is no firewall configured for this URL.</code></p>
  
  <p>Is there a way to user the security context on a public route or is there some kind of alternative other than checking manually what roles the logged in user (if any logged in user) has, because this is quite lumbersome as can be seen at <a href="https://stackoverflow.com/questions/20569927/symfony2-easier-way-to-determine-access">Symfony2 &gt; Easier way to determine access</a></p>