[Artemis] Intercept mqtt client connection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Artemis] Intercept mqtt client connection

aragoubi
This post was updated on .
I added an mqtt interceptor into my artemis broker in order to intercept mqtt client connection:



public class SimpleMQTTInterceptor implements MQTTInterceptor
{
        @Override
        public boolean intercept(final MqttMessage mqttMessage, RemotingConnection connection) throws ActiveMQException
        {
                System.out.println("MQTT Interceptor gets called ");

                if (mqttMessage instanceof MqttConnectMessage)
                {
                        System.out.println("MQTT connection intercepted ");
                }
                return true;
        }
}


My client apache paho connect to the broker via this port "ws://0.0.0.0:61614".
My problem is that only message published to topics are intercepted.
Why this doesn't intercept CONNECT message ?    
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Otavio Piske
I believe it's because it's not implemented.

I did a small modification to the code to test this hypothesis:
https://github.com/orpiske/activemq-artemis/commit/bd57548b6b2897a436240d6abadc1a8e01a1acc9.


After that, it can intercept Connect control packets.

On Thu, Aug 10, 2017 at 2:00 PM, aragoubi <[hidden email]> wrote:

> I added an mqtt interceptor into my artemis broker in order to intercept
> mqtt
> client connection:
>
>
>
> /public class SimpleMQTTInterceptor implements MQTTInterceptor
> {
>         @Override
>         public boolean intercept(final MqttMessage mqttMessage,
> RemotingConnection
> connection) throws ActiveMQException
>         {
>                 System.out.println("MQTT Interceptor gets called ");
>
>                 if (mqttMessage instanceof MqttConnectMessage)
>                 {
>                         System.out.println("MQTT connection intercepted ");
>                 }
>                 return true;
>         }
> }/
>
> My problem is that only message published to topics are intercepted.
> Why this doesn't intercept *CONNECT* message ?
>
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/Intercept-mqtt-client-connection-tp4729594.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



--
Otavio R. Piske
Messaging Quality Assurance Engineer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Justin Bertram
> I believe it's because it's not implemented.

Agreed.  It looks to me like only the publish packets are intercepted
currently.  Unless this was done very specifically then I think the logic
should be modified to intercept all kinds of packets.


Justin

On Mon, Aug 14, 2017 at 12:23 PM, Otavio Piske <[hidden email]> wrote:

