Skip to content

Commit

Permalink
NOISSUE - Change downstream publish auth handler subscribe (#76)
Browse files Browse the repository at this point in the history
* fix: downstream auth publish

Signed-off-by: Arvindh <[email protected]>

* fix: downstream auth publish

Signed-off-by: Arvindh <[email protected]>

* fix: downstream auth publish

Signed-off-by: Arvindh <[email protected]>

* fix: downstream auth publish

Signed-off-by: Arvindh <[email protected]>

* add: comments

Signed-off-by: Arvindh <[email protected]>

* add: comments

Signed-off-by: Arvindh <[email protected]>

---------

Signed-off-by: Arvindh <[email protected]>
  • Loading branch information
arvindh123 authored Nov 1, 2024
1 parent e53a940 commit 8d2b7e2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/session/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,15 @@ func stream(ctx context.Context, dir Direction, r, w net.Conn, h Handler, ic Int
}
default:
if p, ok := pkt.(*packets.PublishPacket); ok {
if err = h.AuthPublish(ctx, &p.TopicName, &p.Payload); err != nil {
topics := []string{p.TopicName}
// The broker sends subscription messages to the client as Publish Packets.
// We need to check if the Publish packet sent by the broker is allowed to be received to by the client.
// Therefore, we are using handler.AuthSubscribe instead of handler.AuthPublish.
if err = h.AuthSubscribe(ctx, &topics); err != nil {
pkt = packets.NewControlPacket(packets.Disconnect).(*packets.DisconnectPacket)
err = pkt.Write(w)
if wErr := pkt.Write(w); wErr != nil {
err = errors.Join(err, wErr)
}
errs <- wrap(ctx, err, dir)
return
}
Expand Down

0 comments on commit 8d2b7e2

Please sign in to comment.