Expose user and role services into plugins (#6880)

#### What type of PR is this?

/kind feature
/area plugin
/milestone 2.20.x

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

This PR exposes user and role services into plugins. Some authentication plugins may interact with users and users' roles.

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

```release-note
允许在插件中使用 UserService 和 RoleService
```
pull/6885/head
John Niang 2024-10-16 17:29:27 +08:00 committed by GitHub
parent c577deb6ee
commit db4e68b732
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 7 additions and 1 deletions

View File

@ -15,7 +15,7 @@ public class ValidationUtils {
public static final Pattern NAME_PATTERN = Pattern.compile(NAME_REGEX); public static final Pattern NAME_PATTERN = Pattern.compile(NAME_REGEX);
/** /**
* A-Z, a-z, 0-9, !@#$%^&* are allowed. * {@code A-Z, a-z, 0-9, !@#$%^&*} are allowed.
*/ */
public static final String PASSWORD_REGEX = "^[A-Za-z0-9!@#$%^&*]+$"; public static final String PASSWORD_REGEX = "^[A-Za-z0-9!@#$%^&*]+$";

View File

@ -8,6 +8,8 @@ import org.springframework.security.web.server.context.ServerSecurityContextRepo
import org.springframework.security.web.server.savedrequest.ServerRequestCache; import org.springframework.security.web.server.savedrequest.ServerRequestCache;
import run.halo.app.content.PostContentService; import run.halo.app.content.PostContentService;
import run.halo.app.core.extension.service.AttachmentService; import run.halo.app.core.extension.service.AttachmentService;
import run.halo.app.core.user.service.RoleService;
import run.halo.app.core.user.service.UserService;
import run.halo.app.extension.DefaultSchemeManager; import run.halo.app.extension.DefaultSchemeManager;
import run.halo.app.extension.ExtensionClient; import run.halo.app.extension.ExtensionClient;
import run.halo.app.extension.ReactiveExtensionClient; import run.halo.app.extension.ReactiveExtensionClient;
@ -86,6 +88,10 @@ public enum SharedApplicationContextFactory {
.ifUnique(serverRequestCache -> .ifUnique(serverRequestCache ->
beanFactory.registerSingleton("serverRequestCache", serverRequestCache) beanFactory.registerSingleton("serverRequestCache", serverRequestCache)
); );
rootContext.getBeanProvider(UserService.class)
.ifUnique(userService -> beanFactory.registerSingleton("userService", userService));
rootContext.getBeanProvider(RoleService.class)
.ifUnique(roleService -> beanFactory.registerSingleton("roleService", roleService));
// TODO add more shared instance here // TODO add more shared instance here
sharedContext.refresh(); sharedContext.refresh();