static public void Attach(IIdentity user, string applicationName, IUserManager userManager, bool cacheRoles) { Debug.Assert(user.IsAuthenticated); IPrincipal customPrincipal = new CustomPrincipal(user, applicationName, userManager, cacheRoles); AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal); //Make sure all future threads in this app domain use this principal //but because default principal cannot be set twice: if (m_ThreadPolicySet == false) { currentDomain.SetThreadPrincipal(customPrincipal); m_ThreadPolicySet = true; } }
protected virtual void OnLogin(object sender, EventArgs e) { string userName = m_UserNameBox.Text; string password = m_PasswordBox.Text; if (userName == String.Empty) { m_ErrorProvider.SetError(m_UserNameBox, "Please Enter User Name"); return; } else { m_ErrorProvider.SetError(m_UserNameBox, String.Empty); } if (password == String.Empty) { m_ErrorProvider.SetError(m_PasswordBox, "Please Enter Password"); return; } else { m_ErrorProvider.SetError(m_PasswordBox, String.Empty); } string applicationName = GetAppName(); IUserManager userManager = GetUserManager(); bool authenticated = userManager.Authenticate(applicationName, userName, password); if (authenticated) { IIdentity identity = new GenericIdentity(userName); CustomPrincipal.Attach(identity, applicationName, userManager, CacheRoles); } LoginEventArgs loginEventArgs = new LoginEventArgs(authenticated); EventsHelper.Fire(LoginEvent, this, loginEventArgs); }