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

@ -12,6 +12,20 @@ BEGIN
END END
GO GO
--- Fix on version 2.0
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
GO
DELETE FROM HostingPlanQuotas WHERE QuotaID = 341
GO
DELETE FROM HostingPlanQuotas WHERE QuotaID = 342
GO
DELETE FROM HostingPlanQuotas WHERE QuotaID = 343
GO
DELETE FROM HostingPlanResources WHERE GroupID = 33
GO
-- Version 2.1 section -- Version 2.1 section
IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Hosted Microsoft Exchange Server 2013') IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Hosted Microsoft Exchange Server 2013')
BEGIN BEGIN
@ -25,16 +39,6 @@ GO
IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Exchange2007.AllowLitigationHold') IF NOT EXISTS (SELECT * FROM [dbo].[Quotas] WHERE [QuotaName] = 'Exchange2007.AllowLitigationHold')
DELETE FROM HostingPlanQuotas WHERE QuotaID = 340
GO
DELETE FROM HostingPlanQuotas WHERE QuotaID = 341
GO
DELETE FROM HostingPlanQuotas WHERE QuotaID = 342
GO
DELETE FROM HostingPlanQuotas WHERE QuotaID = 343
GO
DELETE FROM HostingPlanResources WHERE GroupID = 33
GO
BEGIN BEGIN
INSERT [dbo].[Quotas] ([QuotaID], [GroupID],[QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (420, 12, 24,N'Exchange2007.AllowLitigationHold',N'Allow Litigation Hold',1, 0 , NULL) INSERT [dbo].[Quotas] ([QuotaID], [GroupID],[QuotaOrder], [QuotaName], [QuotaDescription], [QuotaTypeID], [ServiceQuota], [ItemTypeID]) VALUES (420, 12, 24,N'Exchange2007.AllowLitigationHold',N'Allow Litigation Hold',1, 0 , NULL)
END END
@ -315,4 +319,10 @@ exec sp_xml_removedocument @idoc
COMMIT TRAN COMMIT TRAN
RETURN RETURN
GO GO
IF NOT EXISTS (SELECT * FROM [dbo].[Providers] WHERE [DisplayName] = 'Hosted MS CRM 2011')
BEGIN
INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (1201, 21, N'CRM', N'Hosted MS CRM 2011', N'WebsitePanel.Providers.HostedSolution.CRMProvider2011, WebsitePanel.Providers.HostedSolution', N'CRM', NULL)
END
GO

View file

@ -1,2 +0,0 @@
INSERT [dbo].[Providers] ([ProviderID], [GroupID], [ProviderName], [DisplayName], [ProviderType], [EditorControl], [DisableAutoDiscovery]) VALUES (1201, 21, N'CRM', N'Hosted MS CRM 2011', N'WebsitePanel.Providers.HostedSolution.CRMProvider2011, WebsitePanel.Providers.HostedSolution', N'CRM', NULL)
GO

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);
@ -1454,21 +1454,21 @@ 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,19 @@ 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,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 #endregion
#region Domains #region Domains

View file

@ -26,7 +26,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
@ -48,11 +47,11 @@ namespace WebsitePanel.Providers.HostedSolution {
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using WebsitePanel.Providers.Common; using WebsitePanel.Providers.Common;
using WebsitePanel.Providers.ResultObjects; using WebsitePanel.Providers.ResultObjects;
/// <remarks/> /// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")] [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()]
@ -90,6 +89,8 @@ namespace WebsitePanel.Providers.HostedSolution {
private System.Threading.SendOrPostCallback GetSamAccountNameByUserPrincipalNameOperationCompleted; private System.Threading.SendOrPostCallback GetSamAccountNameByUserPrincipalNameOperationCompleted;
private System.Threading.SendOrPostCallback DoesSamAccountNameExistOperationCompleted;
/// <remarks/> /// <remarks/>
public Organizations() { public Organizations() {
this.Url = "http://localhost:9003/Organizations.asmx"; this.Url = "http://localhost:9003/Organizations.asmx";
@ -134,6 +135,9 @@ namespace WebsitePanel.Providers.HostedSolution {
/// <remarks/> /// <remarks/>
public event GetSamAccountNameByUserPrincipalNameCompletedEventHandler GetSamAccountNameByUserPrincipalNameCompleted; public event GetSamAccountNameByUserPrincipalNameCompletedEventHandler GetSamAccountNameByUserPrincipalNameCompleted;
/// <remarks/>
public event DoesSamAccountNameExistCompletedEventHandler DoesSamAccountNameExistCompleted;
/// <remarks/> /// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")] [System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/OrganizationExists", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)] [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/OrganizationExists", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
@ -901,6 +905,48 @@ namespace WebsitePanel.Providers.HostedSolution {
} }
} }
/// <remarks/>
[System.Web.Services.Protocols.SoapHeaderAttribute("ServiceProviderSettingsSoapHeaderValue")]
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/DoesSamAccountNameExist", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public bool DoesSamAccountNameExist(string accountName) {
object[] results = this.Invoke("DoesSamAccountNameExist", new object[] {
accountName});
return ((bool)(results[0]));
}
/// <remarks/>
public System.IAsyncResult BeginDoesSamAccountNameExist(string accountName, System.AsyncCallback callback, object asyncState) {
return this.BeginInvoke("DoesSamAccountNameExist", new object[] {
accountName}, callback, asyncState);
}
/// <remarks/>
public bool EndDoesSamAccountNameExist(System.IAsyncResult asyncResult) {
object[] results = this.EndInvoke(asyncResult);
return ((bool)(results[0]));
}
/// <remarks/>
public void DoesSamAccountNameExistAsync(string accountName) {
this.DoesSamAccountNameExistAsync(accountName, null);
}
/// <remarks/>
public void DoesSamAccountNameExistAsync(string accountName, object userState) {
if ((this.DoesSamAccountNameExistOperationCompleted == null)) {
this.DoesSamAccountNameExistOperationCompleted = new System.Threading.SendOrPostCallback(this.OnDoesSamAccountNameExistOperationCompleted);
}
this.InvokeAsync("DoesSamAccountNameExist", new object[] {
accountName}, this.DoesSamAccountNameExistOperationCompleted, userState);
}
private void OnDoesSamAccountNameExistOperationCompleted(object arg) {
if ((this.DoesSamAccountNameExistCompleted != null)) {
System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
this.DoesSamAccountNameExistCompleted(this, new DoesSamAccountNameExistCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
}
}
/// <remarks/> /// <remarks/>
public new void CancelAsync(object userState) { public new void CancelAsync(object userState) {
base.CancelAsync(userState); base.CancelAsync(userState);
@ -1090,4 +1136,30 @@ namespace WebsitePanel.Providers.HostedSolution {
} }
} }
} }
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
public delegate void DoesSamAccountNameExistCompletedEventHandler(object sender, DoesSamAccountNameExistCompletedEventArgs e);
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class DoesSamAccountNameExistCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
internal DoesSamAccountNameExistCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
/// <remarks/>
public bool Result {
get {
this.RaiseExceptionIfNecessary();
return ((bool)(this.results[0]));
}
}
}
} }

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);
}
} }
} }

