Skip to Main Content

Security Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Can c# .net realy talk to a Sun Directory Server

807573Feb 28 2006 — edited Mar 24 2006
Hi there,

I have been trying desperately for weeks to get Microsoft .net System.DirectoryServices.Protocals and c# to talk to a Sun Java System Directory Server.

My understanding is that the System.DirectoryServices.Protocals namespace talks directly to LDAP, bypassing the ADSI security layer that Active Directory uses and I have seen posts that suggest that this connection is possible. However, although I can create the connection to the LDAP server successfully, the second that I try to send a request through the connection, it fails with an 'DirectoryOperationException' stating that "The authentication method is not supported."

The code I am using is for a command line app that will add some new objects to the LDAP server. The usage is:
App.exe <ldapServer> <user> <pwd> <targetOU>

I am using the following command to attempt to use it against a Sun LDAP server running on the same box:
App.exe localhost admin password ou=Blah,dc=some,dc=net

And all I get is:
DirectoryOperationException:The authentication method is not supported.

Here is the code; if anyone can give me an idea of what I am doing wrong I will be eternally grateful!
using System;
using System.Text;
using System.Net;
using System.Security.Permissions;
using SDS = System.DirectoryServices;

using System.DirectoryServices.Protocols;


[assembly: System.Reflection.AssemblyVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, Execution = true)]
[assembly: SDS.DirectoryServicesPermission(SecurityAction.RequestMinimum)]

namespace Microsoft.Samples.DirectoryServices
{

public class App
{
    // static variables used throughout the sample code
    static LdapConnection ldapConnection;
    static string  ldapServer;
    static NetworkCredential credential;
    static string targetOU; // dn of an OU. eg: "OU=sample,DC=fabrikam,DC=com"

    // object DNs that are created in the sample
    static string ou1, ou2, ou3;

    public static void Main(string[] args)
    {
        try
        {
            if(!GetParameters(args))
            {
                return;
            }

            CreateConnection();            
            Add();
            
            Console.WriteLine("\r\nApplication Finished Successfully!!!");
        }
        catch(Exception e)
        {
            Console.WriteLine("\r\nUnexpected exception occured:\r\n\t" + 
                              e.GetType().Name + ":" + e.Message);
        }        
    }



    static bool GetParameters(string[] args)
    {    
        if(args.Length != 4)
        {
            Console.WriteLine("Usage: App.exe <ldapServer> <user> <pwd> "+
                                                        "<targetOU>");

            // return error 
            return false;
        }

        // initialize variables
        ldapServer = args[0];
        credential = new NetworkCredential(args[1], args[2]);
        targetOU = args[3];

        // return success
        return true;
    }



    static void CreateConnection()
    {
        Console.WriteLine("-Create Connection-");
        ldapConnection = new LdapConnection(ldapServer);
        ldapConnection.Credential = credential;
        Console.WriteLine("LdapConnection is created successfully.");
    }



    static void Add()
    {
        Console.WriteLine("-Add-");

        // create new OUs under the specified OU
        ou1 = "OU=sampleOU1," +targetOU;
        ou2 = "OU=sampleOU2," +targetOU;
        ou3 = "OU=sampleOU3," +targetOU;
        string objectClass = "organizationalUnit";
                
        // create a request to add the new object
        AddRequest addRequest = new AddRequest(ou1, objectClass);

        //// The Problem occurs at this point <<---------------<<
        
        // send the request through the connection
        ldapConnection.SendRequest(addRequest);

        // create a request to add the new object
        addRequest = new AddRequest(ou2, objectClass);

        // send the request through the connection
        ldapConnection.SendRequest(addRequest);

        // create a request to add the new object
        addRequest = new AddRequest(ou3, objectClass);

        // send the request through the connection
        ldapConnection.SendRequest(addRequest);
        
        Console.WriteLine("Objects are created successfully.");
    }

    
}// end class App

}
Help!!!

James :-)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 21 2006
Added on Feb 28 2006
2 comments
572 views