繁体   English   中英

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

[英]Smack XMPP: Can't login to openfire server: “SASLErrorException: SASLError using DIGEST-MD5: not-authorized”

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

User: user
Password: 12345678

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

org.jivesoftware.smack.sasl.SASLErrorException: SASLError using DIGEST-MD5: not-authorized

我有以下代码:

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");
}

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

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

user@localhost.com
or
user@localhost

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

<sasl>
    <mechs> PLAIN </mechs>
</sasl>

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

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

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

使用DIGEST-MD5的SASLError:未经授权

这很可能是因为您没有在ConnectionConfiguration配置正确的XMPP域(/ service name)。 如果用户名或密码错误,DIGEST-MD5不仅会失败,而且如果使用了错误的XMPP域,也会失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM