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;
        }
예제 #2
0
        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);
        }