Smack XMPP:无法登录到openfire服务器:"SASLErrorException:SASLError使用DIGEST-MD5:未授权"

Dea*_*ake 4 java xmpp smack

我正在尝试创建一个基本连接并登录到我已安装的Openfire服务器.我通过Openfire Web管理界面创建的用户数据库中有以下用户:

User: user
Password: 12345678
Run Code Online (Sandbox Code Playgroud)

我可以很好地连接到服务器,因为连接在我的sout中返回true.问题是当它尝试登录时我收到以下错误:

org.jivesoftware.smack.sasl.SASLErrorException: SASLError using DIGEST-MD5: not-authorized
Run Code Online (Sandbox Code Playgroud)

我有以下代码:

private XMPPConnection connection;

public void connect(String serverIP) {
    try {

        System.setProperty("smack.debugEnabled", "true");
        ConnectionConfiguration config = new ConnectionConfiguration(serverIP, 5223);
        config.setDebuggerEnabled(true);
        config.setSocketFactory(new DummySSLSocketFactory());    
        config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
        config.setCompressionEnabled(true);
        connection = new XMPPTCPConnection(config);
        connection.connect();

        System.out.println("Connected: " + connection.isConnected());
        connection.login("user", "12345678");
        System.out.println("Logged in: " + connection.isAuthenticated());

    } catch (SmackException | IOException | XMPPException ex) {
        ex.printStackTrace();
    }
}

public static void main(String[] args) {
    connectionHandler test = new connectionHandler();
    test.connect("localhost");
}
Run Code Online (Sandbox Code Playgroud)

如果有人能够纠正我做错的事情,我将非常感激.

我也尝试过用户名,例如电子邮件

user@localhost.com
or
user@localhost
Run Code Online (Sandbox Code Playgroud)

Dea*_*ake 11

我终于找到了答案.问题(可能甚至不是问题)是在服务器配置中没有设置身份验证方法,并且默认允许所有方法.在java中选择的第一个似乎是DIGEST-MD5,这是造成错误的原因.要解决这个问题,我补充说

<sasl>
    <mechs> PLAIN </mechs>
</sasl>
Run Code Online (Sandbox Code Playgroud)

在服务器的config文件夹中找到的openfire.xml的最后一个结束标记之前.这也可以在ofproperty 名为的数据库表中进行更改sasl.mechs.

希望这对未来的某个人(可能是我)有所帮助.

PS如果不使用SSL(默认为端口5223),这是不安全的