Example to create custom UserProvider

Version 6

    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: