Symfony 3.2 ldap身份验证问题

时间:2017-04-10 10:21:52

标签: symfony ldap

我正在尝试通过ldap(窗口活动目录)对用户进行身份验证,Symfony 3.2根据documents

配置了服务和安全性

但我收到错误:

  

php.DEBUG:警告:ldap_bind():无法绑定到服务器:凭据无效{"异常":" [object](Symfony \ Component \ Debug \ Exception \ SilencedErrorContext:{ \"严重性\":2,\"文件\":\" /无功/网络/ HTML /工作流/供应商/ symfony的/ symfony的/ SRC / Symfony的/ Component / Ldap / Adapter / ExtLdap / Connection.php \",\" line \":54})"} []

尝试添加域{username}等参数的许多更改 或者从ldap search softerra中完全复制cn字符串。

security.yml

security:
    providers:
        my_ldap:
            ldap:
                service: ldap
                base_dn: dc=example,dc=example
                search_dn: "cn=user.name,DC=example,DC=example" 
                search_password: PassWord
                default_roles: ROLE_ADMIN
                uid_key: sAMAccountName

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        # an`enter code here`onymous: ~`enter code here`
        http_basic_ldap:
            service: ldap
            dn_string: 'uid={username},dc=example,dc=example' 

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

service.yml

    services:
        ldap:
            class: Symfony\Component\Ldap\LdapClient
            arguments:
                - ip   # host
                - portenter code here         # port
                - 3           # version
                - false       # SSL
                - false       # TLS

native php

<?php
$name = 'username@domain.local';
$pass = 'password';
$adServer = 'ldap://xxx.xxx.xxx.xxx:1234/';

$basedn="OU=Users,OU=Office,OU=xxx,DC=xxx,DC=xxx"
$filter="(&(!(ou=NoSync))(department=*)(sn=*))";

$attributes=array("displayname", "mail", "company", "department", "physicaldeliveryofficename", "memberOf","givenname","sn","manager",
                    "mobile", "ipphone", "telephoneNumber", "facsimiletelephonenumber", "streetaddress", "l", "st","userprincipalname",
                    "postalcode", "c", "title", "samaccountname", "useraccountcontrol");

$cnx = ldap_connect($adServer) or die("Could not connect to LDAP server.");
ldap_bind($cnx, $name, $pass);

ldap_set_option($cnx, LDAP_OPT_SIZELIMIT,10000);
ldap_set_option($cnx, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol");;
ldap_set_option($cnx, LDAP_OPT_REFERRALS, 0) or die ("Could not set option referrals");
ldap_control_paged_result($cnx, 1000) or die ("Could not set option page limit");


$pageSize = 900;
    $total='';
    $cookie = '';
    $arr_rec=[];
    $arr_rec_update=[]; 
     do {
            $total = $pageSize + $total;
            ldap_control_paged_result($cnx, $pageSize, true, $cookie);

            $result  = ldap_search($cnx,$basedn,$filter,$attributes);
            $entries = ldap_get_entries($cnx, $result);
?>

1 个答案:

答案 0 :(得分:1)

1,不推荐使用ldap服务,对于Symfony 3.2,你应该使用ldap类声明它:

self.view.addGestureRecognizer(revealViewController().panGestureRecognizer())

app/config/services.yml

关于您提供的PHP脚本,您的配置应如下所示:

services: ldap: class: Symfony\Component\Ldap\Ldap factory: [ 'Symfony\Component\Ldap\Ldap', 'create'] arguments: - ext_ldap - host: ip - port: 1234 - version: 3 - ssl: false - tls: false

app/config/security.yml