symfony2 Security.yml AbstractToken.php中的ContextErrorException

时间:2014-12-17 19:42:55

标签: symfony doctrine-orm symfony-forms

当我尝试使用防火墙创建登录表单时出现此错误,当我添加防火墙的代码时,会抛出此错误:

ContextErrorException in AbstractToken.php line 70:
Catchable Fatal Error: Object of class __PHP_Incomplete_Class could not be converted to string

My Security.yml

security:
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        AssaAbloy\AppBundle\Entity\Administrador: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_ADMIN

    providers:
        usuarios:
            entity: { class: AssaAbloy\AppBundle\Entity\Administrador, property: username }

    firewalls:      
        admin:          
            pattern: ^/*
            anonymous: ~
            form_login:
                login_path: /login/
                check_path: /login_check/
                default_target_path: /
            logout:
                path: /logout/
                target: /login/

    access_control:

我的Administrador类

<?php

namespace AssaAbloy\AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Administrador
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="AssaAbloy\AppBundle\Entity\AdministradorRepository")
 */
class Administrador implements UserInterface
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="nombre", type="string", length=30)
     */
    private $nombre;

    /**
     * @var string
     *
     * @ORM\Column(name="apellido", type="string", length=30)
     */
    private $apellido;

    /**
     * @var string
     *
     * @ORM\Column(name="username", type="string", length=255)
     */
    private $username;

    /**
     * @var string
     *
     * @ORM\Column(name="password", type="string", length=255)
     */
    private $password;

    /**
     * @var string
     *
     * @ORM\Column(name="salt", type="string", length=255)
     */
    private $salt;

    /**
     * @var string
     *
     * @ORM\Column(name="correo", type="string", length=255)
     */
    private $correo;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nombre
     *
     * @param string $nombre
     * @return Administrador
     */
    public function setNombre($nombre)
    {
        $this->nombre = $nombre;

        return $this;
    }

    /**
     * Get nombre
     *
     * @return string 
     */
    public function getNombre()
    {
        return $this->nombre;
    }

    /**
     * Set apellido
     *
     * @param string $apellido
     * @return Administrador
     */
    public function setApellido($apellido)
    {
        $this->apellido = $apellido;

        return $this;
    }

    /**
     * Get apellido
     *
     * @return string 
     */
    public function getApellido()
    {
        return $this->apellido;
    }

    /**
     * Set username
     *
     * @param string $username
     * @return Administrador
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Get username
     *
     * @return string 
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Set password
     *
     * @param string $password
     * @return Administrador
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Get password
     *
     * @return string 
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set salt
     *
     * @param string $salt
     * @return Administrador
     */
    public function setSalt($salt)
    {
        $this->salt = $salt;

        return $this;
    }

    /**
     * Get salt
     *
     * @return string 
     */
    public function getSalt()
    {
        return $this->salt;
    }

    /**
     * Set correo
     *
     * @param string $correo
     * @return Administrador
     */
    public function setCorreo($correo)
    {
        $this->correo = $correo;

        return $this;
    }

    /**
     * Get correo
     *
     * @return string 
     */
    public function getCorreo()
    {
        return $this->correo;
    }

    public function eraseCredentials() {

    }

    public function getRoles() {
       return array('ROLE_ADMIN');
    }

    public function __toString() {
        return $this->nombre;
    }

}

Symfony2版本为2.6。 有什么想法吗?

p.s。:完整的日志

in AbstractToken.php line 70
at ErrorHandler->handleError('4096', 'Object of class __PHP_Incomplete_Class could not be converted to string', 'C:\wamp\www\Informatica\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\AbstractToken.php', '70', array()) in AbstractToken.php line 70
at AbstractToken->getUsername() in SecurityDataCollector.php line 59
at SecurityDataCollector->collect(object(Request), object(Response), null) in Profiler.php line 209
at Profiler->collect(object(Request), object(Response), null) in ProfilerListener.php line 109
at ProfilerListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher))
at call_user_func(array(object(ProfilerListener), 'onKernelResponse'), object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) in WrappedListener.php line 59
at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher))
at call_user_func(object(WrappedListener), object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) in classes.php line 1776
at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent)) in classes.php line 1709
at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in classes.php line 1870
at ContainerAwareEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in TraceableEventDispatcher.php line 112
at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in bootstrap.php.cache line 3028
at HttpKernel->filterResponse(object(Response), object(Request), '1') in bootstrap.php.cache line 3023
at HttpKernel->handleRaw(object(Request), '1') in bootstrap.php.cache line 2970
at HttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 3119
at ContainerAwareHttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 2364
at Kernel->handle(object(Request)) in app_dev.php line 28

1 个答案:

答案 0 :(得分:1)

清除浏览器cookie并再次尝试,或运行以下命令清除缓存:

php app / console cache:clear --env = prod