From 3527606947bf67799cc5d9690799e6e0ed934bf0 Mon Sep 17 00:00:00 2001 From: JohnNiang Date: Wed, 11 Sep 2024 15:29:46 +0800 Subject: [PATCH] Expose CryptoService and RateLimiterRegistry to plugins Signed-off-by: JohnNiang --- .../app/security/authentication/CryptoService.java | 0 .../app/plugin/SharedApplicationContextFactory.java | 10 ++++++++++ 2 files changed, 10 insertions(+) rename {application => api}/src/main/java/run/halo/app/security/authentication/CryptoService.java (100%) diff --git a/application/src/main/java/run/halo/app/security/authentication/CryptoService.java b/api/src/main/java/run/halo/app/security/authentication/CryptoService.java similarity index 100% rename from application/src/main/java/run/halo/app/security/authentication/CryptoService.java rename to api/src/main/java/run/halo/app/security/authentication/CryptoService.java diff --git a/application/src/main/java/run/halo/app/plugin/SharedApplicationContextFactory.java b/application/src/main/java/run/halo/app/plugin/SharedApplicationContextFactory.java index 90b146114d..c0236917b5 100644 --- a/application/src/main/java/run/halo/app/plugin/SharedApplicationContextFactory.java +++ b/application/src/main/java/run/halo/app/plugin/SharedApplicationContextFactory.java @@ -1,5 +1,6 @@ package run.halo.app.plugin; +import io.github.resilience4j.ratelimiter.RateLimiterRegistry; import org.springframework.cache.CacheManager; import org.springframework.context.ApplicationContext; import org.springframework.context.support.GenericApplicationContext; @@ -16,6 +17,7 @@ import run.halo.app.notification.NotificationReasonEmitter; import run.halo.app.plugin.extensionpoint.ExtensionGetter; import run.halo.app.security.LoginHandlerEnhancer; +import run.halo.app.security.authentication.CryptoService; /** * Utility for creating shared application context. @@ -69,6 +71,14 @@ public static ApplicationContext create(ApplicationContext rootContext) { ); beanFactory.registerSingleton("extensionGetter", rootContext.getBean(ExtensionGetter.class)); + rootContext.getBeanProvider(CryptoService.class) + .ifUnique( + cryptoService -> beanFactory.registerSingleton("cryptoService", cryptoService) + ); + rootContext.getBeanProvider(RateLimiterRegistry.class) + .ifUnique(rateLimiterRegistry -> + beanFactory.registerSingleton("rateLimiterRegistry", rateLimiterRegistry) + ); // TODO add more shared instance here sharedContext.refresh();