Symfony2登录时出现错误"The user provider must return a UserInterface object"



我正试图修改现有的演示登录,它带有symfony,从in_memory到db存储的用户。我仍然得到:

[2013-03-27 19:24:34] security.INFO: Authentication request failed: The user provider must return a UserInterface object. [] []

所以我改成:

security.yml

  providers:
  user_db:
        entity: { class: CremeskAgentisBundleEntityPouzivatel, property: meno }

也创建了提到的实体:

'use DoctrineORMMapping as ORM;
 use SymfonyComponentSecurityCoreUserUserInterface;
 /**
 * Pouzivatel
 *
 * @ORMTable('pouzivatel')
 * @ORMEntity
 */
 class Pouzivatel implements UserInterface
 .etc

和左控制器保持原样:

 use SymfonyBundleFrameworkBundleControllerController;
 use SymfonyComponentSecurityCoreSecurityContext;
 use SensioBundleFrameworkExtraBundleConfigurationRoute;
 use SensioBundleFrameworkExtraBundleConfigurationTemplate;
 use JMSSecurityExtraBundleAnnotationSecure;

 /**
  * @Route("/demo/secured")
  */
 class SecuredController extends Controller
 {
     /**
      * @Route("/login", name="_demo_login")
      * @Template()
      */
     public function loginAction()
     {
         if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
    } else {
        $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
    }
    return array(
        'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
        'error'         => $error,
    );
}
/**
 * @Route("/login_check", name="_security_check")
 */
public function securityCheckAction()
{
    // The security layer will intercept this request
}
/**
 * @Route("/logout", name="_demo_logout")
 */
public function logoutAction()
{
    // The security layer will intercept this request
}
/**
 * @Route("/hello", defaults={"name"="World"}),
 * @Route("/hello/{name}", name="_demo_secured_hello")
 * @Template()
 */
public function helloAction($name)
{
    return array('name' => $name);
}
/**
 * @Route("/hello/admin/{name}", name="_demo_secured_hello_admin")
 * @Secure(roles="ROLE_ADMIN")
 * @Template()
 */
public function helloadminAction($name)
{
    return array('name' => $name);
}
 }

我无法使登录工作。我将感激任何帮助。谢谢你。

检查用户实体的命名空间和安全配置是否匹配。

namespace CremeskAgentisBundleEntity;
use ....
class Pouzivatel implements UserInterface
{
    ....

和in your security.yml

providers:
    user_db:
        entity: { class: CremeskAgentisBundleEntityPouzivatel, property: meno }

相关内容