Example to create custom UserProvider

This example shows you how to make your own UserProvider implementation:

package org.jivesoftware.openfire.user;

import java.util.Collection;

import java.util.Date;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Iterator;

import java.util.Set;

import java.util.TreeSet;

import org.jivesoftware.openfire.auth.AuthFactory;

import org.jivesoftware.util.JiveGlobals;

public class MyUserProvider implements UserProvider {

HashMap();

int endIndex = startIndex+numResults;

int i=0;

for (Iterator iter = userNames.iterator(); iter.hasNext();i++) {

if((i<=startIndex)&&(i>=endIndex))

{

String userName = (String) iter.next();

users.add(userHashMap.get(userName));

}

}

return users;

}

public boolean isNameRequired() {

return false;

}

public boolean isReadOnly() {

return false;

}

public User loadUser(String username) throws UserNotFoundException {

User user = userHashMap.get(username);

if((user==null)&&(username.equals(“admin”)))

{

user = createNewUser(username,username,"vishawjeet@vishawjeet.co.cc");

}

if(user==null)

throw new UserNotFoundException(“User Not Found”);

return user;

}

public void setCreationDate(String username, Date creationDate)

throws UserNotFoundException {

User user=loadUser(username);

}

public void setEmail(String username, String email)

throws UserNotFoundException {

User user=loadUser(username);

}

public void setModificationDate(String username, Date modificationDate)

throws UserNotFoundException {

User user=loadUser(username);

}

public void setName(String username, String name)

throws UserNotFoundException {

User user = loadUser(username);

}

}

Configuring openfire.xml to use your custom UserProvider make entry like this in openfire.xml

for my example it is like:

I want to add email ID as user name in openfire. I’m able to add manually. however when i add the user email in the add to groups roster, it throes an error stating that admin\405cexample.com does not exist. which file in the source code should I modify in order to resolve this problem…openfire works fine with just the usernames before the @ symbol. I’m using SQL 2000 on server 2003 with openfire 3.5.2 and spark as client.

I have a question about User specific context in UserProvider

I’m building a custom AuthProvider and UserProvider to connect my application’s user tables (and group tables, so GroupProvider is next) to OpenFire. What I’m trying to understand (from looking at the source of JDBCUserProvider, and the UserProvider interface) how do I run a findUsers query if the total scope of my query will change based on who I am logged in as. If findUsers took as a parameter the current authenticated user I could factor it in to my select statement, but the interface seems to treat any body of users part of one big pool, unless, (and this is where my question comes from) I don’t understand it. What is missing from my understanding? Do I limit scope though the Group provider? if so how to I factor in the group information to my UserPorvider search or is that not what OpenFire is designed to do.