webdav portal login + access token fix

This commit is contained in:
vfedosevich 2015-01-16 03:56:59 -08:00
parent 1c3f10a30a
commit 213eaf0077
19 changed files with 1431 additions and 1181 deletions

View file

@ -29,12 +29,14 @@ namespace WebsitePanel.WebDavPortal.Controllers
private readonly ICryptography _cryptography;
private readonly IWebDavManager _webdavManager;
private readonly IAuthenticationService _authenticationService;
private readonly IAccessTokenManager _tokenManager;
public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService)
public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager)
{
_cryptography = cryptography;
_webdavManager = webdavManager;
_authenticationService = authenticationService;
_tokenManager = tokenManager;
}
[HttpGet]
@ -73,11 +75,11 @@ namespace WebsitePanel.WebDavPortal.Controllers
var owaOpener = WebDavAppConfigManager.Instance.OfficeOnline.Single(x => x.Extension == Path.GetExtension(pathPart));
string fileUrl = WebDavAppConfigManager.Instance.WebdavRoot+ org + "/" + pathPart.TrimStart('/');
string accessToken = _authenticationService.CreateAccessToken(WspContext.User);
var accessToken = _tokenManager.CreateToken(WspContext.User, pathPart);
string wopiSrc = Server.UrlDecode(Url.RouteUrl(OwaRouteNames.CheckFileInfo, new { encodedPath = _webdavManager.CreateFileId(pathPart) }, Request.Url.Scheme));
string wopiSrc = Server.UrlDecode(Url.RouteUrl(OwaRouteNames.CheckFileInfo, new { accessTokenId = accessToken.Id }, Request.Url.Scheme));
var uri = string.Format("{0}/{1}?WOPISrc={2}&access_token={3}", WebDavAppConfigManager.Instance.OfficeOnline.Url, owaOpener.OwaOpener, Server.UrlEncode(wopiSrc), Server.UrlEncode(accessToken));
var uri = string.Format("{0}/{1}?WOPISrc={2}&access_token={3}", WebDavAppConfigManager.Instance.OfficeOnline.Url, owaOpener.OwaOpener, Server.UrlEncode(wopiSrc), Server.UrlEncode(accessToken.AccessToken.ToString("N")));
return View(new OfficeOnlineModel(uri, new Uri(fileUrl).Segments.Last()));
}

View file

@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using WebsitePanel.EnterpriseServer.Base.HostedSolution;
using WebsitePanel.WebDav.Core.Interfaces.Managers;
using WebsitePanel.WebDav.Core.Interfaces.Owa;
using WebsitePanel.WebDav.Core.Interfaces.Security;
using WebsitePanel.WebDav.Core.Security.Cryptography;
using WebsitePanel.WebDav.Core.Wsp.Framework;
namespace WebsitePanel.WebDavPortal.Controllers
{
@ -16,28 +19,40 @@ namespace WebsitePanel.WebDavPortal.Controllers
private readonly IWopiServer _wopiServer;
private readonly IWebDavManager _webDavManager;
private readonly IAuthenticationService _authenticationService;
private readonly IAccessTokenManager _tokenManager;
private readonly ICryptography _cryptography;
private WebDavAccessToken _token;
public OwaController(IWopiServer wopiServer, IWebDavManager webDavManager, IAuthenticationService authenticationService)
public OwaController(IWopiServer wopiServer, IWebDavManager webDavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager, ICryptography cryptography)
{
_wopiServer = wopiServer;
_webDavManager = webDavManager;
_authenticationService = authenticationService;
_tokenManager = tokenManager;
_cryptography = cryptography;
}
public JsonResult CheckFileInfo( string encodedPath)
public ActionResult CheckFileInfo(int accessTokenId)
{
var path = _webDavManager.FilePathFromId(encodedPath);
if (!CheckAccess(accessTokenId))
{
return new HttpStatusCodeResult(HttpStatusCode.NoContent);
}
var fileInfo = _wopiServer.GetCheckFileInfo(path);
var fileInfo = _wopiServer.GetCheckFileInfo(_token.FilePath);
return Json(fileInfo, JsonRequestBehavior.AllowGet);
}
public FileResult GetFile(string encodedPath)
public ActionResult GetFile(int accessTokenId)
{
var path = _webDavManager.FilePathFromId(encodedPath);
if (!CheckAccess(accessTokenId))
{
return new HttpStatusCodeResult(HttpStatusCode.NoContent);
}
return _wopiServer.GetFile(path);
return _wopiServer.GetFile((_token.FilePath));
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
@ -46,8 +61,26 @@ namespace WebsitePanel.WebDavPortal.Controllers
if (!string.IsNullOrEmpty(Request["access_token"]))
{
_authenticationService.LogIn(Request["access_token"]);
var guid = Guid.Parse((Request["access_token"]));
_tokenManager.ClearExpiredTokens();
_token = _tokenManager.GetToken(guid);
var user = WSP.Services.ExchangeServer.GetAccount(_token.ItemId, _token.AccountId);
_authenticationService.LogIn(user.UserPrincipalName, _cryptography.Decrypt(_token.AuthData));
}
}
private bool CheckAccess(int accessTokenId)
{
if (_token == null || accessTokenId != _token.Id)
{
return false;
}
return true;
}
}
}