Skip to content

Commit

Permalink
Expose CryptoService and RateLimiterRegistry to plugins (#6638)
Browse files Browse the repository at this point in the history
#### What type of PR is this?

/kind feature
/area core
/area plugin
/milestone 2.20.x

#### What this PR does / why we need it:

Currently, we are refactoring login and logout pages to make them extensible. If plugins want to realize a new authentication method, the CryptoService and RateLimiterRegistry may be used to authenticate.

So this PR exposes the two beans to plugins. No side effect will be introduced.

#### Does this PR introduce a user-facing change?

```release-note
【开发相关】允许在插件使用 CryptoService 和 RateLimiterRegistry
```
  • Loading branch information
JohnNiang authored Sep 12, 2024
1 parent 39545a1 commit a36822c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit a36822c

Please sign in to comment.