首页 > 解决方案 > 在不公开服务名称和主机名的情况下使用 Android XMPP Smack

问题描述

正如您在下面的示例代码中看到的,Smack 要求我提供服务名称和主机。我将 Ejabberd 与 Linux 和一个 EC2 实例一起使用。

在检查 XMPP 客户端应用程序时,我看到了使用其他 XMPP 提供商创建帐户的选项。我担心当我向公众发布我的应用程序时,我的 EC2 实例的 DNS 将使人们能够创建大量帐户,而不是直接从我的应用程序而是从任何地方创建。

我应该使用 Firebase Functions 之类的东西吗?或者类似的东西?解决这个问题的最佳方法是什么?我只是不希望主机名公开。

XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration
            .builder();
    config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    config.setServiceName(serverAddress);
    config.setHost(serverAddress);
    config.setPort(5222);
    config.setResource(context.getResources().getString(R.string.resource_name));
    config.setDebuggerEnabled(true);
    config.setSendPresence(true);
    XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true);
    XMPPTCPConnection.setUseStreamManagementDefault(true);
    mConnection = new XMPPTCPConnection(config.build());
    XMPPConnectionListener connectionListener = new XMPPConnectionListener(type);
    mConnection.addConnectionListener(connectionListener);

标签: androidamazon-ec2xmppejabberd

解决方案


仅当您在 ejabberd 配置中启用了该选项时,此帐户创建才有效。如果您使用 ProcessOne 和大多数 Linux 发行版提供的标准配置,则应该禁用它。它应该是这样的:

modules:
  # other modules stuff

  mod_register:
    ip_access: trusted_network

您的 acl 应该与此类似:

acl:
  # other irrelevant acls

  loopback:
    ip:
      - "127.0.0.0/8"
      - "::1/128"

所需的访问规则应如下所示:

access_rules:
  trusted_network:
    - allow: loopback

这都是根据配置的文档,可以在这里找到:https ://docs.ejabberd.im/admin/configuration/


推荐阅读