fixed: AD verification on samAccountName when creating user
object
This commit is contained in:
parent
71600a0be1
commit
43ff5bfaf6
5 changed files with 691 additions and 416 deletions
|
@ -1329,7 +1329,7 @@ namespace WebsitePanel.EnterpriseServer
|
|||
Organizations orgProxy = GetOrganizationProxy(org.ServiceId);
|
||||
|
||||
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("upn :" + upn);
|
||||
|
@ -1454,21 +1454,21 @@ namespace WebsitePanel.EnterpriseServer
|
|||
{
|
||||
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 CounterStr = "00000";
|
||||
int counter = 0;
|
||||
bool bFound = false;
|
||||
|
||||
if (!AccountExists(accountName)) return accountName;
|
||||
if (!AccountExists(accountName, ServiceId)) return accountName;
|
||||
|
||||
do
|
||||
{
|
||||
accountName = genSamLogin(name, CounterStr);
|
||||
|
||||
if (!AccountExists(accountName)) bFound = true;
|
||||
if (!AccountExists(accountName, ServiceId)) bFound = true;
|
||||
|
||||
CounterStr = counter.ToString("d5");
|
||||
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)
|
||||
|
|
|
@ -64,5 +64,7 @@ namespace WebsitePanel.Providers.HostedSolution
|
|||
PasswordPolicyResult GetPasswordPolicy();
|
||||
|
||||
string GetSamAccountNameByUserPrincipalName(string organizationId, string userPrincipalName);
|
||||
|
||||
bool DoesSamAccountNameExist(string accountName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -162,5 +162,12 @@ namespace WebsitePanel.Server
|
|||
{
|
||||
return Organization.GetSamAccountNameByUserPrincipalName(organizationId, userPrincipalName);
|
||||
}
|
||||
|
||||
[WebMethod, SoapHeader("settings")]
|
||||
public bool DoesSamAccountNameExist(string accountName)
|
||||
{
|
||||
return Organization.DoesSamAccountNameExist(accountName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue