webdav portal auth via ad

This commit is contained in:
vfedosevich 2015-01-13 04:18:56 -08:00
parent 05d9fddb5d
commit 7dd090820b
56 changed files with 927 additions and 281 deletions

View file

@ -0,0 +1,17 @@
using System.Configuration;
using WebsitePanel.WebDavPortal.WebConfigSections;
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public abstract class AbstractConfigCollection
{
protected WebDavExplorerConfigurationSettingsSection ConfigSection;
protected AbstractConfigCollection()
{
ConfigSection =
(WebDavExplorerConfigurationSettingsSection)
ConfigurationManager.GetSection(WebDavExplorerConfigurationSettingsSection.SectionName);
}
}
}

View file

@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Linq;
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public class ElementsRendering : AbstractConfigCollection
{
public int DefaultCount { get; private set; }
public int AddElementsCount { get; private set; }
public List<string> ElementsToIgnore { get; private set; }
public ElementsRendering()
{
DefaultCount = ConfigSection.ElementsRendering.DefaultCount;
AddElementsCount = ConfigSection.ElementsRendering.AddElementsCount;
ElementsToIgnore = ConfigSection.ElementsRendering.ElementsToIgnore.Split(',').ToList();
}
}
}

View file

@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using WebsitePanel.WebDav.Core.Config.WebConfigSections;
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public class FileIconsDictionary : AbstractConfigCollection, IReadOnlyDictionary<string, string>
{
private readonly IDictionary<string, string> _fileIcons;
public FileIconsDictionary()
{
DefaultPath = ConfigSection.FileIcons.DefaultPath;
_fileIcons = ConfigSection.FileIcons.Cast<FileIconsElement>().ToDictionary(x => x.Extension, y => y.Path);
}
public string DefaultPath { get; private set; }
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
return _fileIcons.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public int Count
{
get { return _fileIcons.Count; }
}
public bool ContainsKey(string extension)
{
return _fileIcons.ContainsKey(extension);
}
public bool TryGetValue(string extension, out string path)
{
return _fileIcons.TryGetValue(extension, out path);
}
public string this[string extension]
{
get { return ContainsKey(extension) ? _fileIcons[extension] : DefaultPath; }
}
public IEnumerable<string> Keys
{
get { return _fileIcons.Keys; }
}
public IEnumerable<string> Values
{
get { return _fileIcons.Values; }
}
}
}

View file

@ -0,0 +1,21 @@
using System.Globalization;
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public class HttpErrorsCollection
{
public string this[int statusCode]
{
get
{
var message = Resources.HttpErrors.ResourceManager.GetString("_" + statusCode.ToString(CultureInfo.InvariantCulture));
return message ?? Default;
}
}
public string Default
{
get { return Resources.HttpErrors.Default; }
}
}
}

View file

@ -0,0 +1,42 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using WebsitePanel.WebDavPortal.WebConfigSections;
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public class OfficeOnlineCollection : AbstractConfigCollection, IReadOnlyCollection<string>
{
private readonly IList<string> _officeExtensions;
public OfficeOnlineCollection()
{
IsEnabled = ConfigSection.OfficeOnline.IsEnabled;
Url = ConfigSection.OfficeOnline.Url;
_officeExtensions = ConfigSection.OfficeOnline.Cast<OfficeOnlineElement>().Select(x => x.Extension).ToList();
}
public bool IsEnabled { get; private set; }
public string Url { get; private set; }
public IEnumerator<string> GetEnumerator()
{
return _officeExtensions.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public int Count
{
get { return _officeExtensions.Count; }
}
public bool Contains(string extension)
{
return _officeExtensions.Contains(extension);
}
}
}

View file

@ -0,0 +1,54 @@
using System.Collections.Generic;
using System.Linq;
using WebsitePanel.WebDavPortal.WebConfigSections;
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public class SessionKeysCollection : AbstractConfigCollection
{
private readonly IEnumerable<SessionKeysElement> _sessionKeys;
public SessionKeysCollection()
{
_sessionKeys = ConfigSection.SessionKeys.Cast<SessionKeysElement>();
}
public string AuthTicket
{
get
{
SessionKeysElement sessionKey =
_sessionKeys.FirstOrDefault(x => x.Key == SessionKeysElement.AuthTicketKey);
return sessionKey != null ? sessionKey.Value : null;
}
}
public string WebDavManager
{
get
{
SessionKeysElement sessionKey =
_sessionKeys.FirstOrDefault(x => x.Key == SessionKeysElement.WebDavManagerKey);
return sessionKey != null ? sessionKey.Value : null;
}
}
public string ResourseRenderCount
{
get
{
SessionKeysElement sessionKey = _sessionKeys.FirstOrDefault(x => x.Key == SessionKeysElement.ResourseRenderCountKey);
return sessionKey != null ? sessionKey.Value : null;
}
}
public string ItemId
{
get
{
SessionKeysElement sessionKey = _sessionKeys.FirstOrDefault(x => x.Key == SessionKeysElement.ItemIdSessionKey);
return sessionKey != null ? sessionKey.Value : null;
}
}
}
}

