diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs index 0d0a3b6d..41f27079 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Code/HostedSolution/OrganizationController.cs @@ -1314,8 +1314,18 @@ namespace WebsitePanel.EnterpriseServer // load organization Organization org = GetOrganization(itemId); + if (org == null) + { return -1; + } + + StringDictionary serviceSettings = ServerController.GetServiceSettings(org.ServiceId); + + if (serviceSettings == null) + { + return -1; + } // check package int packageCheck = SecurityContext.CheckPackage(org.PackageId, DemandPackage.IsActive); @@ -1329,7 +1339,7 @@ namespace WebsitePanel.EnterpriseServer Organizations orgProxy = GetOrganizationProxy(org.ServiceId); string upn = string.Format("{0}@{1}", name, domain); - string sAMAccountName = BuildAccountName(org.OrganizationId, name, org.ServiceId); + string sAMAccountName = AppendOrgId(serviceSettings) ? BuildAccountNameWithOrgId(org.OrganizationId, name, org.ServiceId) : BuildAccountName(org.OrganizationId, name, org.ServiceId); TaskManager.Write("accountName :" + sAMAccountName); TaskManager.Write("upn :" + upn); @@ -1367,7 +1377,23 @@ namespace WebsitePanel.EnterpriseServer return userId; } + /// Checks should or not user name include organization id. + /// The service settings. + /// True - if organization id should be appended. + private static bool AppendOrgId(StringDictionary serviceSettings) + { + if (!serviceSettings.ContainsKey("usernameformat")) + { + return false; + } + if (!serviceSettings["usernameformat"].Equals("Append OrgId", StringComparison.CurrentCultureIgnoreCase)) + { + return false; + } + + return true; + } public static int ImportUser(int itemId, string accountName, string displayName, string name, string domain, string password, string subscriberNumber) { @@ -1474,6 +1500,40 @@ namespace WebsitePanel.EnterpriseServer return accountName; } + /// Building account name with organization Id. + /// The organization identifier. + /// The name. + /// The service identifier. + /// The account name with organization Id. + private static string BuildAccountNameWithOrgId(string orgId, string name, int serviceId) + { + int maxLen = 19 - orgId.Length; + + // try to choose name + int i = 0; + + while (true) + { + string num = i > 0 ? i.ToString() : ""; + int len = maxLen - num.Length; + + if (name.Length > len) + { + name = name.Substring(0, len); + } + + string accountName = name + num + "_" + orgId; + + // check if already exists + if (!AccountExists(accountName, serviceId)) + { + return accountName; + } + + i++; + } + } + private static string genSamLogin(string login, string strCounter) { int maxLogin = 20; diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/Organizations_Settings.ascx.resx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/Organizations_Settings.ascx.resx index 6f6e1735..340ae559 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/Organizations_Settings.ascx.resx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/App_LocalResources/Organizations_Settings.ascx.resx @@ -126,4 +126,13 @@ Tempory Domain Name: + + Username Format: + + + Standard + + + Append OrgID + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx index fbbf9ffd..3905c282 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx @@ -23,4 +23,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.cs index a3596f40..e7fb8f87 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.cs @@ -35,6 +35,7 @@ namespace WebsitePanel.Portal.ProviderControls public const string RootOU = "RootOU"; public const string PrimaryDomainController = "PrimaryDomainController"; public const string TemporyDomainName = "TempDomain"; + public const string UserNameFormat = "UserNameFormat"; protected void Page_Load(object sender, EventArgs e) { @@ -46,6 +47,12 @@ namespace WebsitePanel.Portal.ProviderControls txtPrimaryDomainController.Text = settings[PrimaryDomainController]; txtRootOU.Text = settings[RootOU]; txtTemporyDomainName.Text = settings[TemporyDomainName]; + + if (settings.ContainsKey(UserNameFormat)) + { + UserNameFormatDropDown.SelectedValue = + UserNameFormatDropDown.Items.FindByText(settings[UserNameFormat]).Value; + } } public void SaveSettings(System.Collections.Specialized.StringDictionary settings) @@ -53,6 +60,7 @@ namespace WebsitePanel.Portal.ProviderControls settings[RootOU] = txtRootOU.Text.Trim(); settings[PrimaryDomainController] = txtPrimaryDomainController.Text.Trim(); settings[TemporyDomainName] = txtTemporyDomainName.Text.Trim(); + settings[UserNameFormat] = UserNameFormatDropDown.SelectedItem.Text; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.designer.cs b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.designer.cs index 5faeea8c..2cbecd62 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.designer.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebPortal/DesktopModules/WebsitePanel/ProviderControls/Organizations_Settings.ascx.designer.cs @@ -1,22 +1,15 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:2.0.50727.1378 // // Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// the code is regenerated. // //------------------------------------------------------------------------------ namespace WebsitePanel.Portal.ProviderControls { - /// - /// Organizations_Settings class. - /// - /// - /// Auto-generated class. - /// public partial class Organizations_Settings { /// @@ -81,5 +74,23 @@ namespace WebsitePanel.Portal.ProviderControls { /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.TextBox txtTemporyDomainName; + + /// + /// UserNameFormatLabel control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.Label UserNameFormatLabel; + + /// + /// UserNameFormatDropDown control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.DropDownList UserNameFormatDropDown; } }