Fixed: AD verification on existence of samAccountName when creating a user

object
This commit is contained in:
robvde 2013-01-19 09:40:27 +04:00
parent c48deb39b0
commit 53c40ab5eb
8 changed files with 172 additions and 27 deletions

View file

@ -710,6 +710,52 @@ 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;
return false;
}
#endregion
#region Domains