LDAP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesLDAP Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 19th, 2010, 03:25 PM
SapAuthor SapAuthor is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 2 SapAuthor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 28 sec
Reputation Power: 0
Exclamation LDAP connects in example code given, but not in my application

I'm working on integrating Microsoft Active directory authentication into a drupal module for a project. I loaded the adLDAP folder with examples on the server, and it is able to authenticate perfectly fine. No problems what so ever.
Here's the original code from the example:
PHP Code:
 $username=strtoupper($_POST["username"]); //remove case sensitivity on the username
$password=$_POST["password"];
$formage=$_POST["formage"];

if (
$_POST["oldform"]){ //prevent null bind

    
if ($username!=NULL && $password!=NULL){
        
//include the class and create a connection
        
include ("../adLDAP.php");
        try {
            
$adldap = new adLDAP();
        }
        catch (
adLDAPException $e) {
            echo 
$e; exit();   
        }
        
        
//authenticate the user
        
if ($adldap -> authenticate($username,$password)){
            
//establish your session and redirect
            
session_start();
            
$_SESSION["username"]=$username;
            
$redir="Location: https://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/menu.htm";
            
header($redir);
            exit;
        }
    }
    
$failed=1;



And this is what's in my drupal code:
PHP Code:
 $response = array();  
  
$response['status'] = 'failed';
  
  if (isset(
$_SESSION['openid']['claimed_id']) && isset($_SESSION['openid']['claimed_password'])) {
    
$claimed_id $_SESSION['openid']['claimed_id'];
    
$claimed_password $_SESSION['openid']['claimed_id'];
    unset(
$_SESSION['openid']['service']);
    unset(
$_SESSION['openid']['claimed_id']);
    unset(
$_SESSION['openid']['claimed_password']);

    
$response['openid.claimed_id'] = $claimed_id// For finding the user in the system.

    // Authentification Here
    
    //you should look into using PECL filter or some form of filtering here for POST variables
    
$username=strtoupper($claimed_id); //remove case sensitivity on the username
    
$password=$claimed_password;

    if (
$username!=NULL && $password!=NULL){
        try {
            
$adldap = new adLDAP();
        }
        catch (
adLDAPException $e) {
           die(
$e);   
        }
        
        
//authenticate the user
        
if ($adldap -> authenticate($username,$password)){
            
$response['status'] = 'success';
        }
    }
    
    die(
"openid_complete() 3, response status is ".$response['status']);
  }
  return 
$response


I used die statements to see how the code is flowing. From the die statements, i know the following

The username and password are getting to the authenticate function properly.
The statements leading up to and following the ldap_connect and ldap_bind are working.


Here is adLDAP's authentification function, it's here where the main problem occurs:
PHP Code:
public function authenticate($username,$password,$prevent_rebind=false){
        
// Prevent null binding
        
if ($username===NULL || $password===NULL){ return (false); } 
        
        
// Bind as the user        
                
die("_conn = ".$this->_conn.", username = ".$username.$this->_account_suffix.", and password = ".$password); 

        
$this->_bind = @ldap_bind($this->_conn,$username.$this->_account_suffix,$password);
        if (!
$this->_bind){ return (false); } // !!! This is running, the ldap_bind is failing!!!
        
        // Cnce we've checked their details, kick back into admin mode if we have it
        
if ($this->_ad_username!=NULL && !$prevent_rebind){
            
$this->_bind = @ldap_bind($this->_conn,$this->_ad_username.$this->_account_suffix,$this->_ad_password);
            if (!
$this->_bind){
                
// This should never happen in theory
                
throw new adLDAPException('Rebind to Active Directory failed. AD said: ' $this->get_last_error());
            } 
        }
        
        return (
true);
    } 


Any help would be awesome, the only difference i can see between the adLDAP's example code that worked and the drupal one which isn't working is the resource ID #, for the drupal one it shows #95, for the example one the resource ID # from the connect is #3

Thanks a ton...i got to finish this up by the end of hte month or i'm screwed :P

Reply With Quote
  #2  
Old January 19th, 2010, 05:39 PM
ldapswandog ldapswandog is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2009
Location: Charlotte, NC
Posts: 111 ldapswandog User rank is Corporal (100 - 500 Reputation Level)ldapswandog User rank is Corporal (100 - 500 Reputation Level)ldapswandog User rank is Corporal (100 - 500 Reputation Level)ldapswandog User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 18 m
Reputation Power: 8
In the example code they retrieve the user's DN and then BIND using it and the password. In your code your building the DN using variable '_account_suffix' and I do not see where it is being set. If you do not have a flat tree then building the DN is not a good solution. BTW I'm not a PHP code expert, just reading through your example and providing what assistance I can.

Reply With Quote
  #3  
Old January 19th, 2010, 07:26 PM
SapAuthor SapAuthor is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 2 SapAuthor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 28 sec
Reputation Power: 0
Quote:
Originally Posted by ldapswandog
In the example code they retrieve the user's DN and then BIND using it and the password. In your code your building the DN using variable '_account_suffix' and I do not see where it is being set. If you do not have a flat tree then building the DN is not a good solution. BTW I'm not a PHP code expert, just reading through your example and providing what assistance I can.


Thanks for the help. That wasn't the issue, but i did find out what was after a long while. Turns out for the domain controller i had dc01.thesite.com, when all i needed was thesite.com...which is odd cuz i was positive i copied the working adldap.php file and pasted it in there.

Anyways, i'll close this, sorry i forgot to before. The module is nearing completion, sadly when i started this module, there was no ldap integration, and now there are already 2 out there :P so much for providing something in need xD

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesLDAP Programming > LDAP connects in example code given, but not in my application

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap