Overview | Package | Class | Tree | Deprecated | Index | Help
| Openfire 3.4.3 Javadoc
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jivesoftware.openfire.user
Class JDBCUserProvider

    java.lang.Object
      org.jivesoftware.openfire.user.JDBCUserProvider

All Implemented Interfaces:
  UserProvider

    public class JDBCUserProvider

extends Object
implements UserProvider

The JDBC user provider allows you to use an external database to define the users. It is best used with the JDBCAuthProvider & JDBCGroupProvider to provide integration between your external system and Openfire. All data is treated as read-only so any set operations will result in an exception.

For the seach facility, the SQL will be constructed from the SQL in the search section below, as well as the usernameField, the nameField and the emailField.

To enable this provider, set the following in the XML configuration file:

     <provider>
         <user>
             <className>org.jivesoftware.openfire.user.JDBCUserProvider</className>
         </user>
     </provider>

Then you need to set your driver, connection string and SQL statements:

     <jdbcProvider>
         <driver>com.mysql.jdbc.Driver</driver>
         <connectionString>jdbc:mysql://localhost/dbname?user=username&password=secret</connectionString>
     </jdbcProvider>

     <jdbcUserProvider>
          <loadUserSQL>SELECT name,email FROM myUser WHERE user = ?</loadUserSQL>
          <userCountSQL>SELECT COUNT(*) FROM myUser</userCountSQL>
          <allUsersSQL>SELECT user FROM myUser</allUsersSQL>
          <searchSQL>SELECT user FROM myUser WHERE</searchSQL>
          <usernameField>myUsernameField</usernameField>
          <nameField>myNameField</nameField>
          <emailField>mymailField</emailField>
     </jdbcUserProvider>

Author:
  Huw Richards huw.richards@gmail.com

Constructor Summary
`JDBCUserProvider()` Constructs a new JDBC user provider.

Method Summary
`User` | `createUser(String username, String password, String name, String email)` Creates a new user.
`void` | `deleteUser(String username)` Delets a user.
`Collection<User>` | `findUsers(Set<String> fields, String query)` Searches for users based on a set of fields and a query string.
`Collection<User>` | `findUsers(Set<String> fields, String query, int startIndex, int numResults)` Searches for users based on a set of fields and a query string.
`Set<String>` | `getSearchFields()` Returns the set of fields that can be used for searching for users.
`int` | `getUserCount()` Returns the number of users in the system.
`Collection<String>` | `getUsernames()` Returns an unmodifiable Collection of usernames of all users in the system.
`Collection<User>` | `getUsers()` Returns an unmodifiable Collections of all users in the system.
`Collection<User>` | `getUsers(int startIndex, int numResults)` Returns an unmodifiable Collections of users in the system within the specified range.
`boolean` | `isReadOnly()` Returns true if this UserProvider is read-only.
`User` | `loadUser(String username)` Loads the specified user by username.
`void` | `setCreationDate(String username, Date creationDate)` Sets the date the user was created.
`void` | `setEmail(String username, String email)` Sets the user's email address.
`void` | `setModificationDate(String username, Date modificationDate)` Sets the date the user was last modified.
`void` | `setName(String username, String name)` Sets the user's name.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### JDBCUserProvider

    public JDBCUserProvider()

  Constructs a new JDBC user provider.

Method Detail

### loadUser

    public User loadUser(String username)
                  throws UserNotFoundException

  Description copied from interface: `UserProvider`
  Loads the specified user by username.

  Specified by:
    `loadUser` in interface `UserProvider`
  Parameters:
    `username` - the username
  Returns:
    the User.
  Throws:
    `UserNotFoundException` - if the User could not be loaded.

### getUserCount

    public int getUserCount()

  Description copied from interface: `UserProvider`
  Returns the number of users in the system.

  Specified by:
    `getUserCount` in interface `UserProvider`
  Returns:
    the total number of users.

