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

@ -3,8 +3,8 @@ using System.Net;
using System.Web.Mvc;
using System.Web.Routing;
using WebsitePanel.WebDav.Core.Config;
using WebsitePanel.WebDav.Core.Security.Authentication;
using WebsitePanel.WebDav.Core.Security.Cryptography;
using WebsitePanel.WebDavPortal.Exceptions;
using WebsitePanel.WebDavPortal.Models;
using WebsitePanel.WebDavPortal.UI.Routes;
using WebsitePanel.WebDav.Core.Interfaces.Security;
@ -39,11 +39,13 @@ namespace WebsitePanel.WebDavPortal.Controllers
public ActionResult Login(AccountModel model)
{
var user = _authenticationService.LogIn(model.Login, model.Password);
ViewBag.LdapIsAuthentication = user.Identity.IsAuthenticated;
if (user.Identity.IsAuthenticated)
{
_authenticationService.CreateAuthenticationTicket(user);
Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = null;
return RedirectToRoute(FileSystemRouteNames.FilePath, new { org = WspContext.User.OrganizationId });

View file

@ -1,17 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mime;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using WebsitePanel.WebDav.Core;
using WebsitePanel.WebDav.Core.Client;
using WebsitePanel.WebDav.Core.Config;
using WebsitePanel.WebDav.Core.Exceptions;
using WebsitePanel.WebDav.Core.Interfaces.Managers;
using WebsitePanel.WebDav.Core.Interfaces.Security;
using WebsitePanel.WebDav.Core.Security.Cryptography;
using WebsitePanel.WebDavPortal.CustomAttributes;
using WebsitePanel.WebDavPortal.Extensions;
using WebsitePanel.WebDavPortal.Models;
using System.Net;
using WebsitePanel.WebDavPortal.UI.Routes;
namespace WebsitePanel.WebDavPortal.Controllers
@ -20,11 +26,15 @@ namespace WebsitePanel.WebDavPortal.Controllers
[LdapAuthorization]
public class FileSystemController : Controller
{
private readonly ICryptography _cryptography;
private readonly IWebDavManager _webdavManager;
private readonly IAuthenticationService _authenticationService;
public FileSystemController(IWebDavManager webdavManager)
public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService)
{
_cryptography = cryptography;
_webdavManager = webdavManager;
_authenticationService = authenticationService;
}
[HttpGet]
@ -58,8 +68,14 @@ namespace WebsitePanel.WebDavPortal.Controllers
public ActionResult ShowOfficeDocument(string org, string pathPart = "")
{
var owaOpener = WebDavAppConfigManager.Instance.OfficeOnline.Single(x => x.Extension == Path.GetExtension(pathPart));
string fileUrl = _webdavManager.RootPath.TrimEnd('/') + "/" + pathPart.TrimStart('/');
var uri = new Uri(WebDavAppConfigManager.Instance.OfficeOnline.Url).AddParameter("src", fileUrl).ToString();
string accessToken = _authenticationService.CreateAccessToken(WspContext.User);
string wopiSrc = Server.UrlDecode(Url.RouteUrl(OwaRouteNames.CheckFileInfo, new { encodedPath = _webdavManager.CreateFileId(pathPart) }, 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));
return View(new OfficeOnlineModel(uri, new Uri(fileUrl).Segments.Last()));
}
@ -80,7 +96,7 @@ namespace WebsitePanel.WebDavPortal.Controllers
return PartialView("_ResourseCollectionPartial", result);
}
return new HttpStatusCodeResult(HttpStatusCode.NoContent); ;
return new HttpStatusCodeResult(HttpStatusCode.NoContent);
}
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebsitePanel.WebDav.Core.Interfaces.Managers;
using WebsitePanel.WebDav.Core.Interfaces.Owa;
using WebsitePanel.WebDav.Core.Interfaces.Security;
using WebsitePanel.WebDav.Core.Security.Cryptography;
namespace WebsitePanel.WebDavPortal.Controllers
{
[AllowAnonymous]
public class OwaController : Controller
{
private readonly IWopiServer _wopiServer;
private readonly IWebDavManager _webDavManager;
private readonly IAuthenticationService _authenticationService;
public OwaController(IWopiServer wopiServer, IWebDavManager webDavManager, IAuthenticationService authenticationService)
{
_wopiServer = wopiServer;
_webDavManager = webDavManager;
_authenticationService = authenticationService;
}
public JsonResult CheckFileInfo( string encodedPath)
{
var path = _webDavManager.FilePathFromId(encodedPath);
var fileInfo = _wopiServer.GetCheckFileInfo(path);
return Json(fileInfo, JsonRequestBehavior.AllowGet);
}
public FileResult GetFile(string encodedPath)
{
var path = _webDavManager.FilePathFromId(encodedPath);
return _wopiServer.GetFile(path);
}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
if (!string.IsNullOrEmpty(Request["access_token"]))
{
_authenticationService.LogIn(Request["access_token"]);
}
}
}
}