> I believe it's because it's not implemented.
>
> I did a small modification to the code to test this hypothesis:
> https://github.com/orpiske/activemq-artemis/commit/
> bd57548b6b2897a436240d6abadc1a8e01a1acc9.
>
>
> After that, it can intercept Connect control packets.
>
> On Thu, Aug 10, 2017 at 2:00 PM, aragoubi <[hidden email]> wrote:
>
> > I added an mqtt interceptor into my artemis broker in order to intercept
> > mqtt
> > client connection:
> >
> >
> >
> > /public class SimpleMQTTInterceptor implements MQTTInterceptor
> > {
> >         @Override
> >         public boolean intercept(final MqttMessage mqttMessage,
> > RemotingConnection
> > connection) throws ActiveMQException
> >         {
> >                 System.out.println("MQTT Interceptor gets called ");
> >
> >                 if (mqttMessage instanceof MqttConnectMessage)
> >                 {
> >                         System.out.println("MQTT connection intercepted
> ");
> >                 }
> >                 return true;
> >         }
> > }/
> >
> > My problem is that only message published to topics are intercepted.
> > Why this doesn't intercept *CONNECT* message ?
> >
> >
> >
> >
> > --
> > View this message in context: http://activemq.2283324.n4.
> > nabble.com/Intercept-mqtt-client-connection-tp4729594.html
> > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >
>
>
>
> --
> Otavio R. Piske
> Messaging Quality Assurance Engineer
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Otavio Piske
+1 for adding it, unless there's a reason not to.

I'm playing w/ the code for this and will send a PR sometime this week.

On Mon, Aug 14, 2017 at 7:29 PM, Justin Bertram <[hidden email]> wrote:

> > I believe it's because it's not implemented.
>
> Agreed.  It looks to me like only the publish packets are intercepted
> currently.  Unless this was done very specifically then I think the logic
> should be modified to intercept all kinds of packets.
>
>
> Justin
>
> On Mon, Aug 14, 2017 at 12:23 PM, Otavio Piske <[hidden email]> wrote:
>
> > I believe it's because it's not implemented.
> >
> > I did a small modification to the code to test this hypothesis:
> > https://github.com/orpiske/activemq-artemis/commit/
> > bd57548b6b2897a436240d6abadc1a8e01a1acc9.
> >
> >
> > After that, it can intercept Connect control packets.
> >
> > On Thu, Aug 10, 2017 at 2:00 PM, aragoubi <[hidden email]> wrote:
> >
> > > I added an mqtt interceptor into my artemis broker in order to
> intercept
> > > mqtt
> > > client connection:
> > >
> > >
> > >
> > > /public class SimpleMQTTInterceptor implements MQTTInterceptor
> > > {
> > >         @Override
> > >         public boolean intercept(final MqttMessage mqttMessage,
> > > RemotingConnection
> > > connection) throws ActiveMQException
> > >         {
> > >                 System.out.println("MQTT Interceptor gets called ");
> > >
> > >                 if (mqttMessage instanceof MqttConnectMessage)
> > >                 {
> > >                         System.out.println("MQTT connection intercepted
> > ");
> > >                 }
> > >                 return true;
> > >         }
> > > }/
> > >
> > > My problem is that only message published to topics are intercepted.
> > > Why this doesn't intercept *CONNECT* message ?
> > >
> > >
> > >
> > >
> > > --
> > > View this message in context: http://activemq.2283324.n4.
> > > nabble.com/Intercept-mqtt-client-connection-tp4729594.html
> > > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> > >
> >
> >
> >
> > --
> > Otavio R. Piske
> > Messaging Quality Assurance Engineer
> >
>



--
Otavio R. Piske
Messaging Quality Assurance Engineer
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Justin Bertram
Take a look
at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl#invokeInterceptors.
I think the MQTT and STOMP protocol managers should be calling that instead
of invoking the interceptors themselves.


Justin

On Mon, Aug 14, 2017 at 1:38 PM, Otavio Piske <[hidden email]> wrote:

> +1 for adding it, unless there's a reason not to.
>
> I'm playing w/ the code for this and will send a PR sometime this week.
>
> On Mon, Aug 14, 2017 at 7:29 PM, Justin Bertram <[hidden email]>
> wrote:
>
> > > I believe it's because it's not implemented.
> >
> > Agreed.  It looks to me like only the publish packets are intercepted
> > currently.  Unless this was done very specifically then I think the logic
> > should be modified to intercept all kinds of packets.
> >
> >
> > Justin
> >
> > On Mon, Aug 14, 2017 at 12:23 PM, Otavio Piske <[hidden email]>
> wrote:
> >
> > > I believe it's because it's not implemented.
> > >
> > > I did a small modification to the code to test this hypothesis:
> > > https://github.com/orpiske/activemq-artemis/commit/
> > > bd57548b6b2897a436240d6abadc1a8e01a1acc9.
> > >
> > >
> > > After that, it can intercept Connect control packets.
> > >
> > > On Thu, Aug 10, 2017 at 2:00 PM, aragoubi <[hidden email]> wrote:
> > >
> > > > I added an mqtt interceptor into my artemis broker in order to
> > intercept
> > > > mqtt
> > > > client connection:
> > > >
> > > >
> > > >
> > > > /public class SimpleMQTTInterceptor implements MQTTInterceptor
> > > > {
> > > >         @Override
> > > >         public boolean intercept(final MqttMessage mqttMessage,
> > > > RemotingConnection
> > > > connection) throws ActiveMQException
> > > >         {
> > > >                 System.out.println("MQTT Interceptor gets called ");
> > > >
> > > >                 if (mqttMessage instanceof MqttConnectMessage)
> > > >                 {
> > > >                         System.out.println("MQTT connection
> intercepted
> > > ");
> > > >                 }
> > > >                 return true;
> > > >         }
> > > > }/
> > > >
> > > > My problem is that only message published to topics are intercepted.
> > > > Why this doesn't intercept *CONNECT* message ?
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context: http://activemq.2283324.n4.
> > > > nabble.com/Intercept-mqtt-client-connection-tp4729594.html
> > > > Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> > > >
> > >
> > >
> > >
> > > --
> > > Otavio R. Piske
> > > Messaging Quality Assurance Engineer
> > >
> >
>
>
>
> --
> Otavio R. Piske
> Messaging Quality Assurance Engineer
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Jiri Danek
In reply to this post by Justin Bertram
On Mon, Aug 14, 2017 at 7:29 PM, Justin Bertram <[hidden email]> wrote:

> > I believe it's because it's not implemented.
>
> Agreed.  It looks to me like only the publish packets are intercepted


I've been wondering, why are they called "packets"? They are not the IP
packets, so why reuse the word? I haven't seen this answered anywhere.
--
Jiří Daněk
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Justin Bertram
When the broker was first developed it only supported the core protocol.
The client/server would exchange objects which
implement org.apache.activemq.artemis.core.protocol.core.Packet.
Interceptors would intercept packet implementations.  That terminology has
stuck when referring to other protocols even though those protocols don't
use core packets.

Hope that helps...


Justin

On Mon, Aug 14, 2017 at 2:14 PM, Jiri Danek <[hidden email]> wrote:

> On Mon, Aug 14, 2017 at 7:29 PM, Justin Bertram <[hidden email]>
> wrote:
>
> > > I believe it's because it's not implemented.
> >
> > Agreed.  It looks to me like only the publish packets are intercepted
>
>
> I've been wondering, why are they called "packets"? They are not the IP
> packets, so why reuse the word? I haven't seen this answered anywhere.
> --
> Jiří Daněk
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

aragoubi
In reply to this post by Otavio Piske
I tried to add the modification to the code.
I imported all the project, then I tried to compile the artemis-mqtt-project in order to get .class files.
I tried also to generate a jar file.
But It doesn't work. I get a lot of error when I try to import all projects in eclipse.
Do you have an idea of how to update the MQTTProtocolHandler class without importing the full project ?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

clebertsuconic
Maybe you could look at the new broker interceptor that cshanon wrote ?
Maybe you could add needed features there. Or are you looking at lower
level protocol interception ?

On Wed, Aug 16, 2017 at 11:55 AM aragoubi <[hidden email]> wrote:

> I tried to add the modification to the code.
> I imported all the project, then I tried to compile the
> artemis-mqtt-project
> in order to get .class files.
> I tried also to generate a jar file.
> But It doesn't work. I get a lot of error when I try to import all projects
> in eclipse.
> Do you have an idea of how to update the MQTTProtocolHandler class without
> importing the full project ?
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Artemis-Intercept-mqtt-client-connection-tp4729594p4729708.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
--
Clebert Suconic
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

aragoubi
I want to intercept clients when trying to connect in order to do some checks before allowing them to connect.
How could I add needed features to cshanon broker interceptor?
Is cshanon broker interceptor different from the interceptor of Artemis 2.1.0 ?
I don't have any idea about cshanon broker interceptor.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Justin Bertram
In reply to this post by aragoubi
Assuming you've got the Artemis repo from GitHub cloned locally you can
just do this:

  git checkout master
  git cherry-pick 48b9573c66d428722fab172290865b986573f764
  mvn clean install -Prelease

Ideally you could just do the cherry-pick on top of the 2.2.0 branch, but
there's a conflict based on another change that's in master but not in
2.2.0.  The built broker will be in the artemis-distribution/target
directory.

Aside from that, you can use the server plugin functionality that Clebert
mentioned.  There's more information about it in the documentation [1].


Justin

[1] http://activemq.apache.org/artemis/docs/latest/broker-plugins.html

On Wed, Aug 16, 2017 at 10:53 AM, aragoubi <[hidden email]> wrote:

> I tried to add the modification to the code.
> I imported all the project, then I tried to compile the
> artemis-mqtt-project
> in order to get .class files.
> I tried also to generate a jar file.
> But It doesn't work. I get a lot of error when I try to import all projects
> in eclipse.
> Do you have an idea of how to update the MQTTProtocolHandler class without
> importing the full project ?
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.
> nabble.com/Artemis-Intercept-mqtt-client-connection-tp4729594p4729708.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

Justin Bertram
I forgot to mention that you'll need to add Otavio's repo as a remote to be
able to get his commit for the cherry-pick.  You can do that like so:

  git remote add orpiske https://github.com/orpiske/activemq-artemis.git


Justin

On Thu, Aug 17, 2017 at 8:14 AM, Justin Bertram <[hidden email]> wrote:

> Assuming you've got the Artemis repo from GitHub cloned locally you can
> just do this:
>
>   git checkout master
>   git cherry-pick 48b9573c66d428722fab172290865b986573f764
>   mvn clean install -Prelease
>
> Ideally you could just do the cherry-pick on top of the 2.2.0 branch, but
> there's a conflict based on another change that's in master but not in
> 2.2.0.  The built broker will be in the artemis-distribution/target
> directory.
>
> Aside from that, you can use the server plugin functionality that Clebert
> mentioned.  There's more information about it in the documentation [1].
>
>
> Justin
>
> [1] http://activemq.apache.org/artemis/docs/latest/broker-plugins.html
>
> On Wed, Aug 16, 2017 at 10:53 AM, aragoubi <[hidden email]> wrote:
>
>> I tried to add the modification to the code.
>> I imported all the project, then I tried to compile the
>> artemis-mqtt-project
>> in order to get .class files.
>> I tried also to generate a jar file.
>> But It doesn't work. I get a lot of error when I try to import all
>> projects
>> in eclipse.
>> Do you have an idea of how to update the MQTTProtocolHandler class without
>> importing the full project ?
>>
>>
>>
>> --
>> View this message in context: http://activemq.2283324.n4.nab
>> ble.com/Artemis-Intercept-mqtt-client-connection-tp4729594p4729708.html
>> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intercept mqtt client connection

aragoubi
Finally, I succeeded, I compiled project with modification, and replaced the jar into artemis lib folder, and now the broker is able to intercept mqtt connection.
Thank you for your help and suggestions.
Loading...