Search code examples
androidxmppchatejabberdsmack

Disable user login from multiple devices at the sametime, in Ejabberd/XMPP


Environment:

Ejabberd Version : 16.04

Smack-android-4.1.0

I'm working on an Android chat application. Currently, same user credentials can be used login from multiple devices.

The current scenario is as follows:

1. User logs in into the app in device A
2. Using the same username and password, the user logs successfully into the app in device B
3. Now device A says, it is disconnected, but continue the chat in device B

However, according to the given requirement, it should behave like this:

1. User logs in into the app in device A
2. Using the same username and password, when the user tries to log in from device B, it should not allow it. 
(Since he is already logged in from device A)

Would be glad to hear your solutions/ideas on this. Thanks in advance.


Solution

  • So I managed to resolve the problem using the option resource_conflict

    According to Ejabberd Configuring Docs

    The option resource_conflict defines the action when a client attempts to login to an account with a resource that is already connected. The option syntax is:

    resource_conflict: setresource|closenew|closeold: The possible values match exactly the three possibilities described in XMPP Core: section 7.7.2.2. The default value is closeold. If the client uses old Jabber Non-SASL authentication (XEP-0078), then this option is not respected, and the action performed is closeold.

    So open ejabberd.yml and add the following line to that file.

    resource_conflict: closenew 
    

    Then restart the ejabberd server.

    Now it will disallow the resource binding attempt of the newly connecting client and maintain the session of the currently connected client.

    References:

    1. https://www.rfc-editor.org/rfc/rfc6120#section-7.7.2.2
    2. Read @rubycon's answer on this- https://stackoverflow.com/a/51860779/5361779