View file

@ -0,0 +1,14 @@
namespace WebsitePanel.WebDav.Core.Config.Entities
{
public class WebsitePanelConstantUserParameters : AbstractConfigCollection
{
public string Login { get; private set; }
public string Password { get; private set; }
public WebsitePanelConstantUserParameters()
{
Login = ConfigSection.WebsitePanelConstantUser.Login;
Password = ConfigSection.WebsitePanelConstantUser.Password;
}
}
}

View file

@ -0,0 +1,16 @@
using WebsitePanel.WebDav.Core.Config.Entities;
namespace WebsitePanel.WebDav.Core.Config
{
public interface IWebDavAppConfig
{
string UserDomain { get; }
string ApplicationName { get; }
ElementsRendering ElementsRendering { get; }
WebsitePanelConstantUserParameters WebsitePanelConstantUserParameters { get; }
SessionKeysCollection SessionKeys { get; }
FileIconsDictionary FileIcons { get; }
HttpErrorsCollection HttpErrors { get; }
OfficeOnlineCollection OfficeOnline { get; }
}
}

View file

@ -0,0 +1,16 @@
using System.Configuration;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
public class ApplicationNameElement : ConfigurationElement
{
private const string ValueKey = "value";
[ConfigurationProperty(ValueKey, IsKey = true, IsRequired = true)]
public string Value
{
get { return (string)this[ValueKey]; }
set { this[ValueKey] = value; }
}
}
}

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
public class AuthTimeoutCookieNameElement : ConfigurationElement
{
private const string ValueKey = "value";
[ConfigurationProperty(ValueKey, IsKey = true, IsRequired = true)]
public string Value
{
get { return (string)this[ValueKey]; }
set { this[ValueKey] = value; }
}
}
}

View file

@ -0,0 +1,32 @@
using System.Configuration;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
public class ElementsRenderingElement : ConfigurationElement
{
private const string DefaultCountKey = "defaultCount";
private const string AddElementsCountKey = "addElementsCount";
private const string ElementsToIgnoreKey = "elementsToIgnoreKey";
[ConfigurationProperty(DefaultCountKey, IsKey = true, IsRequired = true, DefaultValue = 30)]
public int DefaultCount
{
get { return (int)this[DefaultCountKey]; }
set { this[DefaultCountKey] = value; }
}
[ConfigurationProperty(AddElementsCountKey, IsKey = true, IsRequired = true, DefaultValue = 20)]
public int AddElementsCount
{
get { return (int)this[AddElementsCountKey]; }
set { this[AddElementsCountKey] = value; }
}
[ConfigurationProperty(ElementsToIgnoreKey, IsKey = true, IsRequired = true, DefaultValue = "")]
public string ElementsToIgnore
{
get { return (string)this[ElementsToIgnoreKey]; }
set { this[ElementsToIgnoreKey] = value; }
}
}
}

View file

@ -0,0 +1,24 @@
using System.Configuration;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
public class FileIconsElement : ConfigurationElement
{
private const string ExtensionKey = "extension";
private const string PathKey = "path";
[ConfigurationProperty(ExtensionKey, IsKey = true, IsRequired = true)]
public string Extension
{
get { return (string) this[ExtensionKey]; }
set { this[ExtensionKey] = value; }
}
[ConfigurationProperty(PathKey, IsKey = true, IsRequired = true)]
public string Path
{
get { return (string) this[PathKey]; }
set { this[PathKey] = value; }
}
}
}

View file

@ -0,0 +1,27 @@
using System.Configuration;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
[ConfigurationCollection(typeof (FileIconsElement))]
public class FileIconsElementCollection : ConfigurationElementCollection
{
private const string DefaultPathKey = "defaultPath";
[ConfigurationProperty(DefaultPathKey, IsRequired = false, DefaultValue = "/")]
public string DefaultPath
{
get { return (string) this[DefaultPathKey]; }
set { this[DefaultPathKey] = value; }
}
protected override ConfigurationElement CreateNewElement()
{
return new FileIconsElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((FileIconsElement) element).Extension;
}
}
}