View file

@ -17,8 +17,8 @@ REM %WSE_CLEAN% .\WebsitePanel.Server.Client\DatabaseServerProxy.cs
REM %WSDL% %SERVER_URL%/DNSServer.asmx /out:.\WebsitePanel.Server.Client\DnsServerProxy.cs /namespace:WebsitePanel.Providers.DNS /type:webClient /fields REM %WSDL% %SERVER_URL%/DNSServer.asmx /out:.\WebsitePanel.Server.Client\DnsServerProxy.cs /namespace:WebsitePanel.Providers.DNS /type:webClient /fields
REM %WSE_CLEAN% .\WebsitePanel.Server.Client\DnsServerProxy.cs REM %WSE_CLEAN% .\WebsitePanel.Server.Client\DnsServerProxy.cs
%WSDL% %SERVER_URL%/ExchangeServer.asmx /out:.\WebsitePanel.Server.Client\ExchangeServerProxy.cs /namespace:WebsitePanel.Providers.Exchange /type:webClient /fields REM %WSDL% %SERVER_URL%/ExchangeServer.asmx /out:.\WebsitePanel.Server.Client\ExchangeServerProxy.cs /namespace:WebsitePanel.Providers.Exchange /type:webClient /fields
%WSE_CLEAN% .\WebsitePanel.Server.Client\ExchangeServerProxy.cs REM %WSE_CLEAN% .\WebsitePanel.Server.Client\ExchangeServerProxy.cs
REM %WSDL% %SERVER_URL%/ExchangeServerHostedEdition.asmx /out:.\WebsitePanel.Server.Client\ExchangeServerHostedEditionProxy.cs /namespace:WebsitePanel.Providers.ExchangeHostedEdition /type:webClient /fields REM %WSDL% %SERVER_URL%/ExchangeServerHostedEdition.asmx /out:.\WebsitePanel.Server.Client\ExchangeServerHostedEditionProxy.cs /namespace:WebsitePanel.Providers.ExchangeHostedEdition /type:webClient /fields
REM %WSE_CLEAN% .\WebsitePanel.Server.Client\ExchangeServerHostedEditionProxy.cs REM %WSE_CLEAN% .\WebsitePanel.Server.Client\ExchangeServerHostedEditionProxy.cs
@ -35,8 +35,8 @@ REM %WSE_CLEAN% .\WebsitePanel.Server.Client\OCSServerProxy.cs
REM %WSDL% %SERVER_URL%/OperatingSystem.asmx /out:.\WebsitePanel.Server.Client\OperatingSystemProxy.cs /namespace:WebsitePanel.Providers.OS /type:webClient /fields REM %WSDL% %SERVER_URL%/OperatingSystem.asmx /out:.\WebsitePanel.Server.Client\OperatingSystemProxy.cs /namespace:WebsitePanel.Providers.OS /type:webClient /fields
REM %WSE_CLEAN% .\WebsitePanel.Server.Client\OperatingSystemProxy.cs REM %WSE_CLEAN% .\WebsitePanel.Server.Client\OperatingSystemProxy.cs
REM %WSDL% %SERVER_URL%/Organizations.asmx /out:.\WebsitePanel.Server.Client\OrganizationProxy.cs /namespace:WebsitePanel.Providers.HostedSolution /type:webClient /fields %WSDL% %SERVER_URL%/Organizations.asmx /out:.\WebsitePanel.Server.Client\OrganizationProxy.cs /namespace:WebsitePanel.Providers.HostedSolution /type:webClient /fields
REM %WSE_CLEAN% .\WebsitePanel.Server.Client\OrganizationProxy.cs %WSE_CLEAN% .\WebsitePanel.Server.Client\OrganizationProxy.cs
REM %WSDL% %SERVER_URL%/ServiceProvider.asmx /out:.\WebsitePanel.Server.Client\ServiceProviderProxy.cs /namespace:WebsitePanel.Providers /type:webClient /fields REM %WSDL% %SERVER_URL%/ServiceProvider.asmx /out:.\WebsitePanel.Server.Client\ServiceProviderProxy.cs /namespace:WebsitePanel.Providers /type:webClient /fields
REM %WSE_CLEAN% .\WebsitePanel.Server.Client\ServiceProviderProxy.cs REM %WSE_CLEAN% .\WebsitePanel.Server.Client\ServiceProviderProxy.cs