Authenticated LDAP password not being stored in fos_user database

梦想的初衷 提交于 2019-12-25 03:15:08

问题


I have a Symfony project with FOSUserBundle and FR3DLdapBundle registered and configured, but when I authenticate against a test LDAP server, the authetication works, but when I look at the dev.log the Doctrine insert statement does not have a password (it's blank).

This is the bottom of my config.yml file:

fr3d_ldap:
    driver:
        host: ldap.forumsys.com
    user:
        baseDn: dc=example, dc=com
        attributes:
            - { ldap_attr: uid,  user_method: setUsername }
            - { ldap_attr: mail,  user_method: setEmail }
            - { ldap_attr: userPassword,  user_method: setPassword }
        filter: (&(ObjectClass=person))

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: AppBundle\Entity\User

I use this online LDAP server to validate: http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

Here is my User class:

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser implements LdapUserInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\Column(type="string")
     */
    protected $dn;

    public function __construct()
    {
        parent::__construct();
        if (empty($this->roles)) {
            $this->roles[] = 'ROLE_USER';
        }
    }

    /**
     * {@inheritDoc}
     */
    public function setDn($dn)
    {
        $this->dn = $dn;
    }

    /**
     * {@inheritDoc}
     */
    public function getDn()
    {
        return $this->dn;
    }
}

The main problem occurs when I login with for example "gauss" and a password of "password", the dev.log shows this:

[2016-03-11 20:51:40] ldap_driver.DEBUG: {action}({base_dn}, {filter}, {attributes}) {"action":"ldap_search","base_dn":"dc=example, dc=com","filter":"(&(&(ObjectClass=person))(uid=gauss))","attributes":[]} []
[2016-03-11 20:51:41] security.INFO: User {username} {result} on LDAP {"action":"loadUserByUsername","username":"gauss","result":"found"} []
[2016-03-11 20:51:41] ldap_driver.DEBUG: {action}({bind_rdn}, ****) {"action":"ldap_bind","bind_rdn":"uid=gauss,dc=example,dc=com"} []
[2016-03-11 20:51:41] security.INFO: User has been authenticated successfully. {"username":"gauss"} []
[2016-03-11 20:51:41] doctrine.DEBUG: "START TRANSACTION" [] []
[2016-03-11 20:51:41] doctrine.DEBUG: INSERT INTO fos_user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_token, password_requested_at, roles, credentials_expired, credentials_expire_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) {"1":"gauss","2":"gauss","3":"gauss@ldap.forumsys.com","4":"gauss@ldap.forumsys.com","5":true,"6":"6amuldowmz0oo0ww00wwwgo0k408sc","7":"","8":"2016-03-11 20:51:41","9":false,"10":false,"11":null,"12":null,"13":null,"14":["ROLE_USER"],"15":false,"16":null} []
[2016-03-11 20:51:41] doctrine.DEBUG: "COMMIT" [] []

Notice the password is blank. I want to be able to get the password (even if it's from the form) and store it in the database. I want to know how to do that.

Any help/suggestions are appreciated.


回答1:


If you're using LDAP for authentication then you don't need to persist the password.



来源:https://stackoverflow.com/questions/35959946/authenticated-ldap-password-not-being-stored-in-fos-user-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!