Search code examples
javaxmppsmackopenfireuser-registration

Can't register new users on OpenFire using Smack. What do these stanzas mean?


I'm using the Android version of the Smack API and developing a client that auto-registers itself in case it was not previously registered.

Well, if I manually register the user and login with the client, everything works. But I can't make the client creating a new user. The piece of code is the following:

try {
    conn1.connect();
    // (Try to) Log into the server
    try{
        conn1.login(imei, XMPP_ACCOUNT_PASSWORD);
    }catch (XMPPException ex){
        // Probably not registered
        createdAccount = checkAndRegister(conn1);
    }
    if (createdAccount){
        conn1.login(imei, XMPP_ACCOUNT_PASSWORD);
        ChatManager chatmanager = conn1.getChatManager();
        serverConversation = chatmanager.createChat(SERVER_USERNAME_FULL, this);
        serverConversation.addMessageListener(this);                
} catch (XMPPException e) {
    Log.e(TAG, "Error al comunicarse con XMPP.");
    e.printStackTrace();
}

public boolean checkAndRegister(XMPPConnection currentConn){
    if (!currentConn.isAuthenticated()){
        AccountManager acManager = currentConn.getAccountManager();
        try {
            acManager.createAccount(imei, XMPP_ACCOUNT_PASSWORD);
        } catch (XMPPException e) {
            Log.e(TAG, "No se puede autoregistrar la cuenta de XMPP. " + e.getLocalizedMessage());
            return false;
        }
        return true;
    }else{
        return true;
    }
}

And here is the trace os stanzas I got from the server log. I suspect these specific 4, illustrate the whole process, but correct me if you think I'm wrong.

<packet xmlns="http://www.jivesoftware.org" streamID="c0057471" status="connected" timestamp="oct 25,2011 04:43:52:207 PM">
  <iq xmlns="" id="D1Dq5-2" to="www.fundacionvf.es" type="get">
    <query xmlns="jabber:iq:register" />
  </iq>
</packet>
<packet xmlns="http://www.jivesoftware.org" streamID="c0057471" status="connected" timestamp="oct 25, 2011 04:43:52:208 PM">
  <iq xmlns="" type="result" id="D1Dq5-2">
    <query xmlns="jabber:iq:register">
      <username />
      <password />
      <email />
      <name />
      <x xmlns="jabber:x:data" type="form">
        <title>XMPP Client Registration</title>
        <instructions>Please providethe following information</instructions>
        <field var="FORM_TYPE" type="hidden">
          <value>jabber:iq:register</value>
        </field>
        <field var="username" type="text-single" label="Username">
          <required />
        </field>
        <field var="name" type="text-single" label="Full name" />
        <field var="email" type="text-single" label="Email" />
        <field var="password" type="text-private" label="Password">
          <required />
        </field>
      </x>
    </query>
  </iq>
</packet>
<packet xmlns="http://www.jivesoftware.org" streamID="c0057471" status="connected" timestamp="oct 25, 2011 04:43:52:265 PM">
  <iq xmlns="" id="D1Dq5-3" to="www.fundacionvf.es" type="set">
    <query xmlns="jabber:iq:register">
      <email />
      <password />
      <username />
      <name />
    </query>
  </iq>
</packet>
<packet xmlns="http://www.jivesoftware.org" streamID="c0057471" status="connected" timestamp="oct 25, 2011 04:43:52:265 PM">
  <iq xmlns="" type="error" id="D1Dq5-3" to="www.fundacionvf.es/c0057471">
    <query xmlns="jabber:iq:register">
      <email />
      <password />
      <username />
      <name />
    </query>
    <error code="500" type="wait">
      <internal-server-error xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
    </error>
  </iq>
</packet>

So, if my suspicion is right, the last error tag should be the key of the problem, but what that does mean?

PD: Of course I made sure to enable client-side registration on the OpenFire config.
Edit: After further research on my issue, a couple of questions came up:
1. Is the <iq xmlns="" id="D1Dq5-3" to="www.fundacionvf.es" type="set"> tag supposed to contain the registration information?
2. Are all the fields listed on the second stanza compulsory for registration?

Regards.


Solution

    1. Yes, or as an alternative the form presented in the first packet could be submitted back to the server as shown in the Use Cases in http://xmpp.org/extensions/xep-0077.html
    2. The spec says the client queries the server for the required fields so probably yes. But one could guess that only the ones that are tagged as required in the form are really required by your server implementation otherwise the difference would be senseless.