From d05d2e13e3386a93d0ecb2e9720af50572d1a596 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sun, 10 Mar 2024 23:12:34 +0100 Subject: [PATCH] Updated readme, subscription authorization logic --- README.md | 11 ++++++----- src/Broker/Topic.php | 9 ++------- src/Broker/TopicManager.php | 5 ++++- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3dcd92e..241420b 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,10 @@ $ ./mercureact.phar -c mercureact.conf * [x] Check JWTs on connect * [ ] Check claims on subscribe and publish * [ ] WebSocket authentication -* [ ] Subscription/Topic manager - * [ ] Unify distribution + * [ ] Extract JWT claims to request attributes, instead of JWTToken +* [x] Subscription/Topic manager + * [x] Unify distribution + * [ ] Enumerate subscriptions and topics * [ ] Publish events * [ ] Server-Side Events distributor * [x] Distribute events over SSE @@ -48,6 +50,5 @@ $ ./mercureact.phar -c mercureact.conf * [ ] Setup subscriptions * [ ] Dynamic subscriptions * [x] Distribute events over WS -* [ ] HTTP - * [ ] Break out HTTP middleware into classes - * [ ] HTTP middleware unittests \ No newline at end of file +* [x] Break out HTTP middleware into classes +* [ ] HTTP middleware unittests diff --git a/src/Broker/Topic.php b/src/Broker/Topic.php index 2ac2148..ca35f75 100644 --- a/src/Broker/Topic.php +++ b/src/Broker/Topic.php @@ -31,13 +31,8 @@ class Topic // TODO check if message id has already been published foreach ($this->subscribers as $subscriber) { - if ($message->private === true) { - // TODO check subscriber access - $subscriber->deliver($message); - } else { - // TODO deliver to subscriber - $subscriber->deliver($message); - } + // Deliver to all subscribers + $subscriber->deliver($message); } } diff --git a/src/Broker/TopicManager.php b/src/Broker/TopicManager.php index 7cad74f..af8bee4 100644 --- a/src/Broker/TopicManager.php +++ b/src/Broker/TopicManager.php @@ -34,8 +34,10 @@ class TopicManager public function subscribe(SubscriberInterface $subscriber, array $topics): void { foreach ($topics as $topic) { - $this->getTopic($topic)->addSubscriber($subscriber); + if ($subscriber->isAuthorized($topic)) + $this->getTopic($topic)->addSubscriber($subscriber); } + $this->subscribers->attach($subscriber); } public function unsubscribe(SubscriberInterface $subscriber, ?array $topics=null): void @@ -49,6 +51,7 @@ class TopicManager foreach ($topics as $topic) { $this->getTopic($topic)->removeSubscriber($subscriber); } + $this->subscribers->detach($subscriber); } public function getTopicCount(): int