【问题标题】:Fr3d LDAP bundle with Symfony2 and Fos user bundle. Invalid credentials带有 Symfony2 和 Fos 用户包的 Fr3d LDAP 包。无效证件
【发布时间】:2015-06-01 11:40:41
【问题描述】:

我正在尝试使用 Fr3d LDAP 捆绑包和 Symfony2 来验证用户。我也使用 fosuser 捆绑包。第一次认证成功,用户被插入数据库,但密码为空。第二次身份验证(注销后)失败:“无效凭据”。有人能帮帮我吗?

  security:
  erase_credentials:    false

encoders:
    Ens\LunchBundle\Entity\User: plaintext

providers:
    chain_provider:
        chain:
            providers: [fos_userbundle, fr3d_ldapbundle]

    fr3d_ldapbundle:
        id: fr3d_ldap.security.user.provider

    fos_userbundle:
        id: fos_user.user_manager

firewalls:
    main:
        pattern: ^/
        fr3d_ldap:  ~
        form_login:
            always_use_default_target_path: true
            default_target_path: /
            provider: chain_provider
        logout:       true
        anonymous:    true
    default:
        anonymous: ~

配置:

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

fr3d_ldap:
    driver:
        host:                my host
        port:                389    # Optional
#        version:             3
        username:            +++ # Optional
        password:            +++    # Optional
        bindRequiresDn:      false   # Optional
        bindRequiresDn: true
        accountFilterFormat: (&(samaccountname=%s))
#        baseDn: OU=Users,OU=R4S,OU=SVRD-44-B,OU=SPB,OU=RU,OU=Offices,DC=tps,DC=local
#       accountFilterFormat: (&(uid=%s)) # Optional. sprintf format %s will be the username
#       optReferrals:        false  # Optional
#        useSsl:              false   # Enable SSL negotiation. Optional
#       useStartTls:         true   # Enable TLS negotiation. Optional
#        accountCanonicalForm: 3 # ACCTNAME_FORM_BACKSLASH this is only needed if your users have to login with something like HOST\User
#       accountDomainName: HOST
#       accountDomainNameShort: HOST # if you use the Backslash form set both to Hostname than the Username will be converted to HOST\User
    user:
        baseDn: ++++
        filter: (&(ObjectClass=Person))
        attributes:          # Specify ldap attributes mapping [ldap attribute, user object method]

           - { ldap_attr: samaccountname,  user_method: setusername } # Default
           - { ldap_attr: name,  user_method: setUsernameCanonical } # Default
           - { ldap_attr: mail,  user_method: setName } # Default
           - { ldap_attr: mail,  user_method: setEmail }     # Optional

用户.php

namespace Ens\LunchBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use FR3D\LdapBundle\Model\LdapUserInterface;

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

    protected $name;

    /** @var  string */
    protected $surname;

    private $dn;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

//    public function setUsername($username){
//        var_dump($username);die;
//    }

    /**
     * @return string
     */
    public function getSurname()
    {
        return $this->surname;
    }

    /**
     * @param string $surname
     */
    public function setSurname($surname)
    {
        $this->surname = $surname;
    }


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

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

    /**
     * Set Ldap Distinguished Name.
     *
     * @param string $dn Distinguished Name
     */
    public function setDn($dn)
    {
        $this->dn = $dn;
    }

    /**
     * Get Ldap Distinguished Name.
     *
     * @return string Distinguished Name
     */
    public function getDn()
    {
        return $this->dn;
    }
}

【问题讨论】:

  • 你知道了吗?我在看旧帖...

标签: php symfony


【解决方案1】:

我正在回复这个旧请求,以便其他人可以在需要时找到信息。

$dn 注释中的 ORM 列信息是关键。没有它,您将看到此行为: - 用户可以登录一次。 - 当用户登录时,他们的用户记录被创建。请注意,dn 字段为空。 - 用户可以注销。 - 用户此时无法成功登录。

在 User 类中更改 $dn 的声明以包含注释:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-30
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 2014-03-21
    • 2015-11-06
    • 1970-01-01
    相关资源
    最近更新 更多