0

I need to create a contact in Active Directory. I have a class that extends UserPrincipal. How do I use it to create a new contact? The code below throws PrincipalOperationException " The requested operation did not satisfy one or more constraints associated with the class of the object." exception.

[DirectoryObjectClass("contact")]
[DirectoryRdnPrefix("CN")]
internal class MyContact : UserPrincipal
{

    public MyContact(PrincipalContext context)
        :base(context)
    {   
    }

}

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "domain", 
     "OU=Unit1,DC=domain,DC=com", "login", "pass"))
{

     using (MyContact principal = new MyContact(pc))
     {
         principal.Name = "Cnt1";
         principal.Save();
     }
 }

What am I doing wrong?

IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98

1 Answers1

0

contact object is not a security principal. It do not have SID or SAM account name. It doesn't seems right to use any Principal class to represent contact object.

baldpate
  • 1,707
  • 1
  • 14
  • 23
  • Custom UserPrincipal has DirectoryObjectClass where you can specify AD class. I was able to create class derived from UserPrincipal, search, read and update contacts and all AD attributes specific to Contact. Everything works perfectly. So I think it should be possible.The only thing I can not understand is how to create a new contact using UserPrincipal. I guess there is some property specific to Contact that is either missing or is extra and I need to remove it somehow from UserPrincipal. – IT Hit WebDAV Feb 11 '15 at 05:38
  • I think it only works for classes that represents a security principal. contact is not a security principal (no SID, SAM account name), it also don't have many of the attributes supported by user also (e.g. userAccountControl). If the underlying Principal class try to access related info, it may cause problem. Anyway, if you never touch any properties that related to security principal or user, may be it will work. But I highly suspect that. – baldpate Feb 11 '15 at 07:11