fixed: AD verification on samAccountName when creating user

object
This commit is contained in:
robvde 2013-01-19 09:55:05 +04:00
parent 71600a0be1
commit 43ff5bfaf6
5 changed files with 691 additions and 416 deletions

View file

@ -710,6 +710,47 @@ namespace WebsitePanel.Providers.HostedSolution
}
public bool DoesSamAccountNameExist(string accountName)
{
return DoesSamAccountNameExistInternal(accountName);
}
private bool DoesSamAccountNameExistInternal(string accountName)
{
HostedSolutionLog.LogStart("DoesSamAccountNameExistInternal");
HostedSolutionLog.DebugInfo("userPrincipalName : {0}", accountName);
bool bFound = false;
try
{
string path = GetRootOU();
DirectoryEntry entry = ActiveDirectoryUtils.GetADObject(path);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.PropertiesToLoad.Add("sAMAccountName");
searcher.Filter = "(sAMAccountName=" + accountName + ")";
searcher.SearchScope = SearchScope.Subtree;
SearchResult resCollection = searcher.FindOne();
if (resCollection != null)
{
if (resCollection.Properties["samaccountname"] != null)
bFound = true; ;
}
HostedSolutionLog.LogEnd("GetSamAccountNameByUserPrincipalNameInternal");
}
catch (Exception e)
{
HostedSolutionLog.DebugInfo("Failed : {0}", e.Message);
}
return bFound;
}
#endregion
#region Domains