簡體   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