security - Symfony 2 SecurityContext class deprecated -



security - Symfony 2 SecurityContext class deprecated -

i next error when seek reach app/example on symfony demo

error: symfony\component\security\core\securitycontext class deprecated since version 2.6 , removed in 3.0. utilize symfony\component\security\core\authentication\token\storage\tokenstorage or symfony\component\security\core\authorization\authorizationchecker instead.

the server returning right reply 200 status code though.

i've found nil on google it. has encounter error before and/or know how prepare ?

explanation

starting symfony 2.6 securitycontext got split tokenstorage , authorizationchecker (see: symfony blog - "new in symfony 2.6: security component improvements").

the main reason prevent circular reference occurred quite when injecting securitycontext own services.

solution

the alter 100% backwards compatible (as stated in linked blog post), need rewrite how accessed securitycontext.

// symfony 2.5 $user = $this->get('security.context')->gettoken()->getuser(); // symfony 2.6 $user = $this->get('security.token_storage')->gettoken()->getuser(); // symfony 2.5 if (false === $this->get('security.context')->isgranted('role_admin')) { ... } // symfony 2.6 if (false === $this->get('security.authorization_checker')->isgranted('role_admin')) { ... }

you can seek find culprit doing text-search security.context or securitycontext in source code (including vendor directory).

but stated you're using vanilla symfony 2.6 seems uses deprecated methods. might utilize this...

workaround

as symfony it's deprecation triggering e_user_deprecated errors, can disable them when booting symfony appkernel:

// app/appkernel.php class appkernel extends kernel { public function __construct($environment, $debug) { // maintain error reporting , disable deprecation warnings. error_reporting(error_reporting() & (-1 ^ e_deprecated)); // ... } }

i deprecation warnings, because symfony's changelogs tend give detailed info on how need alter code back upwards future versions of symfony , deprecation warnings triggered months before methods deprecated.

security symfony2

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -