protected void Page_Init( Object sender, EventArgs e ) { if( Request.ServerVariables[ "LOGON_USER" ].Length > 0 ) { AuthenticationController objAuthentication = new AuthenticationController(); objAuthentication.AuthenticationLogon(); } }
public void OnAuthenticateRequest( object s, EventArgs e ) { PortalSettings portalSettings = Globals.GetPortalSettings(); Configuration config = Configuration.GetConfig(); if( config.WindowsAuthentication ) { HttpRequest Request = HttpContext.Current.Request; HttpResponse Response = HttpContext.Current.Response; bool blnWinLogon = Request.RawUrl.ToLower().IndexOf( ( Configuration.AUTHENTICATION_LOGON_PAGE ).ToLower() ) > - 1; bool blnWinLogoff = ( AuthenticationController.GetStatus( portalSettings.PortalId ) == AuthenticationStatus.WinLogon ) && ( Request.RawUrl.ToLower().IndexOf( ( Configuration.AUTHENTICATION_LOGOFF_PAGE ).ToLower() ) > - 1 ); if( AuthenticationController.GetStatus( portalSettings.PortalId ) == AuthenticationStatus.Undefined ) //OrElse (blnWinLogon) Then { AuthenticationController.SetStatus( portalSettings.PortalId, AuthenticationStatus.WinProcess ); string url; if( Request.ApplicationPath == "/" ) { url = "/Admin/Security/WindowsSignin.aspx?tabid=" + portalSettings.ActiveTab.TabID; } else { url = Request.ApplicationPath + "/Admin/Security/WindowsSignin.aspx?tabid=" + portalSettings.ActiveTab.TabID; } Response.Redirect( url ); } else if( ( AuthenticationController.GetStatus( portalSettings.PortalId ) != AuthenticationStatus.WinLogoff ) && blnWinLogoff ) { AuthenticationController objAuthentication = new AuthenticationController(); objAuthentication.AuthenticationLogoff(); } else if( ( AuthenticationController.GetStatus( portalSettings.PortalId ) == AuthenticationStatus.WinLogoff ) && blnWinLogon ) // has been logoff before { AuthenticationController.SetStatus( portalSettings.PortalId, AuthenticationStatus.Undefined ); Response.Redirect( Request.RawUrl ); } } }
protected void Page_Load(Object sender, EventArgs e) { //Put user code to initialize the page here try { // Obtain PortalSettings from Current Context AuthenticationController objAuthenticationController = new AuthenticationController(); // Reset config Configuration.ResetConfig(); Configuration config = Configuration.GetConfig(); if (UserInfo.Username.IndexOf("\\") > 0) { string strDomain = GetUserDomainName(UserInfo.Username); if (strDomain.ToLower() == Request.ServerVariables["SERVER_NAME"].ToLower()) { DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, string.Format(Localization.GetString("SameDomainError", this.LocalResourceFile), strDomain, HttpUtility.HtmlEncode(Request.ServerVariables["SERVER_NAME"])), ModuleMessageType.YellowWarning); DisableScreen(); return; } } if (! Page.IsPostBack) { ProviderConfiguration objProviderConfiguration = ProviderConfiguration.GetProviderConfiguration(Configuration.AUTHENTICATION_KEY); chkAuthentication.Checked = config.WindowsAuthentication; chkSynchronizeRole.Checked = config.SynchronizeRole; chkSynchronizePassword.Checked = config.SynchronizePassword; txtRootDomain.Text = config.RootDomain; txtUserName.Text = config.UserName; txtEmailDomain.Text = config.EmailDomain; // Bind Authentication provider list, this allows each portal could use different provider for authentication foreach (object _Provider in objProviderConfiguration.Providers) { DictionaryEntry objProvider = (DictionaryEntry) _Provider; string ProviderName = Convert.ToString(objProvider.Key); string ProviderType = ((Provider) objProvider.Value).Type; this.cboProviders.Items.Add(new ListItem(ProviderName, ProviderType)); } // Bind AuthenticationTypes list, on first configure, it could obtains only from default authentication provider try { this.cboAuthenticationType.DataSource = objAuthenticationController.AuthenticationTypes(); } catch (TypeInitializationException) { UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("AuthProviderError", this.LocalResourceFile), ModuleMessageType.YellowWarning); DisableScreen(); return; } this.cboAuthenticationType.DataBind(); this.cboAuthenticationType.Items.FindByText(config.AuthenticationType).Selected = true; } valConfirm.ErrorMessage = Localization.GetString("PasswordMatchFailure", this.LocalResourceFile); } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
protected void cmdAuthenticationUpdate_Click(Object sender, EventArgs e) { PortalSettings _portalSettings = (PortalSettings) HttpContext.Current.Items["PortalSettings"]; try { string providerTypeName = this.cboProviders.SelectedItem.Value; string authenticationType = this.cboAuthenticationType.SelectedItem.Value; Configuration.UpdateConfig(_portalSettings.PortalId, this.chkAuthentication.Checked, this.txtRootDomain.Text, this.txtEmailDomain.Text, this.txtUserName.Text, this.txtPassword.Text, this.chkSynchronizeRole.Checked, this.chkSynchronizePassword.Checked, providerTypeName, authenticationType); Configuration.ResetConfig(); AuthenticationController objAuthenticationController = new AuthenticationController(); string statusMessage = objAuthenticationController.NetworkStatus(); if (statusMessage.ToLower().IndexOf("fail") > - 1) { MessageCell.Controls.Add(UI.Skins.Skin.GetModuleMessageControl("", LocalizedStatus(statusMessage), ModuleMessageType.RedError)); } else { MessageCell.Controls.Add(UI.Skins.Skin.GetModuleMessageControl("", LocalizedStatus(statusMessage), ModuleMessageType.GreenSuccess)); } } catch (Exception exc) //Module failed to load { Exceptions.ProcessModuleLoadException(this, exc); } }
/// <summary> /// WindowsAuthorization checks whether the user credentials are valid /// Windows credentials /// </summary> /// <param name="loginStatus">The log in status</param> /// <history> /// [cnurse] 03/15/2006 /// </history> private UserInfo WindowsAuthorization( UserLoginStatus loginStatus ) { string strMessage = Null.NullString; UserInfo objUser = UserController.GetUserByName( PortalSettings.PortalId, txtUsername.Text, false ); AuthenticationController objAuthentication = new AuthenticationController(); DotNetNuke.Security.Authentication.UserInfo objAuthUser = objAuthentication.ProcessFormAuthentication(txtUsername.Text, txtPassword.Text); int _userID = - 1; if( ( objAuthUser != null ) && ( objUser == null ) ) { // Add this user into DNN database for better performance on next logon UserCreateStatus createStatus; DotNetNuke.Security.Authentication.UserController objAuthUsers = new DotNetNuke.Security.Authentication.UserController(); createStatus = objAuthUsers.AddDNNUser( objAuthUser ); _userID = objAuthUser.UserID; // Windows/DNN password validation should be same, check this status here strMessage = UserController.GetUserCreateStatus( createStatus ); } else if( ( objAuthUser != null ) && ( objUser != null ) ) { // User might has been imported by Admin or automatically added with random password // update DNN password to match with authenticated password from AD if( objUser.Membership.Password != txtPassword.Text ) { UserController.ChangePassword( objUser, objUser.Membership.Password, txtPassword.Text ); } _userID = objUser.UserID; } if( _userID > 0 ) { // Authenticated with DNN objUser = UserController.ValidateUser( PortalId, txtUsername.Text, txtPassword.Text, "", PortalSettings.PortalName, ipAddress, ref loginStatus ); if( loginStatus != UserLoginStatus.LOGIN_SUCCESS ) { strMessage = Localization.GetString( "LoginFailed", this.LocalResourceFile ); } } else { objUser = null; } AddLocalizedModuleMessage( strMessage, ModuleMessageType.RedError, !String.IsNullOrEmpty(strMessage) ); return objUser; }