Example #1
0
        public LdapUser(DirectoryEntry adentry, String userName, LdapSettings ldapSettings)
        {
            userid = new LdapAttribute("userid", userName);
            DirectorySearcher ds = new DirectorySearcher(adentry);
            ds.Filter = "(&(sAMAccountName=" + userName + "))";
            SearchResult result = ds.FindOne();
            DirectoryEntry ent = null;

            if (result != null)
            {
                ent = result.GetDirectoryEntry();
            }

            if (ent != null)
            {
                if (ent.Properties["cn"].Value != null)
                {
                    commonname = new LdapAttribute("commonname", ent.Properties["cn"].Value.ToString());
                }
                else
                {
                    commonname = new LdapAttribute("commonname", userName);
                }
                if (ent.Properties["mail"].Value != null)
                {
                    email = new LdapAttribute("email", ent.Properties["mail"].Value.ToString());
                }
                else
                {
                    email = new LdapAttribute("email", userName + "@" + ldapSettings.Domain);
                }
            }
        }
Example #2
0
        private static LdapEntry GetOneUserEntry(
            LdapConnection conn,
            LdapSettings ldapSettings,
            string search)
        {
            LdapSearchConstraints constraints = new LdapSearchConstraints();

            LdapSearchQueue queue = null;

            queue = conn.Search(
                ldapSettings.RootDN,
                LdapConnection.SCOPE_SUB,
                ldapSettings.UserDNKey + "=" + search,
                null,
                false,
                (LdapSearchQueue)null,
                (LdapSearchConstraints)null);

            LdapEntry entry = null;

            if (queue != null)
            {
                LdapMessage message = queue.getResponse();
                if (message != null)
                {
                    if (message is LdapSearchResult)
                    {
                        entry = ((LdapSearchResult)message).Entry;
                    }
                }
            }

            return(entry);
        }
Example #3
0
        public LdapUser(DirectoryEntry adentry, String userName, LdapSettings ldapSettings)
        {
            userid = new LdapAttribute("userid", userName);
            DirectorySearcher ds = new DirectorySearcher(adentry);

            ds.Filter = "(&(sAMAccountName=" + userName + "))";
            SearchResult   result = ds.FindOne();
            DirectoryEntry ent    = null;

            if (result != null)
            {
                ent = result.GetDirectoryEntry();
            }

            if (ent != null)
            {
                if (ent.Properties["cn"].Value != null)
                {
                    commonname = new LdapAttribute("commonname", ent.Properties["cn"].Value.ToString());
                }
                else
                {
                    commonname = new LdapAttribute("commonname", userName);
                }
                if (ent.Properties["mail"].Value != null)
                {
                    email = new LdapAttribute("email", ent.Properties["mail"].Value.ToString());
                }
                else
                {
                    email = new LdapAttribute("email", userName + "@" + ldapSettings.Domain);
                }
            }
        }
Example #4
0
        private static LdapUser LdapStandardLogin(LdapSettings ldapSettings, string uid, string password)
        {
            bool     success = false;
            LdapUser user    = null;

            LdapConnection conn = null;

            try
            {
                conn = GetConnection(ldapSettings);
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                if (log.IsErrorEnabled)
                {
                    //log.Error("couldn't connect to ldap server ", ex);
                    string msg = "Login failure for user: "******". Exception: ";
                    log.Error(msg, ex);
                }
            }

            if ((conn != null) && (conn.Connected))
            {
                LdapEntry entry = null;

                try
                {
                    entry = GetOneUserEntry(conn, ldapSettings, uid);
                    if (entry != null)
                    {
                        LdapConnection authConn = GetConnection(ldapSettings);
                        authConn.Bind(entry.DN, password);
                        authConn.Disconnect();
                        success = true;
                    }
                }
                catch (Novell.Directory.Ldap.LdapException ex)
                {
                    if (log.IsErrorEnabled)
                    {
                        //log.Error("login failure", ex);
                        string msg = "Login failure for user: "******". Exception: ";
                        log.Error(msg, ex);
                    }
                    success = false;
                }

                if (success)
                {
                    if (entry != null)
                    {
                        user = new LdapUser(entry);
                    }
                }

                conn.Disconnect();
            }

            return(user);
        }
