From 946dfef098e82bfde918ea445567465325e1dfcd Mon Sep 17 00:00:00 2001 From: jonechenug Date: Wed, 14 Aug 2024 16:08:49 +0800 Subject: [PATCH 1/5] add plugin support --- SecurityTokenService.sln | 15 +++++++++++ .../Extensions/PluginsExtensions.cs | 25 ++++++++++++++++++ .../SecurityTokenServicePluginDemo.dll | Bin 0 -> 6144 bytes src/SecurityTokenService/Program.cs | 3 ++- .../DisableAnyOneSecurityTokenPlugin.cs | 13 +++++++++ .../DisableAnyOneValidator.cs | 16 +++++++++++ .../SecurityTokenServicePluginDemo.csproj | 15 +++++++++++ 7 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/SecurityTokenService/Extensions/PluginsExtensions.cs create mode 100644 src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll create mode 100644 src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs create mode 100644 src/SecurityTokenServicePluginDemo/DisableAnyOneValidator.cs create mode 100644 src/SecurityTokenServicePluginDemo/SecurityTokenServicePluginDemo.csproj diff --git a/SecurityTokenService.sln b/SecurityTokenService.sln index f8f0555..c68a1ae 100644 --- a/SecurityTokenService.sln +++ b/SecurityTokenService.sln @@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptClient", "src\Jav EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcClient", "src\MvcClient\MvcClient.csproj", "{2775FB23-EC1E-496C-85FC-26E5820C3559}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecurityTokenServicePluginDemo", "src\SecurityTokenServicePluginDemo\SecurityTokenServicePluginDemo.csproj", "{83F692C2-2498-497D-AD53-2CCB4B60E0DD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,6 +103,18 @@ Global {2775FB23-EC1E-496C-85FC-26E5820C3559}.Release|x64.Build.0 = Release|Any CPU {2775FB23-EC1E-496C-85FC-26E5820C3559}.Release|x86.ActiveCfg = Release|Any CPU {2775FB23-EC1E-496C-85FC-26E5820C3559}.Release|x86.Build.0 = Release|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Debug|x64.ActiveCfg = Debug|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Debug|x64.Build.0 = Debug|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Debug|x86.ActiveCfg = Debug|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Debug|x86.Build.0 = Debug|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Release|Any CPU.Build.0 = Release|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Release|x64.ActiveCfg = Release|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Release|x64.Build.0 = Release|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Release|x86.ActiveCfg = Release|Any CPU + {83F692C2-2498-497D-AD53-2CCB4B60E0DD}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -111,6 +125,7 @@ Global {0C920EC3-5FD5-4BF8-9D31-F66075143FD7} = {BD8BA25C-A91D-419D-99B6-B575ADD6D061} {E4C71DA8-2051-4832-9034-01BCEEF49253} = {BD8BA25C-A91D-419D-99B6-B575ADD6D061} {2775FB23-EC1E-496C-85FC-26E5820C3559} = {BD8BA25C-A91D-419D-99B6-B575ADD6D061} + {83F692C2-2498-497D-AD53-2CCB4B60E0DD} = {BD8BA25C-A91D-419D-99B6-B575ADD6D061} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {84D5AF06-1243-46F1-9D58-70ED572832C3} diff --git a/src/SecurityTokenService/Extensions/PluginsExtensions.cs b/src/SecurityTokenService/Extensions/PluginsExtensions.cs new file mode 100644 index 0000000..a05b3c6 --- /dev/null +++ b/src/SecurityTokenService/Extensions/PluginsExtensions.cs @@ -0,0 +1,25 @@ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using Microsoft.Extensions.DependencyInjection; + +namespace SecurityTokenService.Extensions; + +public static class PluginsExtensions +{ + public static void LoadPlugins(this IServiceCollection services) + { + var pluginFiles = Directory.GetFiles("Plugins", "*.dll"); + foreach (var pluginFile in pluginFiles) + { + var assembly = Assembly.LoadFrom(pluginFile); + var pluginTypes = assembly.GetTypes().Where(t => t.Name.Contains("SecurityTokenPlugin")); + foreach (var pluginType in pluginTypes) + { + var registerMethod = pluginType.GetMethod("RegisterServices"); + registerMethod?.Invoke(null, new object[] { services }); + } + } + } +} diff --git a/src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll b/src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll new file mode 100644 index 0000000000000000000000000000000000000000..b2f007a12d9727c6c4ea558f3cb6920c5a9cf6df GIT binary patch literal 6144 zcmeHLZ*Wvs6+iFoW)lL0Bos=imQ4dR5c;zDLz*DaEZG2QNeI~`Koyp^yEmIx-oCfK z_cpN7NGR2g9~|4!VXBVy-}FPrT5H>>M5mp0#t*h5Ggilbu?oyM`lX|tIy#Os7JujN z+uZ~ZtN5iey_=dl9VTEIRG>k0)oyZKu5pCqWo8FeUwQk zN$B0nodMWUQNjej93@(U?w(CVi8Ae@wBd^BQo0WK?s?-hPn__8pIZt5o?NSMH!xYk zL`OBpb<)73Z3F0pQ002i`egvtYmP8&2(qno6qR+YM4eX#h<40FW%ujsR}{8Qr5ak& z0%ePd6iNN>!D64HhR)Nj09ZMzvQZCp=k8)VwoS4ng$=0Rw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Et+yYN0(7>X>W=HLeWenft|rMun!S-5XYktds>Vl zC8;vUe77Kke#%n1l)AjTeL9M}ib*yd$9ZI-wQw5b&=#;~)1m8ecacLn4rY0fq0LiK8Mw7IUPR;_E+ zqw|84>)>$)V3-a&l}=#SAkru)Ur*XRoduKV$gO( zG@sw(f85)q`?LrYG~86#Dr1J5H}&EucFsB;5r#yoLbomWnEe#0e)_nf;$9;+SKQ|@ zYbUOu_z`t0q)DV*^hWwK-RZ8$&aOUvb600qSATC;ZyzqJcXf65b*4n$WWU~YrobxNkMi5e2NBc!E>Qf-oDuKS5ijC_)LBb^$A?gpWt_#UwGhh)H_i7 z@b>6i<}>`}il+^Y$7AvPdipP2crr8c+7bPO#0uvk>*$!U%|cGN9T_p*ku|)jLaO6h z%k04O>6(nHzdP*I{TVTCDpD29m zCc=AYcHwXtX+j2GMQ1sFJ02V$dLMVRa(O?{gYE>yDG4}4 zu_v--54;2Y3zlRm A`Tzg` literal 0 HcmV?d00001 diff --git a/src/SecurityTokenService/Program.cs b/src/SecurityTokenService/Program.cs index 87895cf..1d5bacf 100644 --- a/src/SecurityTokenService/Program.cs +++ b/src/SecurityTokenService/Program.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using SecurityTokenService.Data; +using SecurityTokenService.Extensions; using SecurityTokenService.Identity; using SecurityTokenService.IdentityServer; using Serilog; @@ -111,7 +112,7 @@ internal static WebApplication CreateApp(string[] args) .AllowCredentials() )); builder.Host.UseSerilog(); - + builder.Services.LoadPlugins(); var app = builder.Build(); return app; } diff --git a/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs b/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs new file mode 100644 index 0000000..04195d3 --- /dev/null +++ b/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs @@ -0,0 +1,13 @@ +using IdentityServer4.Validation; +using Microsoft.Extensions.DependencyInjection; + +namespace SecurityTokenServicePluginDemo; + +public static class DisableAnyOneSecurityTokenPlugin +{ + public static void RegisterServices(IServiceCollection services) + { + Console.WriteLine("register DisableAnyOneValidator..."); + services.AddTransient(); + } +} diff --git a/src/SecurityTokenServicePluginDemo/DisableAnyOneValidator.cs b/src/SecurityTokenServicePluginDemo/DisableAnyOneValidator.cs new file mode 100644 index 0000000..b0b0ccc --- /dev/null +++ b/src/SecurityTokenServicePluginDemo/DisableAnyOneValidator.cs @@ -0,0 +1,16 @@ +using IdentityServer4.Validation; + +namespace SecurityTokenServicePluginDemo; + +/// +/// 总是允许校验不通过 +/// +public class DisableAnyOneValidator : IExtensionGrantValidator +{ + public string GrantType => "disableAnyOne"; + + public async Task ValidateAsync(ExtensionGrantValidationContext context) + { + throw new Exception("DisableAnyOne!"); + } +} diff --git a/src/SecurityTokenServicePluginDemo/SecurityTokenServicePluginDemo.csproj b/src/SecurityTokenServicePluginDemo/SecurityTokenServicePluginDemo.csproj new file mode 100644 index 0000000..3d8613a --- /dev/null +++ b/src/SecurityTokenServicePluginDemo/SecurityTokenServicePluginDemo.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + + From d9bbc27b09145553867835217f6f125ca6657464 Mon Sep 17 00:00:00 2001 From: jonechenug Date: Wed, 14 Aug 2024 16:10:04 +0800 Subject: [PATCH 2/5] change load plugin log --- .../DisableAnyOneSecurityTokenPlugin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs b/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs index 04195d3..c99a463 100644 --- a/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs +++ b/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs @@ -7,7 +7,7 @@ public static class DisableAnyOneSecurityTokenPlugin { public static void RegisterServices(IServiceCollection services) { - Console.WriteLine("register DisableAnyOneValidator..."); + Console.WriteLine("Load DisableAnyOneSecurityTokenPlugin"); services.AddTransient(); } } From 7595f2878b4732d8084952dfe07389ce2e0baa05 Mon Sep 17 00:00:00 2001 From: jonechenug Date: Thu, 15 Aug 2024 14:29:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/PluginsExtensions.cs | 11 +++++------ .../SecurityTokenServicePluginDemo.dll | Bin 6144 -> 6656 bytes src/SecurityTokenService/Program.cs | 2 +- .../DisableAnyOneSecurityTokenPlugin.cs | 5 +++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SecurityTokenService/Extensions/PluginsExtensions.cs b/src/SecurityTokenService/Extensions/PluginsExtensions.cs index a05b3c6..ad333e3 100644 --- a/src/SecurityTokenService/Extensions/PluginsExtensions.cs +++ b/src/SecurityTokenService/Extensions/PluginsExtensions.cs @@ -1,14 +1,13 @@ -using System; -using System.IO; +using System.IO; using System.Linq; using System.Reflection; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; namespace SecurityTokenService.Extensions; public static class PluginsExtensions { - public static void LoadPlugins(this IServiceCollection services) + public static void LoadPlugins(this IHostApplicationBuilder builder) { var pluginFiles = Directory.GetFiles("Plugins", "*.dll"); foreach (var pluginFile in pluginFiles) @@ -17,8 +16,8 @@ public static void LoadPlugins(this IServiceCollection services) var pluginTypes = assembly.GetTypes().Where(t => t.Name.Contains("SecurityTokenPlugin")); foreach (var pluginType in pluginTypes) { - var registerMethod = pluginType.GetMethod("RegisterServices"); - registerMethod?.Invoke(null, new object[] { services }); + var loadMethod = pluginType.GetMethod("Load"); + loadMethod?.Invoke(null, new object[] { builder }); } } } diff --git a/src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll b/src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll index b2f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bbOx&D>E?;u%OI-q$yt&F1M>73%Z+9|-jA=Tz zn+*j6xfyZv@i%~-EPIMF#hmw34ly(6`oG>*q>-TiAl6d$vD`hBgB+V?Nqafor|dh) ztkMSAGlV4kYV&h@vomwfcVjKb&;4`u&+*x%FnogFtPjG%hQ}jSmxM*?-X)3~44d$} znJG`w78F9b@8|s`Ek1bLZEj6?`@Q{EhvtoY?G~G6_a@Y^g#D9;Hsw4&ITqM&y!rjd zziM9w>>rJ11JT*PoZPHgc}IAXy4Bms*KUy|1=r!S`h>UL+i3x(?>8?OjyEPF!B|hY zJG8Ya6iv(vHHAX4NGK8w2gCD2;b_yAWOQpR5$WmXr6;h`{G+I{_`gMIO(#-==1tek z0H@(ZcERI&=eaoHzX`Eol{_g2`5xv?eb{9#EGo4|`6m%AGS?SXx!2E)O(); + builder.Services.AddTransient(); } } From 25c282ec567f3f7b056520c4494b562be0248252 Mon Sep 17 00:00:00 2001 From: jonechenug Date: Thu, 15 Aug 2024 15:26:35 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/PluginsExtensions.cs | 33 +++++++++++++++--- .../SecurityTokenServicePluginDemo.dll | Bin 6656 -> 8192 bytes .../Controllers/TestController.cs | 15 ++++++++ .../DisableAnyOneSecurityTokenPlugin.cs | 8 +++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/SecurityTokenServicePluginDemo/Controllers/TestController.cs diff --git a/src/SecurityTokenService/Extensions/PluginsExtensions.cs b/src/SecurityTokenService/Extensions/PluginsExtensions.cs index ad333e3..5a13554 100644 --- a/src/SecurityTokenService/Extensions/PluginsExtensions.cs +++ b/src/SecurityTokenService/Extensions/PluginsExtensions.cs @@ -1,24 +1,47 @@ -using System.IO; +using System; +using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Hosting; namespace SecurityTokenService.Extensions; public static class PluginsExtensions { - public static void LoadPlugins(this IHostApplicationBuilder builder) + private static readonly List _pluginTypes; + + static PluginsExtensions() { + _pluginTypes = new(); var pluginFiles = Directory.GetFiles("Plugins", "*.dll"); foreach (var pluginFile in pluginFiles) { var assembly = Assembly.LoadFrom(pluginFile); var pluginTypes = assembly.GetTypes().Where(t => t.Name.Contains("SecurityTokenPlugin")); - foreach (var pluginType in pluginTypes) + if (pluginTypes.Any()) { - var loadMethod = pluginType.GetMethod("Load"); - loadMethod?.Invoke(null, new object[] { builder }); + _pluginTypes.AddRange(pluginTypes); } } } + + public static void LoadPlugins(this IHostApplicationBuilder builder) + { + foreach (var pluginType in _pluginTypes) + { + var loadMethod = pluginType.GetMethod("Load"); + loadMethod?.Invoke(null, new object[] { builder }); + } + } + + public static void UsePlugins(this WebApplication app) + { + foreach (var pluginType in _pluginTypes) + { + var loadMethod = pluginType.GetMethod("Use"); + loadMethod?.Invoke(null, new object[] { app }); + } + } } diff --git a/src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll b/src/SecurityTokenService/Plugins/SecurityTokenServicePluginDemo.dll index 97e9cce5ccb29953ac2d2451f6b035ae07544e42..0ebd56b47a7fc5976e0fb578bea356b50f6b7cfd 100644 GIT binary patch delta 3281 zcmZ`+4Q!Lg8Gi2jbK;o9c1Q@}r%pnHo1o13Ym&8;n7|-~G?1TlA!6V-AIvndGuweO z%4~#I2J6Jq54CKJ309cse%PdJorZ=+8I{^i+Zw6T+G#?dNwizrp;oB-)wbs@2Ar-v zbI;xL+1z0QN8d4J;<`2Rf7qm z8rb9mgfr!Bvu_|NfQjG&zzr=?!6rzdzBbpdr0}Z2nZZTuB^Jx^C4}0#`;qLqGqbKT z`7B8tN<$h}aV7fjrI?B3wt`EY!&+k|z*%+GTCj>O>ZDz}iimbavvv&3z25>1OWW^~ zP1$}^Hcv>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}J7zw>mwB-DIa(E@5-+@DI7dLI~e{exMXX(+-ErNU{5M zfc}*C8@iMJZ)JN%UU0~C+Fk5v4pj=iTFkSQEATpl!tSuU GetAsync() + { + return new ObjectResult("OK"); + } +} diff --git a/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs b/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs index 52eb23d..639cf91 100644 --- a/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs +++ b/src/SecurityTokenServicePluginDemo/DisableAnyOneSecurityTokenPlugin.cs @@ -1,6 +1,8 @@ using IdentityServer4.Validation; +using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using SecurityTokenServicePluginDemo.Controllers; namespace SecurityTokenServicePluginDemo; @@ -10,5 +12,11 @@ public static void Load(IHostApplicationBuilder builder) { Console.WriteLine("Load DisableAnyOneSecurityTokenPlugin"); builder.Services.AddTransient(); + builder.Services.AddControllers().AddApplicationPart(typeof(TestController).Assembly); + } + + public static void Use(WebApplication app) + { + Console.WriteLine("Use DisableAnyOneSecurityTokenPlugin"); } } From 1e512ebb409b06af610e479c4cab9d1f4e36b52b Mon Sep 17 00:00:00 2001 From: jonechenug Date: Thu, 15 Aug 2024 15:27:22 +0800 Subject: [PATCH 5/5] use plugins --- src/SecurityTokenService/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SecurityTokenService/Program.cs b/src/SecurityTokenService/Program.cs index 0dae904..85d0e59 100644 --- a/src/SecurityTokenService/Program.cs +++ b/src/SecurityTokenService/Program.cs @@ -67,6 +67,7 @@ await File.WriteAllTextAsync(htmlFile, } app.MapControllers().RequireCors("cors"); + app.UsePlugins(); await app.RunAsync(); }