Custom Auth Provider

Hi everybody,

Currently i’'m trying to create my own class to authnticate users via a XML-RPC webservice.

I use MySQLfor the data storage.

I want to keep MySQL as storage, but not to authenticate users (except for the admin user).

So i read the documentation and i developped a class that implements AuthProvider interface.

Here is the code :

package org.jivesoftware.wildfire.auth;

import java.io.*;

import java.util.Vector;

import java.net.URL;

import org.apache.xmlrpc.XmlRpcClient;

import org.apache.xmlrpc.XmlRpcException;

import org.jivesoftware.util.Log;

/**

  • Default AuthProvider implementation. It authenticates against the jiveUser

  • database table and supports plain text and digest authentication.

  • Because each call to authenticate() makes a database connection, the

  • results of authentication should be cached whenever possible.

  • @author Matt Tucker

*/

public class XMLRPCAuthProvider implements AuthProvider {

private static final String SERVERURL =

    "http://localhost:8080/";

public void authenticate(String username, String password) throws UnauthorizedException {

if (username == null || password == null) {

throw new UnauthorizedException();

}

username = username.trim().toLowerCase();

try {

XmlRpcClient client = new XmlRpcClient(SERVERURL);

Vector params = new Vector();

params.addElement( username );

params.addElement( password );

Vector result = (Vector) client.execute(“login”, params);

Object[] finalresult = result.toArray();

if (finalresult[0].toString() == “true”) {

Log.info("user logged: ");

}

else {

throw new UnauthorizedException();

}

}

catch (IOException e) {

Log.error("IO Exception: " + e.getMessage( ));

}

catch (XmlRpcException e) {

Log.error("Exception within XML-RPC: " + e.getMessage( ));

}

}

public void authenticate(String username, String token, String digest)

throws UnauthorizedException

{

throw new UnsupportedOperationException();

}

public boolean isPlainSupported() {

return true;

}

public boolean isDigestSupported() {

return false;

}

}

/codeI test my code in a standalone version and it works. In integrated the code within the wildfire source tree and i compiled wildfire without errors.

I added the following lines into the widlfire.xml config file :

[/code]

But it doesn’'t work, only users coming from MySQL can sign-in.

Maybe i forgot something in the configuration, or i need to modify the MySQL configuration in wildfire.xml.

I need help to understand what i’'m doing wrong …

Thanks in advance.

Message was edited by: ernieball_slinky

Message was edited by: ernieball_slinky

Message was edited by: ernieball_slinky

Hi ernieball_slinky,

Since you’'re only wanting to authenticate against your web service the provider section of your configuration file should look more like the following:

/code

Hope that helps,

Ryan

PS - When posting code use the and / code tags (without the spaces) at the beginning and end of your code so it is formatted properly.

PPS - To make things somewhat easier for yourself you can package your provider code in a jar file and place it in the lib directory of Wildifre. This way you won’'t have to compile Wildfire everytime you want to make a change to your code.

Hi Ryang,

Sorry for the code snippet in my thread i modified it to use the code markup.

Thank you for your answer. Your right, it was a mistake in wildfire.xml.

I will tag this thread as answered.

It was an error in my config file, here is the new one (a little more complicated …):

<!org.jivesoftware.wildfire.ldap.LdapUserProvider>

/code

Have a lot of fun …

Message was edited by: ernieball_slinky

Message was edited by: ernieball_slinky

Hi ernieball_slinky,

Good to hear you got it working.

Cheers,

Ryan