/// <summary> /// Разбирает зашифрованную часть WebDav тикета. использует сивол разделителя для определения части session и absPath /// Разбор ведется на бинарном уровне. /// </summary> private static void ParseAbsPathTicket(string ticket, out Guid sessionId, out WebDavAbsolutePath absPath) { sessionId = Guid.Empty; absPath = null; byte[] ticketArr = DecryptToken(ticket); byte[] absPathArr = new byte[ticketArr.Length]; int offset; sessionId = GetSessionIdFromTicketArray(ticketArr, out offset); Array.Copy(ticketArr, offset, absPathArr, 0, ticketArr.Length - offset); absPath = WebDavAbsolutePath.Parse(absPathArr); }
/// <summary> /// Parses the specified STR. /// </summary> /// <param name="str">The STR.</param> /// <returns></returns> public static WebDavAbsolutePath Parse(string str) { WebDavAbsolutePath retVal = null; try { ObjectTypes storageType = ObjectTypes.UNDEFINED; string strStorageType = str.Substring(0, str.IndexOf(SEPARATOR)); if (!String.IsNullOrEmpty(strStorageType)) { storageType = (ObjectTypes)Convert.ToInt32(strStorageType); retVal = CreateInstance(storageType, str.Substring(strStorageType.Length + 1)); //retVal.Initialize(str.Substring(strStorageType.Length + 1)); } } catch (System.Exception) { } return(retVal); }
/// <summary> /// Parses the specified byte arr. /// </summary> /// <param name="byteArr">The byte arr.</param> /// <returns></returns> public static WebDavAbsolutePath Parse(byte[] byteArr) { WebDavAbsolutePath retVal = null; try { ObjectTypes storageType = ObjectTypes.UNDEFINED; storageType = (ObjectTypes)byteArr[0]; //remove self info byte[] arr = new byte[byteArr.Length - 1]; if (arr.Length > 1) { Array.Copy(byteArr, 1, arr, 0, arr.Length); retVal = CreateInstance(storageType, arr); } } catch (System.Exception) { } return(retVal); }
internal static string GetWebDavUrl(WebDavAbsolutePath absPath, bool withAuthToken, bool detectServerEdit, Uri baseUrl) { if (absPath == null) { throw new ArgumentNullException("absPath"); } if (baseUrl == null) { throw new ArgumentNullException("baseUrl"); } Guid? authToken = null; bool? bWebDavTurnOn = PortalConfig.UseWebDav; string applicationPath = baseUrl.AbsolutePath; if (HttpContext.Current != null) { //try get cached token authToken = (Guid?)HttpContext.Current.Items[AUTH_TOKEN_CACHE_NAME]; applicationPath = HttpContext.Current.Request.ApplicationPath; applicationPath = applicationPath.TrimEnd('/'); } ePluginToken pluginToken = ePluginToken.files; //Determine server editing if (detectServerEdit) { if (bWebDavTurnOn.HasValue && bWebDavTurnOn.Value && ContentTypeResolver.IsWebDAVSupportedExtension(Path.GetExtension(absPath.FileName))) { pluginToken = ePluginToken.webdav; } } //Формировать authToken only for webdav resources if (pluginToken == ePluginToken.webdav) { //Использовать из кеша если нет то сгенерировать новый if (authToken == null) { //authToken = withAuthToken ? WebDavAuthHelper.MakeAuthSession(true, absPath.StorageType, absPath.UniqueId) : Guid.Empty; authToken = withAuthToken ? WebDavAuthHelper.MakeAuthSession(true, ObjectTypes.File_FileStorage, 0) : Guid.Empty; if (HttpContext.Current != null && authToken != Guid.Empty) { //add to cache auth token HttpContext.Current.Items[AUTH_TOKEN_CACHE_NAME] = authToken; } } } else if (pluginToken == ePluginToken.files) { //never add auth token to file plugin token resources authToken = Guid.Empty; } WebDavTicket ticket = WebDavTicket.CreateInstance(pluginToken, authToken.Value, absPath); UriBuilder uriBuilder = new UriBuilder(); uriBuilder.Scheme = baseUrl.Scheme; uriBuilder.Port = baseUrl.Port; uriBuilder.Host = baseUrl.Host; uriBuilder.Path = applicationPath + ticket.ToString(); //Outer url to redirect page only for webdav access type if (ticket.PluginToken == ePluginToken.webdav && !withAuthToken) { uriBuilder.Path = applicationPath + AUTH_REDIRECT_PAGE; string webDavTicket = ticket.ToString("A"); //Remove file name from ticket uriBuilder.Query = AUTH_TICKET_PARAM_NAME + String.Format("={0}", webDavTicket); } ////FileName = System.Web.HttpUtility.UrlPathEncode(FileName); return Uri.EscapeUriString(uriBuilder.Uri.ToString()); }
internal static string GetWebDavUrl(WebDavAbsolutePath absPath, bool withAuthToken, bool detectServerEdit) { return GetWebDavUrl(absPath, withAuthToken, true, HttpContext.Current.Request.Url); }
internal static string GetWebDavUrl(WebDavAbsolutePath absPath, bool withAuthToken) { return GetWebDavUrl(absPath, withAuthToken, true); }
/// <summary> /// Creates the instance. /// </summary> /// <param name="handler">The handler.</param> /// <param name="elementStorageType">Type of the element storage.</param> /// <param name="elmentId">The elment id.</param> /// <param name="sessionId">The session id.</param> /// <param name="fileName">Name of the file.</param> /// <returns></returns> //public static WebDavTicket CreateInstance(ePluginToken handler, ObjectTypes elementStorageType, // int elmentId, Guid sessionId, string fileName) //{ // return new WebDavTicket(handler, elementStorageType, elmentId, sessionId, fileName); //} public static WebDavTicket CreateInstance(ePluginToken handler, Guid sessionId, WebDavAbsolutePath absPath) { return(new WebDavTicket(handler, sessionId, absPath)); }
private WebDavTicket(ePluginToken handler, Guid sessionId, WebDavAbsolutePath absPath) { _handlerType = handler; _sessionId = sessionId; _absPath = absPath; }