Example #5
0
 public static LdapUser LdapLogin(LdapSettings ldapSettings, string uid, string password)
 {
     if (ldapSettings.UserDNKey == "uid") //OpenLDAP
     {
         return(LdapStandardLogin(ldapSettings, uid, password));
     }
     else //Active Directory
     {
         return(ActiveDirectoryLogin(ldapSettings, uid, password));
     }
 }
Example #6
0
        //public static LdapUser LdapLogin(LdapSettings ldapSettings, string uid, string password)
        //{
        //    LdapConnection conn = null;
        //    try
        //    {
        //        conn = GetConnection(ldapSettings);
        //    }
        //    catch (System.Net.Sockets.SocketException ex)
        //    {
        //        log.Error("couldn't connect to ldap server ", ex);
        //    }

        //    bool success = false;
        //    LdapUser user = null;

        //    if ((conn != null)&&(conn.Connected))
        //    {
        //        LdapEntry entry = null;

        //        try
        //        {
        //            // open ldap uses uid
        //            if(ldapSettings.UserDNKey == "uid")
        //            {
        //                entry = GetOneUserEntry(conn, ldapSettings, uid);
        //                if(entry != null)
        //                {
        //                    LdapConnection authConn = GetConnection(ldapSettings);
        //                    authConn.Bind(entry.DN, password);
        //                    authConn.Disconnect();
        //                    success = true;

        //                }

        //            }
        //            else
        //            {
        //                // Active Directory uses CN

        //                // might need this if other Ldap Servers besides Active Directory use CN
        //                //conn.Bind(
        //                //    ldapSettings.UserDNKey + "=" + uid + "," + ldapSettings.RootDN, password);


        //                // this works with Active Directory
        //                conn.Bind(uid + "@" + ldapSettings.Domain, password);
        //                success = conn.Bound;
        //                entry = GetOneUserEntry(conn, ldapSettings, uid);

        //            }


        //        }
        //        catch (Novell.Directory.Ldap.LdapException ex)
        //        {
        //            if (log.IsErrorEnabled)
        //            {
        //                log.Error("login failure", ex);
        //            }
        //            success = false;
        //        }

        //        if (success)
        //        {
        //            if (entry != null)
        //            {
        //                user = new LdapUser(entry);
        //            }
        //            else
        //            {
        //                user = new LdapUser(ldapSettings, uid);
        //            }

        //        }

        //        conn.Disconnect();
        //    }

        //    return user;
        //}

        public static bool TestUser(LdapSettings ldapSettings, string uid, string password)
        {
            bool result = false;

            LdapUser testUser = LdapLogin(ldapSettings, uid, password);

            if (testUser != null)
            {
                result = true;
            }

            return(result);
        }
