internal void DeleteUserInternal(string loginName, string organizationId) { HostedSolutionLog.LogStart("DeleteUserInternal"); HostedSolutionLog.DebugInfo("loginName : {0}", loginName); HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId); if (string.IsNullOrEmpty(loginName)) { throw new ArgumentNullException("loginName"); } if (string.IsNullOrEmpty(organizationId)) { throw new ArgumentNullException("organizationId"); } string path = GetUserPath(organizationId, loginName); if (ActiveDirectoryUtils.AdObjectExists(path)) { ActiveDirectoryUtils.DeleteADObject(path); } HostedSolutionLog.LogEnd("DeleteUserInternal"); }
internal bool OrganizationExistsInternal(string organizationId) { if (string.IsNullOrEmpty(organizationId)) { throw new ArgumentNullException("organizationId"); } string orgPath = GetOrganizationPath(organizationId); return(ActiveDirectoryUtils.AdObjectExists(orgPath)); }
private OrganizationUser GetManager(DirectoryEntry entry) { OrganizationUser retUser = null; string path = ActiveDirectoryUtils.GetADObjectStringProperty(entry, ADAttributes.Manager); if (!string.IsNullOrEmpty(path)) { path = ActiveDirectoryUtils.AddADPrefix(path, PrimaryDomainController); if (ActiveDirectoryUtils.AdObjectExists(path)) { DirectoryEntry user = ActiveDirectoryUtils.GetADObject(path); retUser = new OrganizationUser(); retUser.DisplayName = ActiveDirectoryUtils.GetADObjectStringProperty(user, ADAttributes.DisplayName); retUser.AccountName = ActiveDirectoryUtils.GetADObjectStringProperty(user, ADAttributes.Name); } } return(retUser); }
internal void SetUserGeneralSettingsInternal(string organizationId, string accountName, string displayName, string password, bool hideFromAddressBook, bool disabled, bool locked, string firstName, string initials, string lastName, string address, string city, string state, string zip, string country, string jobTitle, string company, string department, string office, string managerAccountName, string businessPhone, string fax, string homePhone, string mobilePhone, string pager, string webPage, string notes, string externalEmail) { string path = GetUserPath(organizationId, accountName); DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.FirstName, firstName); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.LastName, lastName); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.DisplayName, displayName); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Initials, initials); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.JobTitle, jobTitle); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Company, company); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Department, department); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Office, office); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.BusinessPhone, businessPhone); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Fax, fax); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.HomePhone, homePhone); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.MobilePhone, mobilePhone); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Pager, pager); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.WebPage, webPage); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Address, address); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.City, city); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.State, state); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Zip, zip); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Country, country); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Notes, notes); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.ExternalEmail, externalEmail); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.CustomAttribute2, (disabled ? "disabled" : null)); string manager = string.Empty; if (!string.IsNullOrEmpty(managerAccountName)) { string managerPath = GetUserPath(organizationId, managerAccountName); manager = ActiveDirectoryUtils.AdObjectExists(managerPath) ? managerPath : string.Empty; } ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.Manager, ActiveDirectoryUtils.RemoveADPrefix(manager)); entry.InvokeSet(ADAttributes.AccountDisabled, disabled); if (!string.IsNullOrEmpty(password)) { entry.Invoke(ADAttributes.SetPassword, password); } if (!locked) { bool isLoked = (bool)entry.InvokeGet(ADAttributes.AccountLocked); if (isLoked) { entry.InvokeSet(ADAttributes.AccountLocked, locked); } } entry.CommitChanges(); }
internal int CreateUserInternal(string organizationId, string loginName, string displayName, string upn, string password, bool enabled) { HostedSolutionLog.LogStart("CreateUserInternal"); HostedSolutionLog.DebugInfo("organizationId : {0}", organizationId); HostedSolutionLog.DebugInfo("loginName : {0}", loginName); HostedSolutionLog.DebugInfo("displayName : {0}", displayName); if (string.IsNullOrEmpty(organizationId)) { throw new ArgumentNullException("organizationId"); } if (string.IsNullOrEmpty(loginName)) { throw new ArgumentNullException("loginName"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException("password"); } bool userCreated = false; string userPath = null; try { string path = GetOrganizationPath(organizationId); userPath = GetUserPath(organizationId, loginName); if (!ActiveDirectoryUtils.AdObjectExists(userPath)) { userPath = ActiveDirectoryUtils.CreateUser(path, loginName, displayName, password, enabled); DirectoryEntry entry = new DirectoryEntry(userPath); ActiveDirectoryUtils.SetADObjectProperty(entry, ADAttributes.UserPrincipalName, upn); entry.CommitChanges(); userCreated = true; } else { return(Errors.AD_OBJECT_ALREADY_EXISTS); } string groupPath = GetGroupPath(organizationId); ActiveDirectoryUtils.AddUserToGroup(userPath, groupPath); } catch (Exception e) { HostedSolutionLog.LogError(e); try { if (userCreated) { ActiveDirectoryUtils.DeleteADObject(userPath); } } catch (Exception ex) { HostedSolutionLog.LogError(ex); } } HostedSolutionLog.LogEnd("CreateUserInternal"); return(Errors.OK); }