错误。请检查您的LDAP配置并确保系统正常运行。

3

大家好,如果问题很蠢我很抱歉。我对Symfony(2.6)非常陌生,我的第一个项目需要用户从AD进行身份验证。

无论我做什么都会收到以下信息:由于系统问题,无法处理身份验证请求。

security.yml

encoders:
    FOS\UserBundle\Model\UserInterface: sha512


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

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

    fr3d_ldapbundle:
        id: fr3d_ldap.security.user.provider

    fos_userbundle:
        id: fos_user.user_provider.username

firewalls:
main:

    pattern:    ^/
    fr3d_ldap:  ~
    form_login:
#         check_path: fos_user_security_check
#         login_path: fos_user_security_login
        always_use_default_target_path: true
        default_target_path: /main
        provider: chain_provider
    logout:
        path:   fos_user_security_logout
        target: /login
    anonymous: ~

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

config.yml

fr3d_ldap:
 driver:
  host:                192.168.137.200
  port:                50000
  username:            DOMAIN\Admnistrator    # Optional
  password:            pass_here    # Optional

user:
 baseDn: OU=HP,OU=MANA,DC=DOMAIN,DC=com
 filter: (&(ObjectClass=Person))
 attributes:          # Specify ldap attributes mapping [ldap attribute, user object method]
       - { ldap_attr: uid,  user_method: setUsername }
       - { ldap_attr: mail, user_method: setEmail }

实体/用户类

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

/**
* @ORM\Column(type="string", nullable=true)
*/
protected $name;

/**
* Ldap Object Distinguished Name
* @ORM\Column(type="string", length=128)
* @var string $dn
*/
private $dn;

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

public function setName($name) {
$this->name = $name;
}

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

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

如果我不实现LdapUserInterface接口,数据库认证通过了,但是如果我使用除mysql记录之外的任何东西,我就会收到那个错误。你能帮我解决这个问题吗?谢谢。
2个回答

1
这对我有用的解决方法是添加:


 implements UserInterface, \Serializable

在我的实体类声明末尾添加“到达终点”的注释,然后在实体底部添加所需的方法:
/**
 * @return null
 */
public function getSalt(){
    return null;
}

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

public function eraseCredentials(){

}

/**
 * @return string
 */
public function serialize(){
    return serialize(array($this->id, $this->username, $this->password));
}

/**
 * @param string $serialized
 */
public function unserialize($serialized) {
    list($this->id, $this->username,$this->password) = unserialize($serialized);
}

1
尝试在您的loginAction()中执行此操作。
\Doctrine\Common\Util\Debug::dump($this->getDoctrine()->getEntityManager()->find('AppBundle:User', 1));

你可能会看到一个错误。这对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接