View file

@ -0,0 +1,16 @@
using System.Configuration;
namespace WebsitePanel.WebDavPortal.WebConfigSections
{
public class OfficeOnlineElement : ConfigurationElement
{
private const string ExtensionKey = "extension";
[ConfigurationProperty(ExtensionKey, IsKey = true, IsRequired = true)]
public string Extension
{
get { return this[ExtensionKey].ToString(); }
set { this[ExtensionKey] = value; }
}
}
}

View file

@ -0,0 +1,36 @@
using System;
using System.Configuration;
namespace WebsitePanel.WebDavPortal.WebConfigSections
{
[ConfigurationCollection(typeof(OfficeOnlineElement))]
public class OfficeOnlineElementCollection : ConfigurationElementCollection
{
private const string UrlKey = "url";
private const string IsEnabledKey = "isEnabled";
[ConfigurationProperty(UrlKey, IsKey = true, IsRequired = true)]
public string Url
{
get { return this[UrlKey].ToString(); }
set { this[UrlKey] = value; }
}
[ConfigurationProperty(IsEnabledKey, IsKey = true, IsRequired = true, DefaultValue = false)]
public bool IsEnabled
{
get { return Boolean.Parse(this[IsEnabledKey].ToString()); }
set { this[IsEnabledKey] = value; }
}
protected override ConfigurationElement CreateNewElement()
{
return new OfficeOnlineElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((OfficeOnlineElement)element).Extension;
}
}
}

View file

@ -0,0 +1,30 @@
using System.Configuration;
namespace WebsitePanel.WebDavPortal.WebConfigSections
{
public class SessionKeysElement : ConfigurationElement
{
private const string KeyKey = "key";
private const string ValueKey = "value";
public const string AccountInfoKey = "AccountInfoSessionKey";
public const string AuthTicketKey = "AuthTicketKey";
public const string WebDavManagerKey = "WebDavManagerSessionKey";
public const string ResourseRenderCountKey = "ResourseRenderCountSessionKey";
public const string ItemIdSessionKey = "ItemId";
[ConfigurationProperty(KeyKey, IsKey = true, IsRequired = true)]
public string Key
{
get { return (string) this[KeyKey]; }
set { this[KeyKey] = value; }
}
[ConfigurationProperty(ValueKey, IsKey = true, IsRequired = true)]
public string Value
{
get { return (string) this[ValueKey]; }
set { this[ValueKey] = value; }
}
}
}

View file

@ -0,0 +1,19 @@
using System.Configuration;
using WebsitePanel.WebDavPortal.WebConfigSections;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
[ConfigurationCollection(typeof (SessionKeysElement))]
public class SessionKeysElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new SessionKeysElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((SessionKeysElement) element).Key;
}
}
}

View file

@ -0,0 +1,16 @@
using System.Configuration;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
public class UserDomainElement : ConfigurationElement
{
private const string ValueKey = "value";
[ConfigurationProperty(ValueKey, IsKey = true, IsRequired = true)]
public string Value
{
get { return (string) this[ValueKey]; }
set { this[ValueKey] = value; }
}
}
}

View file

