개체를 검색 및 업데이트/생성하고 ADOB Person
개체를 업데이트 및 생성하기 위해 WCF 서비스를 만들고 있습니다. 확장 된 특성 (전달 된 스키마 특성은 있지만 기본 계정 관리 클래스 특성 집합은 포함하지 않음)을 관리하기 위해 확장 클래스를 만들었습니다. 이러한 확장 된 특성을 검색하거나 업데이트하는 데 문제가 없지만 AD에서 새 사람 개체를 만들려고 할 때 제약 조건 위반이 발생합니다.계정 관리 확장 클래스 속성을 사용하여 AD 사용자 개체를 만들 때 제약 조건 위반
System.DirectoryServices.DirectoryServicesCOMException : 제약 조건 위반이 발생했습니다.
현재 Windows 8.1 데스크톱의 Visio 2013에서 디버그 모드로 테스트 중입니다. 아래 코드. 누구나 제공 할 수있는 힌트 또는 통찰력이 가장 높이 평가됩니다.
아래 코드는 충분히 문서화되어 있고 의미가 있습니다. 미리 감사드립니다!
업데이트 : 더 명확해야합니다. 내가 확장 속성이라고 확신하는 이유는 오류없이 객체를 생성 할 속성을 설정하는 호출 코드 (아래의 코드 섹션에 주석 처리되어 있음)에서 해당 라인을 주석 처리 할 때입니다.
이 내 호출 코드 :
....other code.....
PrincipalContext pc = null;
try {
pc = new PrincipalContext(ContextType.Domain, MyProject.ADAccountService.Properties.Settings.Default.Domain, MyProject.ADAccountService.Properties.Settings.Default.PeopleDN, MyProject.ADAccountService.Properties.Settings.Default.AdminAcct, MyProject.ADAccountService.Properties.Settings.Default.AdminPW);
}
catch (Exception e) {
defaultLogger.Warn(MyProject.ADAccountService.App_GlobalResources.Messages.PrincipalContextCreateFail, e);
// Application.Exit();
}
....other code looking for whether ADObject already exists...
// Create the new UserPrincipal object
if (!newADPerson.personExists) {
using (ADeXt userNew = new ADeXt(pc)) {
string randomPassword = System.Web.Security.Membership.GeneratePassword(20, 4);
if (newADPerson.officePhone != null && newADPerson.officePhone.Length > 0) { userNew.VoiceTelephoneNumber = newADPerson.officePhone; }
if (newADPerson.department != null && newADPerson.department.Length > 0) { userNew.department = newADPerson.department; } //offending codeline
if (newADPerson.title != null && newADPerson.title.Length > 0) { userNew.title = newADPerson.title; } //offending codeline
if (newADPerson.faxNumber != null && newADPerson.faxNumber.Length > 0) { userNew.facsimileTelephoneNumber = newADPerson.faxNumber; } //offending codeline
if (newADPerson.officeLocation != null && newADPerson.officeLocation.Length > 0) { userNew.physicalDeliveryOfficeName = newADPerson.officeLocation; } //offending codeline
if (newADPerson.isEmployee) {
//if an employee and (newADPerson.script == null) use default value from global project settings
userNew.ScriptPath = newADPerson.script ?? MyProject.ADAccountService.Properties.Settings.Default.defaultScript;
}
if (newADPerson.lastName != null && newADPerson.lastName.Length > 0) { userNew.Surname = newADPerson.lastName; }
if (newADPerson.firstName != null && newADPerson.firstName.Length > 0) { userNew.GivenName = newADPerson.firstName; }
if (newADPerson.emplID != null) { userNew.EmployeeId = newADPerson.emplID; }
if (newADPerson.displayName != null && newADPerson.displayName.Length > 0) { userNew.DisplayName = newADPerson.displayName; }
userNew.SamAccountName = AccountID;
userNew.Name = AccountID;
userNew.UserPrincipalName = AccountID + MyProject.ADAccountService.Properties.Settings.Default.ExchangeAddress;
try {
userNew.Save();
userNew.SetPassword(randomPassword);
}
catch (Exception e) {
pc.Dispose();
}
}
}
확장 클래스 코드 :
namespace MyProject.ADAccountService.Classes {
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
class ADeXt : UserPrincipal {
public ADeXt(PrincipalContext context)
: base(context) {
}
public ADeXt(
PrincipalContext context,
string Container, //new constructor parameter added resolving issue
string samAccountName,
string password,
bool enabled
)
: base(
context,
samAccountName,
password,
enabled
) {
}
public static new ADeXt FindByIdentity(PrincipalContext context, string identityValue) {
return (ADeXt)FindByIdentityWithType(context, typeof(ADeXt), identityValue);
}
[DirectoryProperty("physicalDeliveryOfficeName")]
public string physicalDeliveryOfficeName {
get {
object[] result = this.ExtensionGet("physicalDeliveryOfficeName");
if (result != null) {
return (string)result[0];
}
else {
return null;
}
}
set {
this.ExtensionSet("physicalDeliveryOfficeName", value);
}
}
[DirectoryProperty("department")]
public string department {
get {
object[] result = this.ExtensionGet("department");
if (result != null) {
return (string)result[0];
}
else {
return null;
}
}
set {
this.ExtensionSet("department", value);
}
}
[DirectoryProperty("title")]
public string title {
get {
object[] result = this.ExtensionGet("title");
if (result != null) {
return (string)result[0];
}
else {
return null;
}
}
set {
this.ExtensionSet("title", value);
}
}
[DirectoryProperty("facsimileTelephoneNumber")]
public string facsimileTelephoneNumber {
get {
object[] result = this.ExtensionGet("facsimileTelephoneNumber");
if (result != null) {
return (string)result[0];
}
else {
return null;
}
}
set {
this.ExtensionSet("facsimileTelephoneNumber", value);
}
}
}
}
당신은 매개 변수로 바로'PrincipalContext' 물체로'AdExt' 생성자를 호출하는 경우 나, 제대로 설정합니다 다음 ** 기본 ** 생성자 코드를 이해한다면 ** SamAccountName 등의 필수 속성 **은 호출되지 않습니다. 그래서 당신은 ** Person 클래스의 ** 필수 속성 **이 무엇인지를 배워야하고, ** 당신이 항상 당신의 코드로부터 그것들을 설정했는지 확인해야합니다! –
마크, 그 힌트가 해결하는 데 도움이되었습니다. 확장 생성자의 컨테이너에 대한 새 매개 변수가 추가되어 트릭을 수행했습니다. – Jeff