# PublishAuthorizer, SubscriptionAuthorizer class is getting triggered post PublishInboundInterceptor and SubscribeInboundInterceptor

**URL:** <https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395>\
**Category:** HiveMQ Extension SDK\
**Created:** [September 1, 2022, 9:14am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395 "2022-09-01T09:14:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha.khan](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@neha.khan](https://community.hivemq.com/u/neha.khan)\
**Post date:** [September 1, 2022, 9:14am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395/1 "2022-09-01T09:14:19Z")

</div>

Hi Team,

We are working on the extension logic in our project the expected flow for subscribe and publish should be authentication → publish/subscribe Authorizer → PublishInboundInterceptor/SubscribeInboundInterceptor.

However while performing integration testing on the extension code the flow seen  
authentication → PublishInboundInterceptor/SubscribeInboundInterceptor → publish/subscribe Authorizer

Could you please look into this and let us know if it is an expected extension behaviour?

---

<div class="post-metadata">

**Author:** ![FloLi](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/floli/32/17_2.png) [@FloLi](https://community.hivemq.com/u/FloLi)\
**Post date:** [September 1, 2022, 9:19am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395/2 "2022-09-01T09:19:45Z")

</div>

Hi neha.khan,

Welcome to the board and glad you are interested in HiveMQ extension development.

To answer your question. Yes it is expected behaviour. Interception happens before Authorization.

Regards Flo

---

<div class="post-metadata">

**Author:** ![neha.khan](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@neha.khan](https://community.hivemq.com/u/neha.khan)\
**Post date:** [September 1, 2022, 9:47am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395/3 "2022-09-01T09:47:28Z")

</div>

Thanks @FloLi for such a quick response!  
Since expected flow is Authentication → Authorization → Publish/Subscribe implementation.

Could you suggest a better way to approach the same i.e., Alternative for PublishInboundInterceptor/ SubscribeInboundInterceptor  
or Publish/Subscribe Authorizer?

---

<div class="post-metadata">

**Author:** ![Daria\_H](https://avatars.discourse-cdn.com/v4/letter/d/dfb087/32.png) [@Daria\_H](https://community.hivemq.com/u/Daria_H)\
**Post date:** [September 1, 2022, 10:06am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395/4 "2022-09-01T10:06:52Z")

</div>

Hello @neha.khan ,

The flow that you have asked about is the expected behaviour:

> [@neha.khan](#):
>
> authentication → PublishInboundInterceptor/SubscribeInboundInterceptor → publish/subscribe Authorizer

What is that the alternative you are looking for? What is your use case?

mfg,  
Dasha from HiveMQ team

---

<div class="post-metadata">

**Author:** ![neha.khan](https://avatars.discourse-cdn.com/v4/letter/n/4491bb/32.png) [@neha.khan](https://community.hivemq.com/u/neha.khan)\
**Post date:** [September 1, 2022, 10:32am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395/5 "2022-09-01T10:32:00Z")

</div>

Hi @Daria_H,

The use case is we have some custom logic for when a client publish a message or subscribe to a topic but before that we want to do authorization.

Thanks,  
Neha

---

<div class="post-metadata">

**Author:** ![FloLi](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/floli/32/17_2.png) [@FloLi](https://community.hivemq.com/u/FloLi)\
**Post date:** [September 2, 2022, 10:14am UTC](https://community.hivemq.com/t/publishauthorizer-subscriptionauthorizer-class-is-getting-triggered-post-publishinboundinterceptor-and-subscribeinboundinterceptor/1395/6 "2022-09-02T10:14:22Z")

</div>

Hi @neha.khan

As you decide the authorization in your custom authorizer, cant you just implement your custom logic in the Publish/Subscribe authorizer?

Maybe something like this:

```auto
new PublishAuthorizer() {
    @Override
    public void authorizePublish(
            @NotNull final PublishAuthorizerInput publishAuthorizerInput,
            @NotNull final PublishAuthorizerOutput publishAuthorizerOutput) {
                
        final boolean publishAuthorized = checkAuthorized(publishAuthorizerInput);
        if(publishAuthorized) {
            doCustomLogic();
            publishAuthorizerOutput.authorizeSuccessfully();
        } else {
            publishAuthorizerOutput.failAuthorization();
        }
    }
};

```

Regards Flo
