public class JDBCUserProvider extends Object implements UserProvider
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 system properties:
provider.user.className = org.jivesoftware.openfire.user.JDBCUserProvider
Then you need to set your driver, connection string and SQL statements:
jdbcProvider.driver = com.mysql.jdbc.Driver
jdbcProvider.connectionString = jdbc:mysql://localhost/dbname?user=username&password=secret
jdbcUserProvider.loadUserSQL = SELECT name,email FROM myUser WHERE user = ?
jdbcUserProvider.userCountSQL = SELECT COUNT(*) FROM myUser
jdbcUserProvider.allUsersSQL = SELECT user FROM myUser
jdbcUserProvider.searchSQL = SELECT user FROM myUser WHERE
jdbcUserProvider.usernameField = myUsernameField
jdbcUserProvider.nameField = myNameField
jdbcUserProvider.emailField = mymailField
jdbcUserProvider.useConnectionProvider = true
Constructor and Description |
---|
JDBCUserProvider()
Constructs a new JDBC user provider.
|
Modifier and Type | Method and Description |
---|---|
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 |
isEmailRequired()
Returns true if this UserProvider requires an email address to be set on User objects.
|
boolean |
isNameRequired()
Returns true if this UserProvider requires a name to be set on User objects.
|
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.
|
public User loadUser(String username) throws UserNotFoundException
UserProvider
loadUser
in interface UserProvider
username
- the usernameUserNotFoundException
- if the User could not be loaded.public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException
UserProvider
createUser
in interface UserProvider
username
- the username.password
- the plain-text password.name
- the user's name, which can be null
, unless isNameRequired is set to true.email
- the user's email address, which can be null
, unless isEmailRequired is set to true.UserAlreadyExistsException
- if the username is already in use.public void deleteUser(String username)
UserProvider
deleteUser
in interface UserProvider
username
- the username to delete.public int getUserCount()
UserProvider
getUserCount
in interface UserProvider
public Collection<User> getUsers()
UserProvider
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)
.getUsers
in interface UserProvider
public Collection<String> getUsernames()
UserProvider
getUsernames
in interface UserProvider
public Collection<User> getUsers(int startIndex, int numResults)
UserProvider
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.
getUsers
in interface UserProvider
startIndex
- the beginning index to start the results at.numResults
- the total number of results to return.public void setName(String username, String name) throws UserNotFoundException
UserProvider
setName
in interface UserProvider
username
- the username.name
- the name.UserNotFoundException
- if the user could not be found.public void setEmail(String username, String email) throws UserNotFoundException
UserProvider
setEmail
in interface UserProvider
username
- the username.email
- the email address.UserNotFoundException
- if the user could not be found.public void setCreationDate(String username, Date creationDate) throws UserNotFoundException
UserProvider
setCreationDate
in interface UserProvider
username
- the username.creationDate
- the date the user was created.UserNotFoundException
- if the user could not be found.public void setModificationDate(String username, Date modificationDate) throws UserNotFoundException
UserProvider
setModificationDate
in interface UserProvider
username
- the username.modificationDate
- the date the user was last modified.UserNotFoundException
- if the user could not be found.public Set<String> getSearchFields() throws UnsupportedOperationException
UserProvider
UserProvider.findUsers(Set,String)
method.This method should throw an UnsupportedOperationException if this operation is not supported by the backend user store.
getSearchFields
in interface UserProvider
UnsupportedOperationException
- if the provider does not
support the operation (this is an optional operation).public Collection<User> findUsers(Set<String> fields, String query) throws UnsupportedOperationException
UserProvider
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.
findUsers
in interface UserProvider
fields
- the fields to search on.query
- the query string.UnsupportedOperationException
- if the provider does not
support the operation (this is an optional operation).public Collection<User> findUsers(Set<String> fields, String query, int startIndex, int numResults) throws UnsupportedOperationException
UserProvider
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.
findUsers
in interface UserProvider
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.UnsupportedOperationException
- if the provider does not
support the operation (this is an optional operation).public boolean isReadOnly()
UserProvider
isReadOnly
in interface UserProvider
public boolean isNameRequired()
UserProvider
isNameRequired
in interface UserProvider
public boolean isEmailRequired()
UserProvider
isEmailRequired
in interface UserProvider
Copyright © 2003–2020 Ignite Realtime. All rights reserved.