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

@ -1329,7 +1329,7 @@ namespace WebsitePanel.EnterpriseServer
Organizations orgProxy = GetOrganizationProxy(org.ServiceId); Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
string upn = string.Format("{0}@{1}", name, domain); string upn = string.Format("{0}@{1}", name, domain);
string sAMAccountName = BuildAccountName(org.OrganizationId, name); string sAMAccountName = BuildAccountName(org.OrganizationId, name, org.ServiceId);
TaskManager.Write("accountName :" + sAMAccountName); TaskManager.Write("accountName :" + sAMAccountName);
TaskManager.Write("upn :" + upn); TaskManager.Write("upn :" + upn);
@ -1455,20 +1455,20 @@ namespace WebsitePanel.EnterpriseServer
DataProvider.AddExchangeAccountEmailAddress(accountId, emailAddress); DataProvider.AddExchangeAccountEmailAddress(accountId, emailAddress);
} }
private static string BuildAccountName(string orgId, string name) private static string BuildAccountName(string orgId, string name, int ServiceId)
{ {
string accountName = name = name.Replace(" ", ""); string accountName = name = name.Replace(" ", "");
string CounterStr = "00000"; string CounterStr = "00000";
int counter = 0; int counter = 0;
bool bFound = false; bool bFound = false;
if (!AccountExists(accountName)) return accountName; if (!AccountExists(accountName, ServiceId)) return accountName;
do do
{ {
accountName = genSamLogin(name, CounterStr); accountName = genSamLogin(name, CounterStr);
if (!AccountExists(accountName)) bFound = true; if (!AccountExists(accountName, ServiceId)) bFound = true;
CounterStr = counter.ToString("d5"); CounterStr = counter.ToString("d5");
counter++; counter++;
@ -1494,9 +1494,18 @@ namespace WebsitePanel.EnterpriseServer
} }
private static bool AccountExists(string accountName) private static bool AccountExists(string accountName, int ServiceId)
{ {
return DataProvider.ExchangeAccountExists(accountName); if (!DataProvider.ExchangeAccountExists(accountName))
{
Organizations orgProxy = GetOrganizationProxy(ServiceId);
return orgProxy.DoesSamAccountNameExist(accountName);
}
else
return true;
} }
public static int DeleteUser(int itemId, int accountId) public static int DeleteUser(int itemId, int accountId)

View file

@ -64,5 +64,7 @@ namespace WebsitePanel.Providers.HostedSolution
PasswordPolicyResult GetPasswordPolicy(); PasswordPolicyResult GetPasswordPolicy();
string GetSamAccountNameByUserPrincipalName(string organizationId, string userPrincipalName); string GetSamAccountNameByUserPrincipalName(string organizationId, string userPrincipalName);
bool DoesSamAccountNameExist(string accountName);
} }
} }

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 #endregion
#region Domains #region Domains

View file

@ -162,5 +162,12 @@ namespace WebsitePanel.Server
{ {
return Organization.GetSamAccountNameByUserPrincipalName(organizationId, userPrincipalName); return Organization.GetSamAccountNameByUserPrincipalName(organizationId, userPrincipalName);
} }
[WebMethod, SoapHeader("settings")]
public bool DoesSamAccountNameExist(string accountName)
{
return Organization.DoesSamAccountNameExist(accountName);
}
} }
} }