hazelcast cluster with vertx when logout goes through infinite cycles

14 views
Skip to first unread message

fadel....@productionstmv.com

unread,
Feb 13, 2018, 1:56:11 PM2/13/18
to Hazelcast
Hi 

I have a strange problem with hazelcast cluster.

when logout RoutingContext.clearUser() is called in AuthHandle.authenticate then RoutingContext.reroute to restart the context is called but next it will still have the user assigned old value and it will go through the same cycle infinitely.


<code>
authProvider.authenticate(credentials, authResultHanlder -> {
   if (routingContext.user() != null) {
     routingContext.session().destroy();
routingContext.removeCookie(SESSION_COOKIE_NAME);
routingContext.clearUser();
routingContext.reroute(routingContext.request().path()); // restart current Router. It will create new session
   } else {
      // assign new user and
      // authorize(...) 
      // routingContext.next
   }
});
</code>

this code is executed inside MyAuthHandlerImpl handle method

in cluster mode, the reroute will cause this method to be called again but user will still be assigned, so it will go into infinite loops of calling. 
while in normal mode, next call the user is gone and processing goes without any problem

for now to solve the problem I did this

routingContext.session().destroy();
routingContext.removeCookie(WebConfig.SESSION_COOKIE_NAME);
routingContext.clearUser();

if (routingContext.vertx()!=null && routingContext.vertx().isClustered()) { // checking routingContext.vertx()!=null is necessary for unit test
routingContext.response().putHeader("Refresh", "0").end();
} else {
routingContext.reroute(routingContext.request().path()); // restart current Router. It will create new session
}

but this is not ideal

any thoughts about this

thanks

Alparslan Avcı

unread,
Feb 14, 2018, 7:31:50 AM2/14/18
to Hazelcast
Hello,

Why do you think the issue is caused from Hazelcast? It looks like it is related to how the authentication is handled when clustering is enabled in Vert.x.

Regards,
Alparslan

fadel....@productionstmv.com

unread,
Feb 14, 2018, 8:29:17 AM2/14/18
to Hazelcast
Hi. 
Thank you for your reply.
I couldn't see anything wrong in the code related to authentication pretty straight forward using 
userSessHandler = UserSessionHandler.create(AuthProvider.newInstance(myAuthHandlerImpl))
router.route().handler(userSessHandler);
beside adding other handlrs such as CorsHandler, cookieHandler,...
but userSessionHandler is the one causing this weird behaviour as the mentioned clearUser() doesn't seem to change the internal state of the routingContext.

Alparslan Avcı

unread,
Feb 14, 2018, 8:44:12 AM2/14/18
to Hazelcast
Hi again,

I mean that you need to ask this question in the vert.x user group (https://groups.google.com/forum/#!forum/vertx), since it is not directly related to Hazelcast. If you have any questions regarding Hazelcast itself, we will be glad to help here.

Regards,
Alparslan

fadel....@productionstmv.com

unread,
Feb 14, 2018, 8:55:14 AM2/14/18
to Hazelcast
Ah ok.

thanks for your help
Reply all
Reply to author
Forward
0 new messages