I am try to create extension of principal for organizationalUnit using this code below
[DirectoryRdnPrefix("OU")]
[DirectoryObjectClass("organizationalUnit")]
public class OrganizationalUnitPrincipal : Principal
{
public OrganizationalUnitPrincipal(PrincipalContext Context_p)
{
PropertyInfo contextRaw = this.GetType().BaseType.GetProperty("ContextRaw",
BindingFlags.Instance | BindingFlags.NonPublic);
contextRaw.SetValue(this, Context_p, null);
}
}
But it throws the following error:
System.ArgumentException: Persisted Principal objects cannot be used as query filters.
This error occurs when I try retrieve organizationalUnit attributes and properties.
Can this work or not?
I want to achieve the same as show on this page http://msdn.microsoft.com/en-us/site/bb384372
On the theorical point of view, I think that what you want to do has no sense. It’s explained in the article you point, but it’s not so clear. The concept of
Principalis based on theDirectory Schemawich discribe objects you can add to ActiveDirectory.The Principal, AuthenticablePrincipal, UserPrincipal, ComputerPrincipal, and GroupPrincipal classes can all be extended to create custom objects that extend the object model.
But in LDAP in general and it’s the case in Active-Directory the class
organizationalUnitis not a subclass of theuserclass, but just a subclass of thetopclass.In other words : on the conceptual point of view you can note that a
Principalis kind of user (Yes in Microsoft point of view computers are users, they open sessions onto the domain like the users) andorganizationalUnitis a kind of organizational box (like a directory in a file system), so the second one do not extent the first one.Edited
Here is a subclass of DirectoryEntry that do what you want :