Developer Zone
Register  |  Login  
 Mainsoft.com
Search  
 

Directory Services

The System.DirectoryServices namespace provides easy access to Active Directory, using the Active Directory Services Interfaces (ADSI) technology. ADSI is the set of interfaces that Microsoft provides as a tool for working with a variety of network providers: IIS, LDAP, NDS and WinNT. Grasshopper supports the LDAP protocol only, that is the protocol of choice for cross-platform directory services access.

Architecture

Grasshopper implementation of the System.DirectoryServices namespace consists of two layers:

  • Back-end layer: based on Novell LDAP Libraries for C#, ported to Java EE with Grasshopper. The Novell LDAP Libraries for C# is an open-source C# library designed to provide an easy access to any LDAP server compliant directory from managed code.
  • Front-end layer: Mono implementation of the System.DirectoryServices API, and ported to Java EE with Grasshopper. Mainsoft team is working within the Mono community to develop tests and improve the quality of System.DirectoryServices namespace implementation.

This two-layer architecture enables you to use the System.DirectoryServices API as you do in a regular .NET application. Any .NET System.DirectoryServices API calls a corresponding API of the LDAP Libraries for C#. For example, interacting with an LDAP server through a DirectoryEntry or a DirectorySearcher object, is done using an underlying LdapConnection object.

To query a server for information about the directory server, including its capabilities and configuration, RFC 2251 (LDAPv3) defines a special entry that appears on every LDAP server: RootDSE. We support retrieval of server-specific information by accessing it with a DirectoryEntry object which is initialized to the RootDSE, through an LDAP URL of the form ldap://host:port/RootDSE.

Default DirectoryEntry

.NET supplies the ability to create a "default" DirectoryEntry, i.e., instantiating a DirectoryEntry object without supplying any parameters, not even a path of an entry on the server. In this case, the entry is initialized to the root entry of the default LDAP server, by using native Windows services to resolve the default server on the particular network from domain controller configuration. With Grasshopper, we offer an alternative approach, of using the App.config file to provide an application with the information about the default LDAP server.

The following example of an App.config file demonstrates the use of this feature:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="System.DirectoryServices">
      <section name="Settings" 
             type="System.Configuration.NameValueSectionHandler"/>
    </sectionGroup>
  </configSections>
  <System.DirectoryServices>
    <Settings>
      <add key="servername" value="ldapsrv"/>
      <add key="port" value="389"/>
    </Settings>
  </System.DirectoryServices>
</configuration>

This example sets the default LDAP server to be ldapsrv running on port 389. If no default server is specified, or no configuration file is found, the implementation fallbacks to the default of localhost:389.

Once the default server is resolved, we investigate the default server RootDSE entry in order to determine the naming context of the root entry, and then initialize the DirectoryEntry so it points to the default server root entry.

Testing a sample application

Download a sample application , based on a simple LDAP browser application available from Novell Cool Solutions . To build this application you should first create a Web Virtual directory.

  1. Go to Start > Settings > Control Panel > Administrative Tools > Internet Information Services.

  2. Expand your local computer, and under the Web Sites folder, right-click Default Web Site and choose New > Virtual Directory... to start the Virtual Directory Creation wizard.

  3. Via this wizard, add a virtual directory to point to the ActiveDirectorySample folder. Use ActiveDirectorySample as the alias name.

Now you can open the sample project in Visual Studio .NET, WebApplication1.csproj located in the ActiveDirectorySample folder. In the Web.config file, set the values of LDAPServerConnectionString, LDAPServerUsername, and LDAPServerPassword according to your Directory Server. Before you port this application to Java EE and Linux, build it and make sure that it’s working properly.

Make sure you have updated the Grasshopper runtime with the System.DirectoryServices modules.

To convert this sample to a Grasshopper application, right click on WebApplication1 project and select Generate Java EE Project…. Follow the wizard instructions to convert your application to Java EE. Building this application will result in a JAR file that will be deployed on your selected Java EE application server. Run it to test your application.

Known issues and limitations

  • LDAP schema

    A schema of a directory specifies the types of objects it may have and the mandatory and optional attributes for each object type. System.DirectoryServices provides an access to the schema information through the properties of DirectoryEntry class. This functionality is not implemented yet.
  • Authentication

    AuthenticationTypes.ServerBind is the only authentication mode currently tested.
  • Encryption

    Not yet functional (neither SSL nor Kerberos).
  • Filtering

    DirectorySearcher class enables filtering of query results based on filter expressions. Our current implementation does not support all the possible forms of filter expression, due to limitations of the underlying provider (LDAP libraries for C#).

Home  Site map  Privacy statement  Legal notice  Contact us
Mainsoft Product Validations: Optimized for Microsoft Visual Studio, Java Powered for the Enterprise, and Ready for IBM WebSphere.
Read more about: .NET Java and .NET for Linux

Copyright © Mainsoft Corporation 2005-2009. All rights reserved