问题
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