Example #7
0
        private static LdapConnection GetConnection(LdapSettings ldapSettings)
        {
            LdapConnection conn = new LdapConnection();

            bool useSsl = false;

            if (ConfigurationManager.AppSettings["UseSslForLdap"] != null)
            {
                useSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSslForLdap"]);
            }

            if (useSsl)
            {
                // make this support ssl/tls
                //http://stackoverflow.com/questions/386982/novell-ldap-c-novell-directory-ldap-has-anybody-made-it-work
                conn.SecureSocketLayer = true;
                conn.UserDefinedServerCertValidationDelegate += new CertificateValidationCallback(LdapSSLHandler);
            }

            conn.Connect(ldapSettings.Server, ldapSettings.Port);

            return(conn);
        }
 private bool TestCurrentUserLdap(LdapSettings testLdapSettings)
 {
     String uid = Context.User.Identity.Name;
     SiteUser user = new SiteUser(this.selectedSite, uid);
     return LdapHelper.TestUser(testLdapSettings, user.LoginName, txtLdapTestPassword.Text);
 }
        protected void btnSave_Click(Object sender, EventArgs e)
        {
            Page.Validate("sitesettings");
            if (!Page.IsValid) { return; }

            bool creatingNewSite = false;
            if (this.IsServerAdmin)
            {
                if (isAdmin)
                {
                    if (selectedSiteID == -1)
                    {
                        selectedSite = new SiteSettings(selectedSiteID);
                        creatingNewSite = true;
                    }
                }
            }

            selectedSite.SiteName = txtSiteName.Text.Trim();
            selectedSite.Slogan = txtSlogan.Text;
            selectedSite.CompanyName = txtCompanyName.Text;
            selectedSite.CompanyStreetAddress = txtStreetAddress.Text;
            selectedSite.CompanyStreetAddress2 = txtStreetAddress2.Text;
            selectedSite.CompanyLocality = txtLocality.Text;
            selectedSite.CompanyRegion = txtRegion.Text;
            selectedSite.CompanyPostalCode = txtPostalCode.Text;
            selectedSite.CompanyCountry = txtCountry.Text;
            selectedSite.CompanyPhone = txtPhone.Text;
            selectedSite.CompanyFax = txtFax.Text;
            selectedSite.CompanyPublicEmail = txtPublicEmail.Text;

            selectedSite.PrivacyPolicyUrl = txtPrivacyPolicyUrl.Text;

            selectedSite.BingAPIId = txtBingSearchAPIKey.Text;
            selectedSite.GoogleCustomSearchId = txtGoogleCustomSearchId.Text;
            selectedSite.ShowAlternateSearchIfConfigured = chkShowAlternateSearchIfConfigured.Checked;
            selectedSite.PrimarySearchEngine = ddSearchEngine.SelectedValue;

            #if!MONO
            ISettingControl setting = timeZone as ISettingControl;
            if (setting != null)
            {
                selectedSite.TimeZoneId = setting.GetValue();
            }
            #endif

            selectedSite.Logo = ddLogos.SelectedValue;
            selectedSite.Skin = SkinSetting.GetValue();

            if (ddMobileSkin.Enabled)
            {
                selectedSite.MobileSkin = ddMobileSkin.SelectedValue;
            }

            selectedSite.MyPageSkin = ddMyPageSkin.SelectedValue;
            if (ddEditorProviders.SelectedIndex > -1)
            {
                selectedSite.EditorProviderName = ddEditorProviders.SelectedValue;
            }

            if (ddNewsletterEditor.SelectedIndex > -1)
            {
                selectedSite.NewsletterEditor = ddNewsletterEditor.SelectedValue;
            }

            selectedSite.AvatarSystem = ddAvatarSystem.SelectedValue;

            selectedSite.DefaultFriendlyUrlPattern = (SiteSettings.FriendlyUrlPattern)Enum.Parse(typeof(SiteSettings.FriendlyUrlPattern), ddDefaultFriendlyUrlPattern.SelectedValue);

            if (ddCaptchaProviders.SelectedIndex > -1)
            {
                selectedSite.CaptchaProvider = ddCaptchaProviders.SelectedValue;
            }

            if (ddDefaultCountry.SelectedValue.Length == 36)
            {
                selectedSite.DefaultCountryGuid = new Guid(ddDefaultCountry.SelectedValue);
            }

            if (ddDefaultGeoZone.SelectedValue.Length == 36)
            {
                selectedSite.DefaultStateGuid = new Guid(ddDefaultGeoZone.SelectedValue);
            }

            selectedSite.RecaptchaPrivateKey = txtRecaptchaPrivateKey.Text;
            selectedSite.RecaptchaPublicKey = txtRecaptchaPublicKey.Text;
            selectedSite.GmapApiKey = txtGmapApiKey.Text;
            selectedSite.AddThisDotComUsername = txtAddThisUserId.Text;
            selectedSite.GoogleAnalyticsAccountCode = txtGoogleAnayticsAccountCode.Text;
            selectedSite.OpenIdSelectorId = txtOpenIdSelectorCode.Text;
            selectedSite.CommentProvider = ddCommentSystem.SelectedValue;
            selectedSite.IntenseDebateAccountId = txtIntenseDebateAccountId.Text;
            selectedSite.DisqusSiteShortName = txtDisqusSiteShortName.Text;
            selectedSite.FacebookAppId = txtFacebookAppId.Text;

            if (divWoopra.Visible)
            {
                selectedSite.EnableWoopra = chkEnableWoopra.Checked;
            }

            if (divSiteIsClosed.Visible)
            {
                selectedSite.SiteIsClosed = chkSiteIsClosed.Checked;
            }

            // keep track if password format changed then we need to update passwords to new format
            int previousPasswordFormat = selectedSite.PasswordFormat;

            if (isAdmin)
            {
                selectedSite.PreferredHostName = txtPreferredHostName.Text.Replace("https://", string.Empty).Replace("http://",string.Empty).Replace("/", string.Empty);

                if (WebConfigSettings.EnableOpenIdAuthentication)
                {
                    selectedSite.AllowOpenIdAuth = chkAllowOpenIDAuth.Checked;
                }
                if (WebConfigSettings.EnableWindowsLiveAuthentication)
                {
                    selectedSite.AllowWindowsLiveAuth = chkAllowWindowsLiveAuth.Checked;
                    selectedSite.WindowsLiveAppId = txtWindowsLiveAppID.Text;
                    selectedSite.WindowsLiveKey = txtWindowsLiveKey.Text;
                }

                selectedSite.DisableDbAuth = chkDisableDbAuthentication.Checked;

                selectedSite.AllowWindowsLiveMessengerForMembers = chkAllowWindowsLiveMessengerForMembers.Checked;
                selectedSite.AppLogoForWindowsLive = txtAppLogoForWindowsLive.Text;

                selectedSite.RpxNowApiKey = txtRpxNowApiKey.Text;
                selectedSite.RpxNowApplicationName = txtRpxNowApplicationName.Text;
                if (selectedSite.RpxNowApiKey.Length == 0) { selectedSite.RpxNowAdminUrl = string.Empty; }

                selectedSite.OpenSearchName = txtOpenSearchName.Text;

                selectedSite.AllowUserSkins = chkAllowUserSkins.Checked;
                selectedSite.AllowPageSkins = chkAllowPageSkins.Checked;
                selectedSite.AllowHideMenuOnPages = chkAllowHideMenuOnPages.Checked;
                selectedSite.UseSecureRegistration = chkSecureRegistration.Checked;
                selectedSite.RequireApprovalBeforeLogin = chkRequireApprovalForLogin.Checked;
                selectedSite.EmailAdressesForUserApprovalNotification = txtEmailAdressesForUserApprovalNotification.Text;
                selectedSite.AllowPersistentLogin = chkAllowPersistentLogin.Checked;
                selectedSite.ForceContentVersioning = chkForceContentVersioning.Checked;
                selectedSite.EnableContentWorkflow = chkEnableContentWorkflow.Checked;

                ISettingControl currencySetting = SiteCurrencySetting as ISettingControl;
                string currencyGuidString = currencySetting.GetValue();
                if (currencyGuidString.Length == 36)
                {
                    selectedSite.CurrencyGuid = new Guid(currencyGuidString);
                }

                //ISettingControl commerceReportRoles = CommerceReportRolesSetting as ISettingControl;
                //selectedSite.RolesThatCanCreateRootPages = chkRolesThatCanCreateRootPages.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.CommerceReportViewRoles = chkCommerceReportRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.GeneralBrowseAndUploadRoles = chkGeneralBrowseAndUploadRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.UserFilesBrowseAndUploadRoles = chkUserFilesBrowseAndUploadRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanEditContentTemplates = chkRolesThatCanEditContentTemplates.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesNotAllowedToEditModuleSettings = chkRolesNotAllowedToEditModuleSettings.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanCreateUsers = chkRolesThatCanCreateUsers.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanManageUsers = chkRolesThatCanManageUsers.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanLookupUsers = chkRolesThatCanLookupUsers.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanViewMemberList = chkRolesThatCanViewMemberList.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanViewMyPage = chkRolesThatCanViewMyPage.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanDeleteFilesInEditor = chkRolesThatCanDeleteFilesInEditor.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanManageSkins = chkRolesThatCanManageSkins.Items.SelectedItemsToSemiColonSeparatedString();
                //selectedSite.RolesThatCanAssignSkinsToPages = chkRolesThatCanAssignSkinsToPages.Items.SelectedItemsToSemiColonSeparatedString();

                //if (divDefaultRootPageViewRoles.Visible)
                //{
                //    selectedSite.DefaultRootPageViewRoles = chkDefaultRootPageViewRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //}

                //if (divDefaultRootPageEditRoles.Visible)
                //{
                //    selectedSite.DefaultRootPageEditRoles = chkDefaultRootPageEditRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //}

                //if (divDefaultRootPageCreateChildPageRoles.Visible)
                //{
                //    selectedSite.DefaultRootPageCreateChildPageRoles = chkDefaultRootPageCreateChildPageRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //}

                if (sslIsAvailable)
                {
                    selectedSite.UseSslOnAllPages = chkRequireSSL.Checked;
                }

                if ((chkAllowRegistration.Enabled) && (divAllowRegistration.Visible)&&(tabGeneralSecurity.Visible))
                {
                    selectedSite.AllowNewRegistration = chkAllowRegistration.Checked;
                }
                else
                {
                    if (chkUseLdapAuth.Checked && !selectedSite.AllowDbFallbackWithLdap)
                    {
                        selectedSite.AllowNewRegistration = false;
                    }

                }

                if (
                (WebConfigSettings.UseRelatedSiteMode)
                && ((selectedSite.SiteId != WebConfigSettings.RelatedSiteID) && (selectedSiteID != -1))
                )
                {
                    //don't change this on child sites in related sites mode
                }
                else
                {
                    if ((chkAllowUserToChangeName.Enabled) && (divAllowUserToChangeName.Visible))
                    {
                        selectedSite.AllowUserFullNameChange = chkAllowUserToChangeName.Checked;
                    }

                    if ((chkUseEmailForLogin.Enabled) && (divUseEmailForLogin.Visible))
                    {
                        selectedSite.UseEmailForLogin = chkUseEmailForLogin.Checked;

                    }

                }

                selectedSite.AutoCreateLdapUserOnFirstLogin = chkAutoCreateLdapUserOnFirstLogin.Checked;
                selectedSite.AllowDbFallbackWithLdap = chkAllowDbFallbackWithLdap.Checked;
                selectedSite.AllowEmailLoginWithLdapDbFallback = chkAllowEmailLoginWithLdapDbFallback.Checked;

                if ((!selectedSite.UseLdapAuth) && (chkUseLdapAuth.Checked) && (!creatingNewSite))
                {
                    LdapSettings testLdapSettings = new LdapSettings();
                    testLdapSettings.Server = txtLdapServer.Text;
                    testLdapSettings.Port = Convert.ToInt32(txtLdapPort.Text);
                    testLdapSettings.Domain = txtLdapDomain.Text;
                    testLdapSettings.RootDN = txtLdapRootDN.Text;
                    testLdapSettings.UserDNKey = ddLdapUserDNKey.SelectedValue;
                    if (!TestCurrentUserLdap(testLdapSettings))
                    {
                        lblErrorMessage.Text += "  " + Resource.SiteSettingsLDAPAdminUserNotFound;
                        btnSave.Text = Resource.SiteSettingsApplyChangesButton;
                        btnSave.Enabled = true;
                        return;
                    }
                }

                if (
                (WebConfigSettings.UseRelatedSiteMode)
                && ((selectedSite.SiteId != WebConfigSettings.RelatedSiteID) && (selectedSiteID != -1))
                )
                {
                    tabLDAP.Visible = false;
                }

                if (selectedSite.SiteId > -1)
                {
                    if (tabLDAP.Visible)
                    {
                        if (divUseLdap.Visible)
                        {
                            selectedSite.UseLdapAuth = chkUseLdapAuth.Checked;
                        }
                        if (divLdapServer.Visible)
                        {
                            selectedSite.SiteLdapSettings.Server = txtLdapServer.Text;
                        }
                        if ((divLdapPort.Visible)&&(txtLdapPort.Text.Length > 0))
                        {
                            int port = 389;
                            int.TryParse(txtLdapPort.Text, out port);
                            selectedSite.SiteLdapSettings.Port = port;
                        }

                        if (divLdapDomain.Visible)
                        {
                            selectedSite.SiteLdapSettings.Domain = txtLdapDomain.Text;
                        }

                        if (divLdapRootDn.Visible)
                        {
                            selectedSite.SiteLdapSettings.RootDN = txtLdapRootDN.Text;
                        }
                        if (divLdapUserDNKey.Visible)
                        {
                            selectedSite.SiteLdapSettings.UserDNKey = ddLdapUserDNKey.SelectedValue;
                        }
                    }
                }

                if (selectedSite.UseLdapAuth && !selectedSite.AllowDbFallbackWithLdap)
                {
                    selectedSite.ReallyDeleteUsers = false;
                }
                else
                {
                    selectedSite.ReallyDeleteUsers = chkReallyDeleteUsers.Checked;
                }

                if (
                (WebConfigSettings.UseRelatedSiteMode)
                && ((selectedSite.SiteId != WebConfigSettings.RelatedSiteID) && (selectedSiteID != -1))
                )
                {
                    //don't change this on child sites in related sites mode
                }
                else
                {
                    if (
                    (allowPasswordFormatChange)
                    || (selectedSite.SiteGuid == Guid.Empty) // new site
                    )
                    {
                        try
                        {
                            selectedSite.PasswordFormat = int.Parse(ddPasswordFormat.SelectedValue);
                        }
                        catch (ArgumentException) { }
                        catch (FormatException) { }
                    }

                    selectedSite.AllowPasswordRetrieval = chkAllowPasswordRetrieval.Checked;
                    selectedSite.RequiresQuestionAndAnswer = chkRequiresQuestionAndAnswer.Checked;
                    selectedSite.AllowPasswordReset = chkAllowPasswordReset.Checked;
                    selectedSite.RequirePasswordChangeOnResetRecover = chkRequirePasswordChangeAfterRecovery.Checked;

                    int MaxInvalidPasswordAttempts = selectedSite.MaxInvalidPasswordAttempts;
                    int.TryParse(txtMaxInvalidPasswordAttempts.Text, out MaxInvalidPasswordAttempts);
                    selectedSite.MaxInvalidPasswordAttempts = MaxInvalidPasswordAttempts;

                    int PasswordAttemptWindowMinutes = selectedSite.PasswordAttemptWindowMinutes;
                    int.TryParse(txtPasswordAttemptWindowMinutes.Text, out PasswordAttemptWindowMinutes);
                    selectedSite.PasswordAttemptWindowMinutes = PasswordAttemptWindowMinutes;

                    int MinRequiredPasswordLength = selectedSite.MinRequiredPasswordLength;
                    int.TryParse(txtMinimumPasswordLength.Text, out MinRequiredPasswordLength);
                    selectedSite.MinRequiredPasswordLength = MinRequiredPasswordLength;

                    int MinRequiredNonAlphanumericCharacters = selectedSite.MinRequiredNonAlphanumericCharacters;
                    int.TryParse(txtMinRequiredNonAlphaNumericCharacters.Text, out MinRequiredNonAlphanumericCharacters);
                    selectedSite.MinRequiredNonAlphanumericCharacters = MinRequiredNonAlphanumericCharacters;

                    selectedSite.PasswordStrengthRegularExpression = txtPasswordStrengthRegularExpression.Text.Trim();
                    selectedSite.PasswordRegexWarning = txtPasswordStrengthErrorMessage.Text.Trim();
                    selectedSite.ShowPasswordStrengthOnRegistration = chkShowPasswordStrength.Checked;
                    selectedSite.RequireCaptchaOnRegistration = chkRequireCaptcha.Checked;
                    selectedSite.RequireCaptchaOnLogin = chkRequireCaptchaOnLogin.Checked;
                    selectedSite.RequireEnterEmailTwiceOnRegistration = chkRequireEmailTwice.Checked;
                }

                //if (IsServerAdmin
                //&& (WebConfigSettings.UseRelatedSiteMode)
                //&& (selectedSite.SiteId != WebConfigSettings.RelatedSiteID)
                //&& (chkListEditRoles.Items.Count > 0)
                //)
                //{
                //    selectedSite.SiteRootEditRoles = chkListEditRoles.Items.SelectedItemsToSemiColonSeparatedString();
                //}

            } //end isAdmin

            selectedSite.AllowUserEditorPreference = chkAllowUserEditorChoice.Checked;
            selectedSite.MetaProfile = txtMetaProfile.Text;
            selectedSite.DefaultEmailFromAddress = txtSiteEmailFromAddress.Text;
            selectedSite.DefaultFromEmailAlias = txtSiteEmailFromAlias.Text;
            selectedSite.EnableMyPageFeature = chkEnableMyPageFeature.Checked;

            SetMailSettings();

            // the site may previously have been using email for login
            //but we need to make sure it uses loging name in case usinh ldap as fallback authentication
            if (selectedSite.UseLdapAuth) { selectedSite.UseEmailForLogin = false; }

            if (creatingNewSite)
            {
                selectedSite.SiteCreated += new SiteCreatedEventHandler(siteSettings_SiteCreated);
            }

            selectedSite.Save();

            if (creatingNewSite)
            {
                mojoSetup.CreateNewSiteData(selectedSite);
            }
            CacheHelper.ClearSiteSettingsCache(selectedSite.SiteId);

            mojoMembershipProvider mojoMembership = (mojoMembershipProvider)Membership.Provider;

            if (
                (!creatingNewSite)
                && (previousPasswordFormat != selectedSite.PasswordFormat)
                )
            {
                // this is not something you want to change very often
                mojoMembership.ChangeUserPasswordFormat(selectedSite, previousPasswordFormat);
                CacheHelper.ClearSiteSettingsCache(selectedSite.SiteId);

            }

            //String oldSkin = ViewState["skin"].ToString();
            string oldSkin = hdnCurrentSkin.Value;
            if ((oldSkin != selectedSite.Skin)&&(WebConfigSettings.UseCacheDependencyFiles))
            {
                CacheHelper.ResetThemeCache();
            }

            //if ((WebConfigSettings.UseRelatedSiteMode)&&(selectedSite.SiteId == WebConfigSettings.RelatedSiteID))
            if (WebConfigSettings.UseRelatedSiteMode)
            {
                // need to propagate any security changes to all child sites
                // reset the sitesettings cache for each site
                if (creatingNewSite)
                {
                    SiteSettings masterSite = CacheHelper.GetSiteSettings(WebConfigSettings.RelatedSiteID);
                    // siteSettings is the master site we need some permissions from it synced to the new site
                    SiteSettings.SyncRelatedSites(masterSite, WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites);
                }
                else
                {
                    SiteSettings.SyncRelatedSites(selectedSite, WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites);
                }

                // reset the sitesettings cache for each site
                CacheHelper.ClearRelatedSiteCache(-1);

            }

            String redirectUrl = SiteRoot
                + "/Admin/SiteSettings.aspx?SiteID=" + selectedSite.SiteId.ToString();

            if (selectedSite.SiteId == currentSiteID)
            {
                redirectUrl = Request.RawUrl;
            }

            WebUtils.SetupRedirect(this, redirectUrl);
        }
