php - Symfony2 ContextErrorException in Custom Authentication Provider -


i'm trying make how create custom authentication provider, after full reading , looking symfony code, thought creating factory, authentication provider , using symfony default class enough i'm missing , i'm getting error

contexterrorexception: catchable fatal error: argument 1 passed acme\demobundle\provider\myprovider::__construct() must implement interface symfony\component\security\core\user\userproviderinterface, string given, called in d:\wamp\www\sf2ldap\app\cache\dev\appdevdebugprojectcontainer.php on line 1383 , defined in d:\wamp\www\sf2ldap\src\acme\demobundle\provider\myprovider.php line 20

the factory

namespace acme\demobundle\factory;  use symfony\component\dependencyinjection\containerbuilder; use symfony\component\dependencyinjection\reference; use symfony\component\dependencyinjection\definitiondecorator; use symfony\component\config\definition\builder\nodedefinition; use symfony\bundle\securitybundle\dependencyinjection\security\factory\abstractfactory;  class myfactory extends abstractfactory {      public function getposition()     {         return 'form';     }      public function getkey()     {         return 'kstr';     }      protected function createauthprovider(containerbuilder $container, $id, $config, $userproviderid)     {          $providerid = 'security.authentication.provider.kstr.' . $id;         $container                 ->setdefinition($providerid, new definitiondecorator('kstr.security.authentication.provider'))                 ->replaceargument(0, new reference($userproviderid));         return $providerid;     }      protected function getlistenerid()     {         return 'security.authentication.listener.form';     }  } 

my provider

namespace acme\demobundle\provider;  use symfony\component\security\core\authentication\provider\authenticationproviderinterface; use symfony\component\security\core\user\userproviderinterface; use symfony\component\security\core\exception\authenticationexception; use symfony\component\security\core\authentication\token\tokeninterface;  class myprovider implements authenticationproviderinterface {      private $_userprovider;      public function __construct(userproviderinterface $userprovider)     {         $this->_userprovider = $userprovider;     }      public function authenticate(tokeninterface $token)     {         try         {             $user = $this->_userprovider->loaduserbyusername($token->getusername());             //custom auth steps             $token = new usernamepasswordtoken(                     $token->getusername(), null, $token->getproviderkey(), $user->getroles()             );             return $token;             }         } catch (\exception $exc)         {             throw new authenticationexception('invalid username or password. ', 0, $e);         }         throw new authenticationexception('invalid username or password asdfasd');     }      public function supports(tokeninterface $token)     {         return $token instanceof usernamepasswordtoken;     }  } 

services.yml

services:     kstr.security.authentication.provider:         class:  acme\demobundle\provider\myprovider         arguments: [""] 

security.yml

security:     encoders:         acme\demobundle\entity\secureuser: plaintext     providers:         multiples:             chain:                 providers: [entity_provider, ldap]         entity_provider:           entity: { class: acmedemobundle:secureuser, property: username }         ldap:           id: kstr.security.authentication.provider      firewalls:         dev:             pattern:  ^/(_(profiler|wdt)|css|images|js)/             security: false          login:             pattern:  ^/demo/secured/login$             security: false          secured_area:             pattern:    ^/demo/secured/             kstr:                  check_path: _security_check                 login_path: _demo_login                 provider: ldap             logout:                 path:   _demo_logout                 target: _demo 

need figure out, i'm missing here? need create custom listener if default "security.authentication.listener.form" fulfil needs?

you're passing string arguments: [""] first argument constructor of service.

that's why typehint in __construct(userproviderinterface $userprovider) fails.

inject userproviderinterface , exception disappear.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -