mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-05-09 22:59:43 +08:00
feat: ClearUserAuthorizationCacheEvent可手动关闭
This commit is contained in:
@@ -2,8 +2,10 @@ package org.hswebframework.web.system.authorization.api.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.hswebframework.web.event.DefaultAsyncEvent;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -23,6 +25,26 @@ public class ClearUserAuthorizationCacheEvent extends DefaultAsyncEvent {
|
||||
|
||||
private boolean async;
|
||||
|
||||
private static final String DISABLE_KEY = ClearUserAuthorizationCacheEvent.class + "_Disabled";
|
||||
|
||||
public static Mono<Void> disable(Mono<Void> task) {
|
||||
return task.contextWrite(Context.of(DISABLE_KEY, true));
|
||||
}
|
||||
|
||||
public static Mono<Void> doOnEnabled(Mono<Void> task) {
|
||||
return Mono.deferContextual(ctx -> {
|
||||
if (ctx.hasKey(DISABLE_KEY)) {
|
||||
return Mono.empty();
|
||||
}
|
||||
return task;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void async(Publisher<?> publisher) {
|
||||
super.async(doOnEnabled(Mono.fromDirect(publisher).then()));
|
||||
}
|
||||
|
||||
public static ClearUserAuthorizationCacheEvent of(Collection<String> collection) {
|
||||
ClearUserAuthorizationCacheEvent event = new ClearUserAuthorizationCacheEvent();
|
||||
if (collection == null || collection.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user