From 2ca4b7d03adfa3cc7c9c6a597a11762142d5b34b Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 00:43:06 -0500 Subject: Created IConfigurationManager --- .../Security/PluginSecurityManager.cs | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs (limited to 'MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs') diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs new file mode 100644 index 000000000..a56637371 --- /dev/null +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -0,0 +1,131 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Security; +using MediaBrowser.Model.Serialization; +using Mediabrowser.Model.Entities; +using Mediabrowser.PluginSecurity; +using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Net; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Common.Implementations.Security +{ + /// + /// Class PluginSecurityManager + /// + public class PluginSecurityManager : ISecurityManager + { + /// + /// The _is MB supporter + /// + private bool? _isMBSupporter; + /// + /// The _is MB supporter initialized + /// + private bool _isMBSupporterInitialized; + /// + /// The _is MB supporter sync lock + /// + private object _isMBSupporterSyncLock = new object(); + + /// + /// Gets a value indicating whether this instance is MB supporter. + /// + /// true if this instance is MB supporter; otherwise, false. + public bool IsMBSupporter + { + get + { + LazyInitializer.EnsureInitialized(ref _isMBSupporter, ref _isMBSupporterInitialized, ref _isMBSupporterSyncLock, () => GetRegistrationStatus("MBSupporter").Result.IsRegistered); + return _isMBSupporter.Value; + } + } + + private IHttpClient _httpClient; + private IJsonSerializer _jsonSerializer; + + /// + /// The _kernel + /// + private readonly IKernel _kernel; + + /// + /// Initializes a new instance of the class. + /// + /// The kernel. + public PluginSecurityManager(IKernel kernel, IHttpClient httpClient, IJsonSerializer jsonSerializer, IApplicationPaths appPaths) + { + if (kernel == null) + { + throw new ArgumentNullException("kernel"); + } + + if (httpClient == null) + { + throw new ArgumentNullException("httpClient"); + } + + _kernel = kernel; + _httpClient = httpClient; + _jsonSerializer = jsonSerializer; + //MBRegistration.Init(appPaths); + } + + /// + /// Gets the registration status. + /// + /// The feature. + /// The MB2 equivalent. + /// Task{MBRegistrationRecord}. + public async Task GetRegistrationStatus(string feature, string mb2Equivalent = null) + { + return await MBRegistration.GetRegistrationStatus(_httpClient, _jsonSerializer, feature, mb2Equivalent).ConfigureAwait(false); + } + + /// + /// Gets or sets the supporter key. + /// + /// The supporter key. + public string SupporterKey + { + get { return MBRegistration.SupporterKey; } + set + { + if (value != MBRegistration.SupporterKey) + { + MBRegistration.SupporterKey = value; + // Clear this so it will re-evaluate + ResetSupporterInfo(); + // And we'll need to restart to re-evaluate the status of plug-ins + _kernel.NotifyPendingRestart(); + + } + } + } + + /// + /// Gets or sets the legacy key. + /// + /// The legacy key. + public string LegacyKey + { + get { return MBRegistration.LegacyKey; } + set + { + MBRegistration.LegacyKey = value; + // And we'll need to restart to re-evaluate the status of plug-ins + _kernel.NotifyPendingRestart(); + } + } + + /// + /// Resets the supporter info. + /// + private void ResetSupporterInfo() + { + _isMBSupporter = null; + _isMBSupporterInitialized = false; + } + } +} -- cgit v1.2.3 From 9cdda84b062d990af285d7f25507c892ce05e180 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 01:06:38 -0500 Subject: updated plugin security --- .../Security/PluginSecurityManager.cs | 2 +- .../Providers/Music/LastfmArtistProvider.cs | 11 +++++++---- .../Providers/Music/LastfmBaseArtistProvider.cs | 5 +++-- Nuget/MediaBrowser.Common.Internal.nuspec | 4 ++-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 ++-- 6 files changed, 16 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs') diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index a56637371..d1a4940ef 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -69,7 +69,7 @@ namespace MediaBrowser.Common.Implementations.Security _kernel = kernel; _httpClient = httpClient; _jsonSerializer = jsonSerializer; - //MBRegistration.Init(appPaths); + MBRegistration.Init(appPaths); } /// diff --git a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs index 5203b6f06..ba32ba9e6 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmArtistProvider.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Logging; @@ -16,8 +17,10 @@ namespace MediaBrowser.Controller.Providers.Music { public class LastfmArtistProvider : LastfmBaseArtistProvider { - public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) - : base(jsonSerializer, httpClient, logManager) + internal readonly SemaphoreSlim LastfmResourcePool = new SemaphoreSlim(5, 5); + + public LastfmArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(jsonSerializer, httpClient, logManager, configurationManager) { } @@ -30,7 +33,7 @@ namespace MediaBrowser.Controller.Providers.Music try { - using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.MovieDb, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url, LastfmResourcePool, cancellationToken).ConfigureAwait(false)) { searchResult = JsonSerializer.DeserializeFromStream(json); } @@ -61,7 +64,7 @@ namespace MediaBrowser.Controller.Providers.Music try { - using (var json = await HttpClient.Get(url, Kernel.Instance.ResourcePools.Lastfm, cancellationToken).ConfigureAwait(false)) + using (var json = await HttpClient.Get(url, LastfmResourcePool, cancellationToken).ConfigureAwait(false)) { result = JsonSerializer.DeserializeFromStream(json); } diff --git a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs index 85f141a56..444c0fefd 100644 --- a/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/LastfmBaseArtistProvider.cs @@ -5,6 +5,7 @@ using System.Net; using System.Text; using System.Threading.Tasks; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Net; @@ -14,8 +15,8 @@ namespace MediaBrowser.Controller.Providers.Music { public abstract class LastfmBaseArtistProvider : LastfmBaseProvider { - protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager) - : base(jsonSerializer, httpClient, logManager) + protected LastfmBaseArtistProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogManager logManager, IServerConfigurationManager configurationManager) + : base(jsonSerializer, httpClient, logManager, configurationManager) { LocalMetaFileName = "MBArtist.json"; } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index b74f7a55f..e3f8d15a1 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.26 + 3.0.28 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theatre and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index bdc564592..725057b94 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.26 + 3.0.28 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 2d127a890..ce4445203 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.26 + 3.0.28 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - + -- cgit v1.2.3