Example #10
0
        private static LdapUser ActiveDirectoryLogin(LdapSettings ldapSettings, string uid, string password)
        {
            bool           success = false;
            LdapUser       user    = null;
            DirectoryEntry adentry = null;

            //Note: Not necessary to check SSL. Default authentication type for .NET 2.0+ is "Secure"
            try
            {
                if (UseRootDNWithActiveDirectory())
                {
                    adentry = new DirectoryEntry("LDAP://" + ldapSettings.Server + "/" + ldapSettings.RootDN, ldapSettings.Domain + "\\" + uid, password);
                }
                else
                {
                    adentry = new DirectoryEntry("LDAP://" + ldapSettings.Server, ldapSettings.Domain + "\\" + uid, password);
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (log.IsErrorEnabled)
                {
                    //log.Error("couldn't connect to ldap server ", ex);
                    string msg = "Login failure for user: "******". Exception: ";
                    log.Error(msg, ex);
                }
            }
            if (adentry != null)
            {
                //Bind to the native AdsObject to force authentication.
                try
                {
                    object testobj = adentry.NativeObject;
                    success = true;
                }
                catch (System.Runtime.InteropServices.COMException ex)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("login failure", ex);
                    }
                    success = false;
                }
                if (success && adentry != null)
                {
                    if (UseRootDNWithActiveDirectory())
                    {
                        DirectorySearcher ds = new DirectorySearcher(adentry);
                        ds.Filter = "(&(sAMAccountName=" + uid + "))";
                        SearchResult result = ds.FindOne();
                        if (result != null)
                        {
                            //log.Error("successful authentication to ldap server in OU with Server: " + ldapSettings.Server + "; RootDN: " + ldapSettings.RootDN + "; UID=" + uid);
                            user = new LdapUser(adentry, uid, ldapSettings);
                        }
                        else
                        {
                            log.Info("failed authentication to ldap server in OU with Server: " + ldapSettings.Server + "; RootDN: " + ldapSettings.RootDN + "; UID=" + uid);
                            //potentially look in the security group
                        }
                    }
                    else
                    {
                        user = new LdapUser(adentry, uid, ldapSettings);
                    }
                }
            }


            return(user);
        }