webdav protal office 365 fix

This commit is contained in:
vfedosevich 2015-01-15 04:03:02 -08:00
parent 92befdea38
commit f2c54df2b0
27 changed files with 466 additions and 80 deletions

View file

@ -1,5 +1,6 @@
using System;
using System.DirectoryServices.AccountManagement;
using System.Threading;
using System.Web;
using System.Web.Script.Serialization;
using System.Web.Security;
@ -29,8 +30,10 @@ namespace WebsitePanel.WebDav.Core.Security.Authentication
return null;
}
var principal = new WspPrincipal(login);
//var user = UserPrincipal.FindByIdentity(_principalContext, IdentityType.UserPrincipalName, login);
var principal = new WspPrincipal(login);
var exchangeAccount = WSP.Services.ExchangeServer.GetAccountByAccountNameWithoutItemId(login);
var organization = WSP.Services.Organizations.GetOrganization(exchangeAccount.ItemId);
@ -40,13 +43,34 @@ namespace WebsitePanel.WebDav.Core.Security.Authentication
principal.DisplayName = exchangeAccount.DisplayName;
principal.EncryptedPassword = _cryptography.Encrypt(password);
CreateAuthenticationTicket(principal);
if (HttpContext.Current != null)
{
HttpContext.Current.User = principal;
}
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;
return principal;
}
public WspPrincipal LogIn(string accessToken)
{
var token = _cryptography.Decrypt(accessToken.Replace("AAAAA", "/"));
var splitResult = token.Split(':');
var login = splitResult[0];
var password = _cryptography.Decrypt(splitResult[1]);
var expiration = DateTime.Parse(splitResult[2]);
if (expiration < DateTime.Today)
{
return null;
}
return LogIn(login, password);
}
public void CreateAuthenticationTicket(WspPrincipal principal)
{
var serializer = new JavaScriptSerializer();
@ -67,6 +91,13 @@ namespace WebsitePanel.WebDav.Core.Security.Authentication
HttpContext.Current.Response.Cookies.Add(cookie);
}
public string CreateAccessToken(WspPrincipal principal)
{
var token = string.Format("{0}:{1}:{2}", principal.Login, principal.EncryptedPassword, DateTime.Now.ToShortDateString());
return _cryptography.Encrypt(token).Replace("/", "AAAAA");
}
public void LogOut()
{
FormsAuthentication.SignOut();

View file

@ -28,8 +28,8 @@ namespace WebsitePanel.WebDav.Core.Security.Authentication.Principals
public IIdentity Identity { get; private set; }
public WspPrincipal(string username)
{
Identity = new GenericIdentity(username);
{
Identity = new GenericIdentity(username);//new WindowsIdentity(username, "WindowsAuthentication");
Login = username;
}