[LDAP] Error when creating Users

[LDAP] Error when creating Users

  
Forge Component
(15)
Published on 2014-11-24 by Filipe Jacinto
15 votes
Published on 2014-11-24 by Filipe Jacinto
I'm having difficulty creating new users through this extension. I've tried doing so through both the included demo and my own espace, and while I have no difficulty listing objects with the Search action, User_Create and Group_Create both give me "Cannot access a disposed object. Object name: 'DirectoryEntry'." errors.

Looking at the source code, it seems readily apparent as to why. User_Create begins with:

public void MssUser_Create(string ssUsername, string ssPassword, string ssPath, string ssNewUsername, string ssNewPassword, string ssUserDescription, string ssGroup, string ssMail)
{
    DirectoryEntry AD = null;
    DirectoryEntry NewUser = null;
    DirectoryEntry group = null;

    try
    {

        // if not valid it will raise an exception
        AD = getValidDirectoryEntry(NormalizeLDAPPath(ssPath), ssUsername, ssPassword);
        NewUser = AD.Children.Add("CN=" + ssNewUsername, "user");
On the final line, the disposed object error triggers. I investigated getValidDirectoryEntry and found:
protected DirectoryEntry getValidDirectoryEntry(string ssPath,
    string ssUsername, string ssPassword)
{
    DirectoryEntry e = null;

    try
    {
        e = new DirectoryEntry(ssPath, ssUsername, ssPassword);

        try
        {
            if (e.Name == "") throw new Exception();
        }
        catch (Exception)
        {
            throw new Exception("Could not find usable entry in path");
        }
    }
    finally
    {
        if (e != null)
        {
            e.Close();
            e.Dispose();
        }
    }

    return e;
}
If I comment out "e.Dispose();", the whole extension works just fine. Can anyone explain what's going on here? Is this a bug? Is this dispose out of place?