PrincipalContext ContextType – Extended


The ContextType acts as a store for PrincipalContext and they can be in any of the 3 forms

a) Domain

b) Machine

c) ApplicationDirectory

 

 

ContextType has 7 Methods to be used

-Compared To

-Equals

-GetHashCode

-GetType

-GetTypeCode

-HasFlag

-ToString

Each of the Method description can be find in Visual Studio.

Advertisements

PrincipalContext Container Property – Extended


The Container property returns the value specified in the Container parameter of PrincipalContext class.  This allows developers to perform search or actions against the specific container and this should be referenced using LDAP, I will be showing them in my future blog posts.

 

There are different Extended methods and Methods provided for Container Property, these are similar to the ConnectedServer property which I have listed in my earlier blog post. Most common Extended method usage are

a) GetHashcode = If developers tend to place the object in Hash Table

b) Length = Gets the length of the Container object

c) ToString() = To populate the Container string defined in the PrincipalContext class

 

ConnectedServer Property – Extended


ConnectedServer property gets the name of the server to which the PrincipalContext is connected. Developers can choose either Domain / ApplicationDirectory/Machine contextTypes to perform operations.  ConnectedServer property relies on the ContextType property and provides the following Extension Methods to perform actions.

 

ConnectedServer Property

Below list provides the Methods, Extended Methods and Properties that can be used with ConnectedServer Property.

image

image

 

The above list would help developers to determine the functions that can be performed.

PrincipalContext Validator


Developers use active directory as central source of authentication , validation and response. To perform actions on Security Principals, one have to open up the connection with the active directory domain where the application will be installed.

Programmers should use PrincipalContext to establish the connection to active directory and this is done through the constructors , properties and Methods exposed by MSDN. PrincipalContext constructor accepts 7 argument types which are listed below
http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.principalcontext.aspx

In my below tool, I am passing OU as the Container Object to perform the operations on Security Principals. Below tool can be used to validate the PrincipalContext and the Container being used, the purpose was to expose the CLASS functionality of PrincpalContext and the behavior of container property.

 

Notes:

a) Ensure you insert the DN of the Container object.
eg: In my example , I am using my OU as a container object and the syntax would be
Principalcontext ( contexttype.domain,”mydomain.com”,OU=Testing,DC=mydomain,DC=com”)

When the above code gets compiled, there is a socket which validates the DN on the Active directory provided in the Container section and returns error, if
the DN is wrong!, this gives more clarity for the developers to understand the DN before releasing the code.

b) From a tool point of view, I am accepting the input from users , but the code can be hardcoded as shown above.

 

 

 

Platform:

This tool was tested on Windows 2008 R2 and Windows Server 2012

Requirement:

.Net Framework 3.5 and above.

Input
-AD Domain

– OU DN ( eg: OU=Testing,DC=mydomain,DC=com)

Result

Tool will provide with the Domain Controller FQDN and OU DN after validation.

Download

Please rename the tool to exe post download.

PrincipalContext Domain Validator