GetUserByPath

Returns an Active Directory user object with all of its related Centrify-specific data given the path to the object.

Syntax

IUser GetUserByPath(string path)

Parameter

Specify the following parameter when using this method:

Parameter Description

path

The LDAP path or distinguished name of the user object you want to retrieve.

Return value

The user object as:

Centrify.DirectControl.API.IUser

Exceptions

GetUserByPath throws an ArgumentException if the computer path is null or empty.

Discussion

This method returns the user object using the LDAP path or distinguished name of the object. The LDAP path to a user object uses the following format:

LDAP://[domain/]attr=name,[...],dc=domain_part,[...]

The method returns the user object as Centrify.DirectControl.API.User.ObjectName. For example, if the Active Directory user account is Jae Smith and the LDAP path to the account is CN=Jae Smith, CN=Users, DC=ajax, DC=org, the method returns the user object as:

Centrify.DirectControl.API.User.Jae Smith

Example

The following code sample illustrates using this method in a script:

...
string strUser = args[0];
if (string.IsNullOrEmpty(strUser))
{
    Console.WriteLine("User DN cannot be empty.");
    return;
}
// Obtain an active directory container object
// Cnfigure the test container
DirectoryEntry objRootDSE = new DirectoryEntry("LDAP://rootDSE");
DirectoryEntry objContainer = new DirectoryEntry("LDAP://" + strParent + "," +     objRootDSE.Properties["defaultNamingContext"].Value.ToString());
string strContainerDN = objContainer.Properties["DistinguishedName"].Value as string;

// Create a CIMS object to interact with AD
ICims cims = new Cims();

// Note the lack of the cims.connect function.'
// By default, this application will use the connection to domain controller
// and existing credentials from the computer already logged in.

IHierarchicalZone objZone =
cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN) as IHierarchicalZone;
IUser objUser = cims.GetUserByPath(strUser);
if (objUser == null)
{
    Console.WriteLine("User " + strUser + " does not exist.");
    return;
}
...