Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smack XMPP: Can't login to openfire server: "SASLErrorException: SASLError using DIGEST-MD5: not-authorized"

Tags:

java

xmpp

smack

I am trying to create a basic connection and login to an Openfire server that I have installed. I have the following user in my users database which I created through the Openfire web admin interface:

User: user
Password: 12345678

I can connect fine to the server as the connection returns true in my sout. The problem is when it tries to log in I get the following error:

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

I have the following code:

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

If anyone can correct what I am doing wrong I would be really grateful.

I have also tried the username as the email would be for example

[email protected]
or
user@localhost
like image 345
DeanMWake Avatar asked Mar 19 '15 17:03

DeanMWake


1 Answers

I finally managed to find the answer to this. The problem (possibly not even a problem) was that the authentication methods weren't set in the server config and as default allowed all methods. The first one chosen in java seems to be DIGEST-MD5 which was what was causing the errors. To fix this I added:

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

before the last closing tag of the openfire.xml found in the config folder of the server. This can also be changed in the ofproperty database table for the column called sasl.mechs.

Hopefully this helps someone (possibly me) in the future.

P.S. this is unsecure if not using SSL (port 5223 by default)

like image 93
DeanMWake Avatar answered Oct 18 '22 01:10

DeanMWake