From 1925288a860ccc3fcd7364432ac5057eccf044e0 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Tue, 26 Feb 2013 17:13:58 -0500 Subject: [PATCH 1/2] Extract ISecurityManager interface --- .../MediaBrowser.Common.csproj | 1 + .../Security/ISecurityManager.cs | 34 +++++++++++++++++++ .../Plugins/PluginSecurityManager.cs | 5 +-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 MediaBrowser.Common/Security/ISecurityManager.cs diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 709d6c0165..7f1f980eb1 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -136,6 +136,7 @@ + diff --git a/MediaBrowser.Common/Security/ISecurityManager.cs b/MediaBrowser.Common/Security/ISecurityManager.cs new file mode 100644 index 0000000000..bcda3c6b41 --- /dev/null +++ b/MediaBrowser.Common/Security/ISecurityManager.cs @@ -0,0 +1,34 @@ +using System.Threading.Tasks; +using Mediabrowser.Model.Entities; + +namespace MediaBrowser.Common.Security +{ + public interface ISecurityManager + { + /// + /// Gets a value indicating whether this instance is MB supporter. + /// + /// true if this instance is MB supporter; otherwise, false. + bool IsMBSupporter { get; } + + /// + /// Gets or sets the supporter key. + /// + /// The supporter key. + string SupporterKey { get; set; } + + /// + /// Gets or sets the legacy key. + /// + /// The legacy key. + string LegacyKey { get; set; } + + /// + /// Gets the registration status. + /// + /// The feature. + /// The MB2 equivalent. + /// Task{MBRegistrationRecord}. + Task GetRegistrationStatus(string feature, string mb2Equivalent = null); + } +} \ No newline at end of file diff --git a/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs b/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs index db3f20ee3f..3a097ba1ff 100644 --- a/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs +++ b/MediaBrowser.Controller/Plugins/PluginSecurityManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.Serialization; +using MediaBrowser.Common.Security; +using MediaBrowser.Model.Serialization; using Mediabrowser.Model.Entities; using Mediabrowser.PluginSecurity; using MediaBrowser.Common.Kernel; @@ -12,7 +13,7 @@ namespace MediaBrowser.Controller.Plugins /// /// Class PluginSecurityManager /// - public class PluginSecurityManager + public class PluginSecurityManager : ISecurityManager { /// /// The _is MB supporter From 4b2cf29fe1714e2bdef1d75d1b3aefb2f29ab4f6 Mon Sep 17 00:00:00 2001 From: Eric Reed Date: Tue, 26 Feb 2013 17:19:45 -0500 Subject: [PATCH 2/2] Move SecurityManager to BaseKernel/IKernel --- MediaBrowser.Api/PluginService.cs | 10 +++++----- MediaBrowser.Common/Kernel/BaseKernel.cs | 7 +++++++ MediaBrowser.Common/Kernel/IKernel.cs | 7 +++++++ MediaBrowser.Controller/Kernel.cs | 9 ++------- MediaBrowser.Controller/Updates/InstallationManager.cs | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.cs index ab20e18756..3d975090b3 100644 --- a/MediaBrowser.Api/PluginService.cs +++ b/MediaBrowser.Api/PluginService.cs @@ -203,9 +203,9 @@ namespace MediaBrowser.Api var result = new PluginSecurityInfo { - IsMBSupporter = kernel.PluginSecurityManager.IsMBSupporter, - SupporterKey = kernel.PluginSecurityManager.SupporterKey, - LegacyKey = kernel.PluginSecurityManager.LegacyKey + IsMBSupporter = kernel.SecurityManager.IsMBSupporter, + SupporterKey = kernel.SecurityManager.SupporterKey, + LegacyKey = kernel.SecurityManager.LegacyKey }; return ToOptimizedResult(result); @@ -221,8 +221,8 @@ namespace MediaBrowser.Api var info = _jsonSerializer.DeserializeFromStream(request.RequestStream); - kernel.PluginSecurityManager.SupporterKey = info.SupporterKey; - kernel.PluginSecurityManager.LegacyKey = info.LegacyKey; + kernel.SecurityManager.SupporterKey = info.SupporterKey; + kernel.SecurityManager.LegacyKey = info.LegacyKey; } /// diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 9e8edce233..44e00877e3 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Events; using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.Security; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -152,6 +153,12 @@ namespace MediaBrowser.Common.Kernel /// The TCP manager. public IServerManager ServerManager { get; private set; } + /// + /// Gets the plug-in security manager. + /// + /// The plug-in security manager. + public ISecurityManager SecurityManager { get; set; } + /// /// Gets the UDP server port number. /// This can't be configurable because then the user would have to configure their client to discover the server. diff --git a/MediaBrowser.Common/Kernel/IKernel.cs b/MediaBrowser.Common/Kernel/IKernel.cs index 715dc9a270..4b7375ba1d 100644 --- a/MediaBrowser.Common/Kernel/IKernel.cs +++ b/MediaBrowser.Common/Kernel/IKernel.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.Security; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.System; using System; @@ -89,6 +90,12 @@ namespace MediaBrowser.Common.Kernel /// The TCP manager. IServerManager ServerManager { get; } + /// + /// Gets the plug-in security manager. + /// + /// The plug-in security manager. + ISecurityManager SecurityManager { get; set; } + /// /// Gets the web socket listeners. /// diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 48dfa5c16c..6faa20012b 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Common.Security; using MediaBrowser.Common.Updates; using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Entities; @@ -91,12 +92,6 @@ namespace MediaBrowser.Controller /// The user data manager. public UserDataManager UserDataManager { get; private set; } - /// - /// Gets the plug-in security manager. - /// - /// The plug-in security manager. - public PluginSecurityManager PluginSecurityManager { get; private set; } - /// /// The _users /// @@ -321,7 +316,7 @@ namespace MediaBrowser.Controller ImageManager = (ImageManager)ApplicationHost.CreateInstance(typeof(ImageManager)); ProviderManager = (ProviderManager)ApplicationHost.CreateInstance(typeof(ProviderManager)); UserDataManager = (UserDataManager)ApplicationHost.CreateInstance(typeof(UserDataManager)); - PluginSecurityManager = (PluginSecurityManager)ApplicationHost.CreateInstance(typeof(PluginSecurityManager)); + SecurityManager = (PluginSecurityManager)ApplicationHost.CreateInstance(typeof(PluginSecurityManager)); base.FindParts(); diff --git a/MediaBrowser.Controller/Updates/InstallationManager.cs b/MediaBrowser.Controller/Updates/InstallationManager.cs index 64b72ae636..633cc6bc31 100644 --- a/MediaBrowser.Controller/Updates/InstallationManager.cs +++ b/MediaBrowser.Controller/Updates/InstallationManager.cs @@ -183,7 +183,7 @@ namespace MediaBrowser.Controller.Updates PackageType? packageType = null, Version applicationVersion = null) { - var data = new Dictionary { { "key", Kernel.PluginSecurityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; + var data = new Dictionary { { "key", Kernel.SecurityManager.SupporterKey }, { "mac", _networkManager.GetMacAddress() } }; using (var json = await HttpClient.Post(Controller.Kernel.MBAdminUrl + "service/package/retrieveall", data, Kernel.ResourcePools.Mb, cancellationToken).ConfigureAwait(false)) {