public bool Authenticate(string domain, string userName, string password, bool rememberMe) { using (var impersonation = new Impersonation(domain, userName, password)) { if (impersonation.Authenticated) { using (var wi = WindowsClaimsIdentity.GetCurrent()) { SecurityToken securityToken = GetSecurityTokenFromWindowsIdentity(wi, HttpContext.Current); SPSessionTokenWriteType writeCookie = SPSecurityTokenServiceManager.Local.UseSessionCookies && rememberMe ? SPSessionTokenWriteType.WriteDefaultCookie : SPSessionTokenWriteType.WriteSessionCookie; if (securityToken == null) { throw new ArgumentNullException("securityToken"); } SPSecurity.RunWithElevatedPrivileges( () => SetPrincipalAndWriteSessionToken(securityToken, writeCookie)); } return true; } } return false; }
public bool Authenticate(string domain, string userName, string password, bool rememberMe) { using (var impersonation = new Impersonation(domain, userName, password)) { if (impersonation.Authenticated) { using (var wi = WindowsClaimsIdentity.GetCurrent()) { SecurityToken securityToken = GetSecurityTokenFromWindowsIdentity(wi, HttpContext.Current); SPSessionTokenWriteType writeCookie = SPSecurityTokenServiceManager.Local.UseSessionCookies && rememberMe ? SPSessionTokenWriteType.WriteDefaultCookie : SPSessionTokenWriteType.WriteSessionCookie; if (securityToken == null) { throw new ArgumentNullException("securityToken"); } SPSecurity.RunWithElevatedPrivileges( () => SetPrincipalAndWriteSessionToken(securityToken, writeCookie)); } return(true); } } return(false); }