IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

authentification par ldap


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Inscrit en
    Décembre 2010
    Messages
    24
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 24
    Points : 28
    Points
    28
    Par défaut authentification par ldap
    je rencontre quelques problèmes , svp pouvez vous m'aider à corriger mon code ou ajouter un script pour qu'il fonctionne merciid'avance

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
     
    <?php
       $server = "192.168.85.128";
       $port = "389";
     
        $login = 'toto'; 
       $pass = 'toto'; 
     
        // pour connecter au serveur ldap
    $con = @ldap_connect($server) or die('Impossible de se connecter au serveur LDAP.');
     
     
       // authentification 
      if (@ldap_bind($con)) {
     
     
     
        $sr = @ldap_search ($con,'ou=blibli,dc=blabla,dc=fr', 'uid='.$login);
        $info = @ldap_get_entries($con, $sr);
     
     
        if ($info['count'] == 0)  {
     
          echo 'compte inexistant !!';    
        }
        else {
     
          if (@ldap_bind($con,$info[0]['dn'],$pass)) {
            echo 'authentifi‚ !!';
          }
          else {
            echo 'saisie incorrecte !!';
          }
        }
      }
      else {
        echo 'connexion LDAP impossible !';
      }
    ldap_close($con);
    }
     
    ?>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Commence par enlever tous les @ et donne nous les erreurs que tu obtiens.

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 84
    Points : 101
    Points
    101
    Par défaut
    Hello,

    Si il s'agit de tester ta connexion LDAP je te conseille le code suivant écrit par l'excellent "shmanic" :
    (si ça ne fonctionne pas c'est que tes paramètres sont faux).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    <?php
     
    /** 
     * @name     LDAP Debug
     * @author   Shaun Maunder 
     * @version  V1.05
     * @link     http://shmanic.com/tool/jmapmyldap/?id=4&doc=ver-1-auth-debug-method
     * 
     * @copyright	Copyright (C) 2011 Shaun Maunder. All rights reserved.
     * @license		GNU General Public License version 2 or later
     * 
     * You should NOT leave this file executable on a public web server!
     * 
     * V1.05 ChangeLog
     * Changed: Tidy up code
     * Bug: Escape post variables in JS
     * 
     * V1.04 ChangeLog
     * Added: Group Mapping Helpers
     * Bug: Added the footer HTML to the output
     * 
     * V1.03 ChangeLog
     * Added: Better error strings and output handling
     * Changed: Start and end script output will always show
     * Changed: Using table for LDAP attributes
     * Bug: PHP error output now shows
     * Bug: No search was producing incorrect results due to early bind
     * 
     */
     
    define('debugver','V1.05');
     
    // Override PHP error output
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors','On');
     
    // *****************************************************
    // ****** Function Declartions and Implementation ******
    // *****************************************************
     
    function getRequest($string) {
    	return isset($_REQUEST[$string]) ? $_REQUEST[$string] : false;
    }
     
     
    function ldapRead($ds, $base_dn, $dn=null, $filter=null, $attributes=array()) 
    {
    	//will search the directory from the dn NOT including subtrees
    	//should be used when we know the dn - less of an overhead than search
    	if(is_null($dn)) $dn = $base_dn;
    	if(is_null($filter)) $filter = '(objectclass=*)'; //we have to use a filter
     
    	$result = ldap_read($ds, $dn, $filter, $attributes);
     
    	if($result) return getEntries($ds, $result);
    }
     
    function getEntries($ds, $result) 
    {
    	//get the entries from the result
    	//we are not going to use ldap_get_entries as its got a limit of 1000
    	$entries = array();
     
    	for($entry=ldap_first_entry($ds, $result); $entry!=false; $entry=@ldap_next_entry($ds, $entry)) {
    		$entries[] = array(); //new entry, new array
     
    		$attributes = ldap_get_attributes($ds, $entry);
     
    		foreach($attributes as $name=>$value) {
    			if(is_array($value) && $value['count']>0) {
    				unset($value['count']); //we do not want the count really
    				$entries[count($entries)-1][$name] = $value;
    			}
    		}
     
    		$entries[count($entries)-1]['dn'] = ldap_get_dn($ds, $entry);
    	}
     
    	return $entries;
     
    }
     
    // *****************************************************
    // ************** HTML Header Output *******************
    // *****************************************************
     
    ob_start();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>PHP LDAP Debug</title>
    <style type="text/css">
    	* {margin:0; padding:0;}
    	html {font: 82.5%/1 Helvetica, Arial, Tahoma, sans-serif;}
    	html, body {height:100%;}
    	table.single {margin:0 auto; margin-top:10px; margin-bottom:10px; border:#000 1px solid;}
    	table.single td {padding:4px 2px 4px 2px; border:#666 1px solid;}
    	input.standard {font-size:0.8em; width:99%; background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, rgb(255,255,255)), color-stop(1, rgb(240,240,240))); background-image: -moz-linear-gradient(center bottom,rgb(255,255,255) 0%,rgb(240,240,240) 100%);}
    	input.checkbox {font-size:0.8em; margin:4px 0;}
    	button {padding:2px;}
    	#introduction {margin:0 auto;margin-top:40px;text-align:center;font-size:1.3em;width:70%;border:#333 1px solid;border-radius:20px;}
    	#introduction p {margin-top:13px;}
    	button {width:100px;height:24px;}
    	.roundBorder {border:#333 1px solid;border-radius:10px;}
    	#navigation {margin:0 auto;width:40%;margin-top:24px;height:24px;}
    	tr.header {background-color:#ccc;height:24px;}
    	tr.header th {border-top:#333 1px solid;}
    	hr {margin:4px 0;color:#AAA;}
    	#tabs {height:26px;}
    	#tabs ul {list-style: none;}
    	#tabs ul li {float:left; }
    	#tabs ul li a {display:block; padding:4px 10px; color:#025A8D; text-decoration:none;}
    	#tabs ul li a:hover {background-color:#111; color:#fff;}
    </style>
    <script type="text/javascript">
     
    function getResults(type)
    {
    	var xmlhttp;
    	var postVars;
     
    	document.getElementById("results").innerHTML="Fetching result...";
     
    	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp=new XMLHttpRequest(); 
    	}
    	else { // code for IE6, IE5
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    	}
     
    	xmlhttp.onreadystatechange=function()
    		{
    		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		  {
    		  document.getElementById("results").innerHTML=xmlhttp.responseText;
    		  }
    		}
     
     
    	postVars = getPostVars('authForm');
     
    	if(type==2) {
    		postVars += '&' + getPostVars('mappingForm');
    	}
     
    	xmlhttp.open("POST", "?result=" + type, true); //sent back to the same page
    	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	xmlhttp.setRequestHeader("Content-length", postVars.length);
    	xmlhttp.setRequestHeader("Connection", "close");
    	xmlhttp.send(postVars);
    }
     
     
    function getPostVars(form)
    {
    	var out = '';
    	var elements = document.getElementById(form).elements;
     
    	for(var i=0; i<elements.length; i++) { 
    		if(elements[i].type == 'checkbox') {
    			out += elements[i].id + '=' + elements[i].checked + '&';
    		} else if(elements[i].type == 'text') {
    			out += elements[i].id + '=' + escape(elements[i].value) + '&';
    		} else if(elements[i].type == 'password') {
    			out += elements[i].id + '=' + escape(elements[i].value) + '&';
    		}
    	} 
     
    	out = out.substr(0, out.length-1);
     
    	return out;
    }
     
     
    function showAuth() 
    {
    	document.getElementById("mappingContainer").style.display = 'none';
    	document.getElementById("authContainer").style.display = 'block';
     
    	document.getElementById("mappingTab").style.fontWeight = '';
    	document.getElementById("authTab").style.fontWeight = 'bold';
    }
     
     
    function showMapping() 
    {
    	document.getElementById("authContainer").style.display = 'none';
    	document.getElementById("mappingContainer").style.display = 'block';
     
    	document.getElementById("authTab").style.fontWeight = '';
    	document.getElementById("mappingTab").style.fontWeight = 'bold';
    }
     
    </script>
    </head>
    <body>
    <div style="min-height:100%; height:auto !important; height:100%; margin:0 auto;">
    <div style="background-color:#000000; background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, rgb(0,0,0)), color-stop(1, rgb(110,110,110))); background-image: -moz-linear-gradient(center bottom,rgb(0,0,0) 0%,rgb(110,110,110) 100%); color:#FFFFFF;">
    <h4 style="padding:4px;">Shmanic.com</h4>
    <h3 style="padding:0px 4px 4px 8px;">PHP LDAP Debug <?php echo debugver; ?></h3>
    </div>
     
    <?php
    $htmlHeader = ob_get_contents();
    ob_end_clean();	
     
    // *****************************************************
    // *************** HTML Form Output ********************
    // *****************************************************
     
    ob_start();
    ?>
    <div style="margin:10px;">
    <div id="tabs">
    <ul>
     <li><a href="#" onclick="showAuth()" id="authTab" style="font-weight:bold;">Authentication</a></li>
     <li><a href="#" onclick="showMapping()" id="mappingTab">Group Mapping</a></li>
    </ul>
    </div>
    <div id="authContainer" style="width:40%;float:left;height:100%;">
     
    <form id="authForm">
    <hr />
    	<input type="checkbox" id="chkV3" class="checkbox" /> LDAP V3<br />
    	<input type="checkbox" id="chkTLS" class="checkbox" /> Start TLS<br />
    	<input type="checkbox" id="chkRef" class="checkbox" /> Follow Referrals<br /><br />
    <hr />
    	Host: <input type="text" id="txtHost" class="standard" /><br />
    	Port: <input type="text" id="txtPort" class="standard" value="389" /><br /><br />
    <hr />
    	Connect User: <input type="text" id="connUser" class="standard" /><br />
    	Connect Password: <input type="password" id="connPass" class="standard" /><br /><br />
    <hr />
    	<input type="checkbox" id="chkSearch" class="checkbox" /> Use Search<br />
    	Base DN: <input type="text" id="baseDn" class="standard" /><br />
    	User DN/Filter: <input type="text" id="userQry" class="standard" /><br /><br />
    <hr />
    	Map User ID: <input type="text" id="mapUid" class="standard" value="uid" /><br />
    	Map Full Name: <input type="text" id="mapName" class="standard" value="fullName" /><br />
    	Map Email: <input type="text" id="mapEmail" class="standard" value="mail" /><br /><br />
    <hr />
    	Test User: <input type="text" id="testUser" class="standard" /><br />
    	Test Password: <input type="password" id="testPass" class="standard" /><br />
    <hr />
    <button type="button" onclick="getResults(1)">Show Result</button>
    </form> 
    </div>
     
    <div id="mappingContainer" style="width:40%;float:left;height:100%;display:none;">
     
    <form id="mappingForm">
    <hr />
    	<p>Ensure the authentication results are successful before continuing! </p><br />
    	<p>This tab is only a guide (i.e. it won't give specific parameters for group mapping). You only need either the forward or reverse lookup configured, not both.</p><br />
    <hr />
    	<p>Use the following box to print all attributes for a group. This is optional and is only required for the correct <strong>reverse lookup attribute</strong>. </p><br />
    	Group DN: <input type="text" id="groupDN" class="standard" value="" /><br /><br />
    <hr />
    	<p><strong>Forward Lookup: </strong> if the group membership attribute prints out on the authentication results then populate the following text box with the attribute name (this is memberOf for Active Directory and usually groupMembership for others). </p><br />
    	Lookup Attribute: <input type="text" id="lookupFAttribute" class="standard" value="groupMembership" /><br /><br />
     
    <hr />
    	<p><strong>Reverse Lookup: </strong> if no group membership attribute is printed from the authentication results then a reverse lookup is required. Populate the following boxes to test reverse lookup configuration. You can use the 'Group DN' text box to print out all attributes for a specific group. </p><br />
    	Lookup Attribute: <input type="text" id="lookupRAttribute" class="standard" value="member" /><br />
    	Lookup Member: <input type="text" id="lookupMember" class="standard" value="dn" /><br /><br />
    <hr />
    <button type="button" onclick="getResults(2)">Show Result</button>
    </form> 
    </div>
     
    <div id="results" style="float:right;width:56%;">
     
    </div>
    <div class="clear:both"></div>
    </div>
    <?php
    $htmlForm = ob_get_contents();
    ob_end_clean();
     
    // *****************************************************
    // ************** HTML Footer Output *******************
    // *****************************************************
     
    ob_start();
    ?>
     
    </body>
    </html>
    <?php
    $htmlFooter = ob_get_contents();
    ob_end_clean();
     
    // *****************************************************
    // ************** HTML Result Output *******************
    // *****************************************************
     
    $htmlContent = '';
     
    if($reqResult = getRequest('result')) {
     
    	/* This part will process the authentication RESULTS -
    	* authentication inputs and provide an output
    	* in HTML. This will NOT render the form.
    	*/
     
    	ob_start();
     
    	/*** Parameters to edit ***/
    	$ldapV3    = getRequest('chkV3') == 'true' ? 1 : 0; // copy from ldap v3
    	$startTLS  = getRequest('chkTLS') == 'true' ? 1 : 0; // copy from start tls
    	$referrals = getRequest('chkRef') == 'true' ? 1 : 0; // copy from follow referrals
     
    	$host = getRequest('txtHost'); // copy from host
    	$port = getRequest('txtPort'); //copy from port
     
    	$connectrdn  = getRequest('connUser'); // copy from connect user
    	$connectpass = getRequest('connPass'); // copy from connect password (this is in plain text don't forget)
     
    	$usesearch = getRequest('chkSearch') == 'true' ? 1 : 0; // copy from use search
    	$basedn    = getRequest('baseDn'); // copy from base dn
    	$userdn    = getRequest('userQry'); // copy from User DN/Filter
     
    	$mapuserid   = getRequest('mapUid'); // copy from map user id
    	$mapfullname = getRequest('mapName'); // copy from map full name
    	$mapemail    = getRequest('mapEmail'); // copy from map email
     
    	$authUsername = getRequest('testUser'); // enter an example LDAP based user to test login
    	$authPassword = getRequest('testPass'); //enter the user's password to test login
    	/*** End of parameters ***/
     
    	try {
     
    		if(!extension_loaded('ldap')) {
    			throw new Exception('PHP LDAP extension not loaded. Look at <a href="http://shmanic.com/tool/jmapmyldap/?id=4&doc=php-ldap-extension">this</a> for more information.');
    		}
     
    		if(!$host || !$port) {
    			throw new Exception('This script requires a valid host and port.');
    		}
     
    		if(!$authUsername) {
    			throw new Exception('This script requires a test user for testing authentication. You must set the test user and test password for any LDAP user.');
    		}
     
    		$filterAll = '(objectclass=*)';
     
    		$ldapconn = ldap_connect($host, $port); // copy from host and port
     
    		if ($ldapconn) {
     
    			// LDAP Version 3
    			if($ldapV3) if(!ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
    				throw new Exception('Failed to set LDAP V3. Uncheck LDAP V3 and try again.');
    			}
     
    			// Follow Referrals
    			if(!ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, intval($referrals))) {
    				throw new Exception('Failed to set referrals. Uncheck Follow Referrals and try again.');
    			}
     
    			// Start TLS
    			if($startTLS) if(!ldap_start_tls($ldapconn)) {
    				throw new Exception('Failed to start TLS. Uncheck Start TLS and try again.');
    			}
     
     
    			if($usesearch) {
     
    				// search requires a base dn
    				if(!$basedn) {
    					throw new Exception('Failed: \'Base DN\' is empty. Populate it and try again.');
    				}
     
    				echo "Attempting to bind to LDAP server using connect username and password... <br />";
     
    				// binding to ldap server
    				$ldapbind = ldap_bind($ldapconn, $connectrdn, $connectpass);
     
    				// verify binding
    				if ($ldapbind) {
    					echo "LDAP bind successful.<br /><br />";
     
    					echo "Attempting to use search to find user... <br />";
     
    					$search 	= str_replace('[username]', $authUsername, $userdn);
     
    					/*
    					 * A very basic check for a LDAP filter - this doesn't check to
    					* ensure a filter is valid, just used to make sure that a dn
    					* hasn't been entered.
    					*/
    					if(!preg_match('/\((.)*=(.)*\)/',$search)) {
    						throw new Exception("Failed: search has been used but '$search' is NOT a filter. Check <a href=\"http://shmanic.com/tool/jmapmyldap/?id=4&doc=lib-jldap2-error-validation-filter\">this</a> for more information.");
    					}
     
    					$result = ldap_search($ldapconn, $basedn, $search);
     
    					$result = ldap_first_entry($ldapconn, $result);
     
    					if($result) {
     
    						$dn = ldap_get_dn($ldapconn, $result);
    						echo "Successfully found user";
     
    					} else {
    						$msg = '';
    						if(!$connectrdn || !$connectpass) {
    							$msg = 'Did you forget to set the \'Connect User\' and \'Connect Password\'? Currently it is connecting as anonymous.';
    						}
    						throw new Exception('Failed: cannot find the authenticating user. ' . $msg);
    					}
     
     
    				} else {
    					throw new Exception('LDAP bind failed. Check host, port, connect username and connect password.');
    				}
    			} else {
    				echo "Building full User DN based on 'User DN/Filter' and 'Test User'...<br />";
     
    				$dn = str_replace('[username]', $authUsername, $userdn);
     
    				if(!$dn) {
    					throw new Exception('Failed: the dn is empty, check the \'User DN/Filter\' to ensure it is a valid DN.');
    				}
     
    				/*
    				 * A very basic check for a LDAP filter - this doesn't check to
    				* ensure a filter is valid, just used to make sure that a dn
    				* hasn't been entered.
    				*/
    				if(preg_match('/\((.)*=(.)*\)/',$dn)) {
    					throw new Exception("Failed: the dn '$dn' is a filter but search is not used. Check <a href=\"http://shmanic.com/tool/jmapmyldap/?id=4&doc=lib-jldap2-error-validation-dn\">this</a> for more information.");
    				}
     
    				echo 'Appears to have been successful';
    			}
     
     
    			echo "<br /><br />Attempting to logon with user " . $dn . " ...";
     
    			$ldapbind = ldap_bind($ldapconn, $dn, $authPassword);
     
    			if(!$ldapbind) {
    				throw new Exception('Failed to logon with test user. Check the \'User DN/Filter\' and \'Test User\' parameters.');
    			}
     
    			echo "<br />Successfully logged on with user";
     
    			echo "<br /><br />Attempting to retrieve all user attributes then process the results request...<br /><br />";
     
    			$result = ldapRead($ldapconn, $basedn, $dn);
     
    			if($result && isset($result[0]) && $data = $result[0]) {
     
    				if(isset($data[$mapuserid][0]) && $val = $data[$mapuserid][0]) {
    					echo "User ID: " . $val . '<br />';
    				} else {
    					echo '<p><strong>Invalid Map User ID.</strong></p>';
    				}
     
     
    				if($reqResult==1) {
     
    					/* Authenication result request - print out everything for
    					 * the authentication results.
    					 */
     
    					if(isset($data[$mapfullname][0]) && $val = $data[$mapfullname][0]) {
    						echo "Full Name: " . $val . '<br />';
    					} else {
    						echo '<p><strong>Invalid Map Full Name.</strong></p>';
    					}
     
    					if(isset($data[$mapemail][0]) && $val = $data[$mapemail][0]) {
    						echo "Email: " . $val . '<br /><br />';
    					} else {
    						echo '<p><strong>Invalid Map Email. If your LDAP server does not use emails, then use a \'fake\' email in the plug-in.</strong></p>';
    					}
     
    					echo '<div style="margin:10px 0; padding:2px; background-color:#EAEAEA;display:block;border:#AAA 1px solid;"><table>';
     
    					echo '<tr style="background-color:#CCC;"><th>LDAP Attribute</th><th>Value(s)</th></tr>';
    					foreach($data as $key=>$val) {
    						echo '<tr><td style="border-top:#CCC 1px solid;"><strong>' . $key . '</strong></td><td style="border-top:#CCC 1px solid;">';
    						print_r( $val );
    						echo '</td></tr>';
    					}
    					echo '</table></div>';
     
     
    				} elseif($reqResult==2) {
     
    					/* Group mapping request result - print out everything for
    					 * the groups results.
    					 */
     
    					/*** Parameters to edit ***/
    					$lookupFAttribute = getRequest('lookupFAttribute');
     
    					$lookupRAttribute = getRequest('lookupRAttribute');
    					$lookupMember  = getRequest('lookupMember');
     
    					$groupDN = getRequest('groupDN');
    					/*** End of parameters ***/
     
    					// Group DN Helper
    					if($groupDN) {
    						echo '<br /><u>Group DN</u>';
    						echo '<br />Attempting to get attributes for the Group DN...<br /> ';
     
    						$result = ldapRead($ldapconn, $basedn, $groupDN);
     
    						if($result && isset($result[0]) && $groupDNResult = $result[0]) {
    							echo 'Found the Group DN. Printing out attributes: <br />';
    							echo '<div style="margin:10px 0; padding:2px; background-color:#EAEAEA;display:block;border:#AAA 1px solid;"><table>';
     
    							echo '<tr style="background-color:#CCC;"><th>LDAP Attribute</th><th>Value(s)</th></tr>';
    							foreach($groupDNResult as $key=>$val) {
    								echo '<tr><td style="border-top:#CCC 1px solid;"><strong>' . $key . '</strong></td><td style="border-top:#CCC 1px solid;">';
    								print_r( $val );
    								echo '</td></tr>';
    							}
    							echo '</table></div>';
     
    						} else {
    							echo '<strong>Failed: couldn\'t find the group dn.</strong>';
    						}
     
    					}
     
    					// ** Forward Lookup **
    					if($lookupFAttribute) {
    						echo '<br /><u>Forward Lookup</u>';
    						echo '<br />Attempting a forward lookup...<br /> ';
     
    						if(isset($data[$lookupFAttribute])) {
    							if(count($data[$lookupFAttribute])) {
    								echo 'Found the forward lookup attribute and the following groups will be mapped:<br /> ';
     
    								echo '<div style="margin:10px 0; padding:2px; background-color:#EAEAEA;display:block;border:#AAA 1px solid;"><table>';
     
    								foreach($data[$lookupFAttribute] as $group) {
    									echo '<tr><td style="border-top:#CCC 1px solid;">' . $group . '</td></tr>';
    								}
     
    								echo '</table></div>';
     
     
    							} else {
    								echo 'Found the forward lookup attribute however, it currently has no groups.';
    							}
    						} else {
    							echo '<strong>failed: cannot use forward lookup using the attribute ' . $lookupFAttribute . '</strong>';
    						}
    					}
     
     
    					// ** Reverse Lookup **
    					if($lookupRAttribute) {
    						echo '<br /><u>Reverse Lookup</u>';
    						echo '<br />Attempting a reverse lookup...<br /> ';
     
    						if(isset($data[$lookupMember])) {
     
    							$lookupMemberValue = $lookupMember!='dn' ? $data[$lookupMember][0] : $data[$lookupMember];
     
    							$search = "($lookupRAttribute=$lookupMemberValue)";
    							echo 'Searching LDAP for ' . $search . '<br />';
    							$result = ldap_search($ldapconn, $basedn, $search);
     
    							if($result) {
     
    								if($entries = getEntries($ldapconn, $result)) {
     
    									echo 'Found the reverse lookup attribute and the following groups will be mapped:<br /> ';
     
    									echo '<div style="margin:10px 0; padding:2px; background-color:#EAEAEA;display:block;border:#AAA 1px solid;"><table>';
     
    									foreach($entries as $group) {
    										echo '<tr><td style="border-top:#CCC 1px solid;">' . $group['dn'] . '</td></tr>';
    									}
     
    									echo '</table></div>';
     
     
    								} else {
    									echo '<strong>Failed: couldn\'t get a result for reverse lookup.</strong>';
    								}
     
    							} else {
    								echo '<strong>Failed: couldn\'t get a result for reverse lookup.</strong>';
    							}
     
     
    						} else {
    							echo '<strong>Failed: the lookup member attribute doesn\'t exist. Use only attributes that are listed from the authentication results.</strong>';
    						}
     
    					}
     
     
    				} else {
     
    					throw new Exception('UNKNOWN RESULT REQUEST');
     
    				}
     
     
     
    			} else {
    				$msg = '';
    				if(!$authPassword) {
    					$msg = 'Did you forget to set the test user password?';
    				}
    				throw new Exception('Failed to retrieve user attributes. ' . $msg);
    			}
     
    		} else {
    			throw new Exception('LDAP connect failed. Check host and port.');
    		}
     
     
    	} catch (Exception $e) {
    		echo '<p style="background-color:#FBB;display:block;padding:4px 0;font-weight:bold;">' . $e->getMessage() . '</p>';
    	}
     
    	$resultHTML = ob_get_contents();
    	ob_clean();
     
    	echo ' :: PHP LDAP Debug ' . debugver . ' Script Started :: <br /><br />';
    	echo $resultHTML;
    	echo '<br /><br /> :: PHP LDAP Debug ' . debugver . ' Script Finished :: <br /><br />';
     
     
     
    } else {
     
    	/* Render the HTML form and output the Javascript */
    	echo $htmlHeader;
    	echo $htmlForm;
    	echo $htmlFooter;
     
    }

Discussions similaires

  1. [2.x] Authentification par LDAP
    Par icl1c dans le forum Symfony
    Réponses: 4
    Dernier message: 21/01/2014, 15h52
  2. [Spring Security] Authentification par groupe LDAP
    Par titeuf92 dans le forum Spring Web
    Réponses: 2
    Dernier message: 25/06/2008, 11h28
  3. Réponses: 0
    Dernier message: 26/03/2008, 09h36
  4. Authentification par LDAP ?
    Par arona dans le forum Sybase
    Réponses: 0
    Dernier message: 11/09/2007, 12h57
  5. authentification par LDAP
    Par coco-sup dans le forum Oracle
    Réponses: 1
    Dernier message: 29/05/2006, 07h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo