我正在尝试创建一个基本连接并登录到我已安装的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
答案 0 :(得分:11)
我终于找到了答案。问题(可能甚至不是问题)是在服务器配置中没有设置身份验证方法,并且默认允许所有方法。在java中选择的第一个似乎是DIGEST-MD5,这是造成错误的原因。为了解决这个问题,我补充说:
<sasl>
<mechs> PLAIN </mechs>
</sasl>
在服务器的config文件夹中找到的openfire.xml的最后一个结束标记之前。这也可以在名为ofproperty
的列的sasl.mechs
数据库表中进行更改。
希望将来可以帮助某人(可能是我)。
P.S。如果不使用SSL(默认为端口5223)
,这是不安全的答案 1 :(得分:0)
SASLError使用DIGEST-MD5:未授权
这很可能是因为您未在ConnectionConfiguration
中配置正确的XMPP域(/服务名称)。如果用户名或密码错误,DIGEST-MD5不仅会失败,而且如果使用了错误的XMPP域,也会失败。