【问题标题】:Symfony 2.6 FR3DLdapBundle. Authentication request could not be processed due to a systemSymfony 2.6 FR3DLdapBundle。由于系统原因,无法处理身份验证请求
【发布时间】:2015-05-04 09:13:29
【问题描述】:

大家好,如果问题很愚蠢,我很抱歉。我对 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 条目之外的任何其他内容,我总是会收到该错误。你能帮我吗? 欣赏它。

【问题讨论】:

    标签: php symfony ldap fosuserbundle fr3dldapbundle


    【解决方案1】:

    尝试在您的 loginAction() 上执行此操作

    \Doctrine\Common\Util\Debug::dump($this->getDoctrine()->getEntityManager()->find('AppBundle:User', 1));
    

    您可能会看到错误。这对我有用。

    【讨论】:

      【解决方案2】:

      为我解决这个问题的是添加:

       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);
      }
      

      【讨论】:

        猜你喜欢
        • 2017-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-27
        • 1970-01-01
        • 2020-10-31
        • 2014-08-17
        相关资源
        最近更新 更多