Skip to content

Commit 8e82981

Browse files
committed
refactor: 优化用户权限初始化逻辑
1 parent c28de17 commit 8e82981

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

jetlinks-components/rule-engine-component/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@
6565
<artifactId>relation-component</artifactId>
6666
<version>${project.version}</version>
6767
</dependency>
68+
6869
<dependency>
6970
<groupId>org.jetlinks.community</groupId>
7071
<artifactId>configure-component</artifactId>
71-
<version>2.10.0-SNAPSHOT</version>
72+
<version>${project.version}</version>
7273
<scope>compile</scope>
7374
</dependency>
75+
7476
<dependency>
7577
<groupId>org.jetlinks.community</groupId>
7678
<artifactId>things-component</artifactId>

jetlinks-manager/authentication-manager/src/main/java/org/jetlinks/community/auth/dimension/UserAuthenticationEventPublisher.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ private Mono<Void> publish0(Collection<String> userIdList) {
8181
return Flux
8282
.fromIterable(userIdList)
8383
.flatMapDelayError(
84-
userId -> ReactiveAuthenticationHolder
85-
.get(userId)
86-
.flatMap(auth -> eventBus
87-
.publish(Topics
88-
.Authentications
89-
.userAuthenticationChanged(auth.getUser().getId()),
90-
FastSerializableAuthentication.of(auth, true)
91-
))
92-
.as(MonoTracer.create("/user/" + userId + "/authentication/changed")),
93-
4, 4)
84+
userId -> eventBus
85+
.publish(Topics.Authentications.userAuthenticationChanged(userId),
86+
ReactiveAuthenticationHolder
87+
.get(userId)
88+
.map(auth -> FastSerializableAuthentication.of(auth, true)))
89+
.as(MonoTracer.create("/user/" + userId + "/authentication/changed")), 4, 4)
9490
.then();
9591
}
9692

jetlinks-manager/notify-manager/src/main/java/org/jetlinks/community/notify/manager/service/NotifySubscriberService.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,15 @@ public Mono<Void> doSubscribe(NotifySubscriberEntity entity) {
359359

360360
}
361361

362-
//用户权限变更时重新订阅
363-
@Subscribe(value = Topics.Authentications.allUserAuthenticationChanged, features = Subscription.Feature.local)
364-
public void handleAuthenticationChanged(Authentication auth) {
365-
366-
SubTable table = subscribers.get(auth.getUser().getId());
367-
if (table != null) {
368-
table.resubscribe(auth);
369-
}
370-
}
362+
// //用户权限变更时重新订阅
363+
// @Subscribe(value = Topics.Authentications.allUserAuthenticationChanged, features = Subscription.Feature.local)
364+
// public void handleAuthenticationChanged(Authentication auth) {
365+
//
366+
// SubTable table = subscribers.get(auth.getUser().getId());
367+
// if (table != null) {
368+
// table.resubscribe(auth);
369+
// }
370+
// }
371371

372372
//用户订阅表
373373
private class SubTable implements Disposable {
@@ -380,6 +380,20 @@ private class SubTable implements Disposable {
380380

381381
public SubTable(String subscriber) {
382382
this.subscriber = subscriber;
383+
disposable.add(
384+
eventBus.subscribe(
385+
Subscription
386+
.builder()
387+
.features(Subscription.Feature.local)
388+
.topics(Topics.Authentications.userAuthenticationChanged(subscriber))
389+
.subscriberId("notify_subscriber")
390+
.build(),
391+
p -> {
392+
resubscribe(p.decode(Authentication.class));
393+
return Mono.empty();
394+
}
395+
)
396+
);
383397
}
384398

385399
void resubscribe(Authentication authentication) {
@@ -629,7 +643,7 @@ class NotifySubscriberProviderCache implements Disposable {
629643

630644
private final Map<String, NotifySubscriberChannelEntity> channels = new ConcurrentHashMap<>();
631645

632-
public NotifySubscriberProviderEntity getProvider(){
646+
public NotifySubscriberProviderEntity getProvider() {
633647
return provider;
634648
}
635649

0 commit comments

Comments
 (0)