@ -0,0 +1,77 @@
using System.Configuration;
using WebsitePanel.WebDav.Core.Config.WebConfigSections;
namespace WebsitePanel.WebDavPortal.WebConfigSections
{
public class WebDavExplorerConfigurationSettingsSection : ConfigurationSection
{
private const string UserDomainKey = "userDomain";
private const string AuthTimeoutCookieNameKey = "authTimeoutCookieName";
private const string AppName = "applicationName";
private const string WebsitePanelConstantUserKey = "websitePanelConstantUser";
private const string ElementsRenderingKey = "elementsRendering";
private const string Rfc2898CryptographyKey = "rfc2898Cryptography";
private const string ConnectionStringsKey = "appConnectionStrings";
private const string SessionKeysKey = "sessionKeys";
private const string FileIconsKey = "fileIcons";
private const string OfficeOnlineKey = "officeOnline";
public const string SectionName = "webDavExplorerConfigurationSettings";
[ConfigurationProperty(AuthTimeoutCookieNameKey, IsRequired = true)]
public AuthTimeoutCookieNameElement AuthTimeoutCookieName
{
get { return (AuthTimeoutCookieNameElement)this[AuthTimeoutCookieNameKey]; }
set { this[AuthTimeoutCookieNameKey] = value; }
}
[ConfigurationProperty(UserDomainKey, IsRequired = true)]
public UserDomainElement UserDomain
{
get { return (UserDomainElement) this[UserDomainKey]; }
set { this[UserDomainKey] = value; }
}
[ConfigurationProperty(AppName, IsRequired = true)]
public ApplicationNameElement ApplicationName
{
get { return (ApplicationNameElement)this[AppName]; }
set { this[AppName] = value; }
}
[ConfigurationProperty(WebsitePanelConstantUserKey, IsRequired = true)]
public WebsitePanelConstantUserElement WebsitePanelConstantUser
{
get { return (WebsitePanelConstantUserElement)this[WebsitePanelConstantUserKey]; }
set { this[WebsitePanelConstantUserKey] = value; }
}
[ConfigurationProperty(ElementsRenderingKey, IsRequired = true)]
public ElementsRenderingElement ElementsRendering
{
get { return (ElementsRenderingElement)this[ElementsRenderingKey]; }
set { this[ElementsRenderingKey] = value; }
}
[ConfigurationProperty(SessionKeysKey, IsDefaultCollection = false)]
public SessionKeysElementCollection SessionKeys
{
get { return (SessionKeysElementCollection) this[SessionKeysKey]; }
set { this[SessionKeysKey] = value; }
}
[ConfigurationProperty(FileIconsKey, IsDefaultCollection = false)]
public FileIconsElementCollection FileIcons
{
get { return (FileIconsElementCollection) this[FileIconsKey]; }
set { this[FileIconsKey] = value; }
}
[ConfigurationProperty(OfficeOnlineKey, IsDefaultCollection = false)]
public OfficeOnlineElementCollection OfficeOnline
{
get { return (OfficeOnlineElementCollection)this[OfficeOnlineKey]; }
set { this[OfficeOnlineKey] = value; }
}
}
}

View file

@ -0,0 +1,24 @@
using System.Configuration;
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
{
public class WebsitePanelConstantUserElement : ConfigurationElement
{
private const string LoginKey = "login";
private const string PasswordKey = "password";
[ConfigurationProperty(LoginKey, IsKey = true, IsRequired = true)]
public string Login
{
get { return this[LoginKey].ToString(); }
set { this[LoginKey] = value; }
}
[ConfigurationProperty(PasswordKey, IsKey = true, IsRequired = true)]
public string Password
{
get { return this[PasswordKey].ToString(); }
set { this[PasswordKey] = value; }
}
}
}

View file

@ -0,0 +1,50 @@
using System.Configuration;
using WebsitePanel.WebDav.Core.Config.Entities;
using WebsitePanel.WebDavPortal.WebConfigSections;
namespace WebsitePanel.WebDav.Core.Config
{
public class WebDavAppConfigManager : IWebDavAppConfig
{
private static WebDavAppConfigManager _instance;
private readonly WebDavExplorerConfigurationSettingsSection _configSection;
private WebDavAppConfigManager()
{
_configSection = ((WebDavExplorerConfigurationSettingsSection) ConfigurationManager.GetSection(WebDavExplorerConfigurationSettingsSection.SectionName));
WebsitePanelConstantUserParameters = new WebsitePanelConstantUserParameters();
ElementsRendering = new ElementsRendering();
SessionKeys = new SessionKeysCollection();
FileIcons = new FileIconsDictionary();
HttpErrors = new HttpErrorsCollection();
OfficeOnline = new OfficeOnlineCollection();
}
public static WebDavAppConfigManager Instance
{
get { return _instance ?? (_instance = new WebDavAppConfigManager()); }
}
public string UserDomain
{
get { return _configSection.UserDomain.Value; }
}
public string ApplicationName
{
get { return _configSection.ApplicationName.Value; }
}
public string AuthTimeoutCookieName
{
get { return _configSection.AuthTimeoutCookieName.Value; }
}
public ElementsRendering ElementsRendering { get; private set; }
public WebsitePanelConstantUserParameters WebsitePanelConstantUserParameters { get; private set; }
public SessionKeysCollection SessionKeys { get; private set; }
public FileIconsDictionary FileIcons { get; private set; }
public HttpErrorsCollection HttpErrors { get; private set; }
public OfficeOnlineCollection OfficeOnline { get; private set; }
}
}