Symfony3.0.6(Symfony2.8 aussi)BadCredential

时间:2016-06-02 15:30:51

标签: php oracle orm doctrine-orm symfony

所以我走遍了各种各样的论坛来解决我的问题,但不幸的是我发现任何与我的担忧无关的东西。

我遵循Alexander BACCO(tuto gestion utilisateurs

的课程

身份验证“in_memory”工作正常没问题。

当我进入数据库时​​(没有FOSUserBundle,我现在不在第4阶段)我收到错误消息“BadCredential”

我不明白的是,doctrine生成的SQL查询效果很好,因为当我在SQL Developer中运行它时,它会返回我的用户名和密码。不幸的是app / log / dev.log我有一行Exception我把你放在下面所以你可以看到一切看起来都正确(当然它不是,但似乎),这个例外是奇怪的(我不可理解)

[2016-06-02 08:21:16] request.INFO: Matched route "login_check". {"route_parameters":{"_route":"login_check"},"request_uri":"http://localhost/Symfony/web/app_dev.php/login_check"} []
[2016-06-02 08:21:16] doctrine.DEBUG: SELECT a.* FROM (SELECT t0.id AS ID_1, t0.LOGIN AS LOGIN_2, t0.PASSWORD AS PASSWORD_3 FROM GTL_USERS t0 WHERE t0.LOGIN = ?) a WHERE ROWNUM <= 1 ["benoit"] []
[2016-06-02 08:21:17] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\BadCredentialsException(code: 0): Bad credentials. at C:\\wamp\\www\\Symfony\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\Security\\Core\\Authentication\\Provider\\UserAuthenticationProvider.php:73, Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException(code: 0): User \"benoit\" not found. at C:\\wamp\\www\\Symfony\\vendor\\symfony\\symfony\\src\\Symfony\\Bridge\\Doctrine\\Security\\User\\EntityUserProvider.php:61)"} []
[2016-06-02 08:21:17] security.DEBUG: Authentication failure, redirect triggered. {"failure_path":"login"} []

我不知道还能说些什么来给你带来帮助,但无论如何我都尽力了,我希望社区可以帮助我。

亲切

→-S

文件:User.php

<?php

namespace BO\UserBundle\Entity;

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


/**
 * @ORM\Table(name="GTL_USERS")
 * @ORM\Entity(repositoryClass="BO\UserBundle\Entity\UserRepository")
 */
class User implements UserInterface, \Serializable
{
    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(name="LOGIN", type="string", length=50, unique=true)
     */
    private $username;

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


    public function __construct()
    {

    }

    public function getUsername()
    {
        return $this->username;
    }

    public function getSalt()
    {
        // you *may* need a real salt depending on your encoder
        // see section on salt below
        return null;
    }

    public function getPassword()
    {
        return $this->password;
    }

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

    public function eraseCredentials()
    {
    }

    /** @see \Serializable::serialize() */
    public function serialize()
    {
        return serialize(array(
            $this->id,
            $this->username,
            $this->password,
            // see section on salt below
            // $this->salt,
        ));
    }

    /** @see \Serializable::unserialize() */
    public function unserialize($serialized)
    {
        list (
            $this->id,
            $this->username,
            $this->password,
            // see section on salt below
            // $this->salt
        ) = unserialize($serialized);
    }

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

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

        return $this;
    }

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

        return $this;
    }
}

文件:security.yml

security:
    encoders:        
        BO\UserBundle\Entity\User: plaintext

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

    providers:
        main:
            entity:
                class:    BO\UserBundle\Entity\User
                property: username

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main_login:        
            pattern:   ^/login$
            anonymous: true    

        main:
            pattern:   ^/
            anonymous: false
            pattern:      ^/
            anonymous:    true
            provider:     main 
            form_login:
                login_path: login
                check_path: login_check
            logout:
                path:       logout
                target:     /

    access_control:
        #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

并完成Oracle DB的配置:parameters.yml

parameters:
    database_driver: oci8
    database_host: srvoracle
    database_port: 1521
    database_name: v11akanea.DOM
    database_user: trt
    database_service: true
    database_password: ******

2 个答案:

答案 0 :(得分:0)

Je viensrajouteraprèsunejournéedetest que si je passe en pdo_mysql et une BDDidentiquementfabriquéecelafonctionneàmerveille

Avez-vousuneidée?

答案 1 :(得分:0)

错误看起来像FOSUserBundle未进行身份验证。 我怀疑你需要“注册”你的用户名来解决你指出的错误。

但是在你的“security.yml”文件中你没有添加“/ register”。

access_control:
  - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
  - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
  - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
  - { path: ^/admin/, role: ROLE_ADMIN }

一旦您解决了身份验证问题,请告诉我们。