### getUsers

    public Collection<User> getUsers()

  Description copied from interface: `UserProvider`
  Returns an unmodifiable Collections of all users in the system. The `UserCollection` class can be used to assist in the implementation of this method. It takes a String [] of usernames and presents it as a Collection of User objects (obtained with calls to `UserManager.getUser(String)`.

  Specified by:
    `getUsers` in interface `UserProvider`
  Returns:
    an unmodifiable Collection of all users.

### getUsernames

    public Collection<String> getUsernames()

  Description copied from interface: `UserProvider`
  Returns an unmodifiable Collection of usernames of all users in the system.

  Specified by:
    `getUsernames` in interface `UserProvider`
  Returns:
    an unmodifiable Collection of all usernames in the system.

### getUsers

    public Collection<User> getUsers(int startIndex,
                                     int numResults)

  Description copied from interface: `UserProvider`
  Returns an unmodifiable Collections of users in the system within the specified range. The `UserCollection` class can be used to assist in the implementation of this method. It takes a String [] of usernames and presents it as a Collection of User objects (obtained with calls to `UserManager.getUser(String)`.

  It is possible that the number of results returned will be less than that specified by `numResults` if `numResults` is greater than the number of records left to display.

  Specified by:
    `getUsers` in interface `UserProvider`
  Parameters:
    `startIndex` - the beginning index to start the results at.
    `numResults` - the total number of results to return.
  Returns:
    an unmodifiable Collection of users within the specified range.

### createUser

    public User createUser(String username,
                           String password,
                           String name,
                           String email)
                    throws UserAlreadyExistsException

  Description copied from interface: `UserProvider`
  Creates a new user. This method should throw an UnsupportedOperationException if this operation is not supporte by the backend user store.

  Specified by:
    `createUser` in interface `UserProvider`
  Parameters:
    `username` - the username.
    `password` - the plain-text password.
    `name` - the user's name, which can be `null`.
    `email` - the user's email address, which can be `null`.
  Returns:
    a new User.
  Throws:
    `UserAlreadyExistsException` - if the username is already in use.

### deleteUser

    public void deleteUser(String username)

  Description copied from interface: `UserProvider`
  Delets a user. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `deleteUser` in interface `UserProvider`
  Parameters:
    `username` - the username to delete.

### setName

    public void setName(String username,
                        String name)
                 throws UserNotFoundException

  Description copied from interface: `UserProvider`
  Sets the user's name. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `setName` in interface `UserProvider`
  Parameters:
    `username` - the username.
    `name` - the name.
  Throws:
    `UserNotFoundException` - if the user could not be found.

### setEmail

    public void setEmail(String username,
                         String email)
                  throws UserNotFoundException

  Description copied from interface: `UserProvider`
  Sets the user's email address. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `setEmail` in interface `UserProvider`
  Parameters:
    `username` - the username.
    `email` - the email address.
  Throws:
    `UserNotFoundException` - if the user could not be found.

### setCreationDate

    public void setCreationDate(String username,
                                Date creationDate)
                         throws UserNotFoundException

  Description copied from interface: `UserProvider`
  Sets the date the user was created. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `setCreationDate` in interface `UserProvider`
  Parameters:
    `username` - the username.
    `creationDate` - the date the user was created.
  Throws:
    `UserNotFoundException` - if the user could not be found.

### setModificationDate

    public void setModificationDate(String username,
                                    Date modificationDate)
                             throws UserNotFoundException

  Description copied from interface: `UserProvider`
  Sets the date the user was last modified. This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `setModificationDate` in interface `UserProvider`
  Parameters:
    `username` - the username.
    `modificationDate` - the date the user was last modified.
  Throws:
    `UserNotFoundException` - if the user could not be found.

### findUsers

    public Collection<User> findUsers(Set<String> fields,
                                      String query)
                               throws UnsupportedOperationException

  Description copied from interface: `UserProvider`
  Searches for users based on a set of fields and a query string. The fields must be taken from the values returned by `UserProvider.getSearchFields()`. The query can include wildcards. For example, a search on the field "Name" with a query of "Ma*" might return user's with the name "Matt", "Martha" and "Madeline".

  This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `findUsers` in interface `UserProvider`
  Parameters:
    `fields` - the fields to search on.
    `query` - the query string.
  Returns:
    a Collection of users that match the search.
  Throws:
    `UnsupportedOperationException` - if the provider does not support the operation (this is an optional operation).

### findUsers

    public Collection<User> findUsers(Set<String> fields,
                                      String query,
                                      int startIndex,
                                      int numResults)
                               throws UnsupportedOperationException

  Description copied from interface: `UserProvider`
  Searches for users based on a set of fields and a query string. The fields must be taken from the values returned by `UserProvider.getSearchFields()`. The query can include wildcards. For example, a search on the field "Name" with a query of "Ma*" might return user's with the name "Matt", "Martha" and "Madeline".

  The startIndex and numResults parameters are used to page through search results. For example, if the startIndex is 0 and numResults is 10, the first 10 search results will be returned. Note that numResults is a request for the number of results to return and that the actual number of results returned may be fewer.

  This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `findUsers` in interface `UserProvider`
  Parameters:
    `fields` - the fields to search on.
    `query` - the query string.
    `startIndex` - the starting index in the search result to return.
    `numResults` - the number of users to return in the search result.
  Returns:
    a Collection of users that match the search.
  Throws:
    `UnsupportedOperationException` - if the provider does not support the operation (this is an optional operation).

### getSearchFields

    public Set<String> getSearchFields()
                                throws UnsupportedOperationException

  Description copied from interface: `UserProvider`
  Returns the set of fields that can be used for searching for users. Each field returned must support wild-card and keyword searching. For example, an implementation might send back the set {"Username", "Name", "Email"}. Any of those three fields can then be used in a search with the `UserProvider.findUsers(Set,String)` method.

  This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.

  Specified by:
    `getSearchFields` in interface `UserProvider`
  Returns:
    the valid search fields.
  Throws:
    `UnsupportedOperationException` - if the provider does not support the operation (this is an optional operation).

### isReadOnly

    public boolean isReadOnly()

  Description copied from interface: `UserProvider`
  Returns true if this UserProvider is read-only. When read-only, users can not be created, deleted, or modified.

  Specified by:
    `isReadOnly` in interface `UserProvider`
  Returns:
    true if the user provider is read-only.

Overview | Package | Class | Tree | Deprecated | Index | Help
| Openfire 3.4.3 Javadoc
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2007 Jive Software.