Java 尝试使用 Smack 登录 XMPP 服务器导致 SASL“未授权”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19364704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 16:30:50  来源:igfitidea点击:

Trying to log into XMPP server using Smack results in SASL "not authorized"

javaxmppsmacksasl

提问by Shishigami

I'm trying to use Smack to log into a XMPP server. When trying to login I get the following Error :

我正在尝试使用 Smack 登录 XMPP 服务器。尝试登录时出现以下错误:

SASL authentication PLAIN failed: not-authorized

SASL 认证 PLAIN 失败:未授权

I have been able to connect and log into the server using PSI-IM with the same credentials.

我已经能够使用具有相同凭据的 PSI-IM 连接并登录到服务器。

This is what I currently have :

这是我目前拥有的:

    System.setProperty("smack.debugEnabled", "true");
    XMPPConnection.DEBUG_ENABLED = true;

    SASLAuthentication.supportSASLMechanism("PLAIN", 0);

    ConnectionConfiguration configuration = new ConnectionConfiguration("chat.bla.com", 5223);
    configuration.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    configuration.setSocketFactory(new DummySSLSocketFactory());
    configuration.setSASLAuthenticationEnabled(true);
    configuration.setDebuggerEnabled(true);
    configuration.setServiceName("bla.net");

    Connection connection = new XMPPConnection(configuration);

    try {
        connection.connect();
        connection.login("[email protected]", "blablabla");
    } catch (XMPPException e) {
        e.printStackTrace();
    }

This is the DummySSLSocketFactory I'm using : http://svn.igniterealtime.org/svn/repos/spark/tags/spark_2_5_3_s/src/java/org/jivesoftware/spark/util/DummySSLSocketFactory.java

这是我正在使用的 DummySSLSocketFactory:http://svn.igniterealtime.org/svn/repos/spark/tags/spark_2_5_3_s/src/java/org/jivesoftware/spark/util/DummySSLSocketFactory.java

I'm thinking that the problem is that I need to select 'Legacy SSL' when connecting through PSI, I'm not sure howto do that in Java though.

我在想问题是我在通过 PSI 连接时需要选择“Legacy SSL”,但我不确定如何在 Java 中做到这一点。

Thanks for any help

谢谢你的帮助

采纳答案by Flow

Try login()withoutthe domain part in the username:

尝试在用户名中login()包含域部分:

connection.login("user", "password");

not

不是

connection.login("[email protected]", "password");