Commit d9de1384 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10864 b35dd754-fafc-0310-a699-88a17e54d16e
parent 25fb1ef8
......@@ -44,6 +44,13 @@ import java.sql.*;
* <li><tt>jdbcAuthProvider.setPasswordSQL = UPDATE user_account SET password=? WHERE username=?</tt></li>
* </ul>
*
* In order to use the configured JDBC connection provider do not use a JDBC
* connection string, set the following property
*
* <ul>
* <li><tt>jdbcAuthProvider.useConnectionProvider = true</tt></li>
* </ul>
*
* The passwordType setting tells Openfire how the password is stored. Setting the value
* is optional (when not set, it defaults to "plain"). The valid values are:<ul>
* <li>{@link PasswordType#plain plain}
......@@ -61,6 +68,7 @@ public class JDBCAuthProvider implements AuthProvider {
private String setPasswordSQL;
private PasswordType passwordType;
private boolean allowUpdate;
private boolean useConnectionProvider;
/**
* Constructs a new JDBC authentication provider.
......@@ -74,16 +82,20 @@ public class JDBCAuthProvider implements AuthProvider {
JiveGlobals.migrateProperty("jdbcAuthProvider.setPasswordSQL");
JiveGlobals.migrateProperty("jdbcAuthProvider.allowUpdate");
// Load the JDBC driver and connection string.
String jdbcDriver = JiveGlobals.getProperty("jdbcProvider.driver");
try {
Class.forName(jdbcDriver).newInstance();
}
catch (Exception e) {
Log.error("Unable to load JDBC driver: " + jdbcDriver, e);
return;
useConnectionProvider = JiveGlobals.getBooleanProperty("jdbcAuthProvider.useConnectionProvider");
if (!useConnectionProvider) {
// Load the JDBC driver and connection string.
String jdbcDriver = JiveGlobals.getProperty("jdbcProvider.driver");
try {
Class.forName(jdbcDriver).newInstance();
}
catch (Exception e) {
Log.error("Unable to load JDBC driver: " + jdbcDriver, e);
return;
}
connectionString = JiveGlobals.getProperty("jdbcProvider.connectionString");
}
connectionString = JiveGlobals.getProperty("jdbcProvider.connectionString");
// Load SQL statements.
passwordSQL = JiveGlobals.getProperty("jdbcAuthProvider.passwordSQL");
......@@ -223,6 +235,12 @@ public class JDBCAuthProvider implements AuthProvider {
return (passwordSQL != null && passwordType == PasswordType.plain);
}
private Connection getConnection() throws SQLException {
if (useConnectionProvider)
return DbConnectionManager.getConnection();
return DriverManager.getConnection(connectionString);
}
/**
* Returns the value of the password field. It will be in plain text or hashed
* format, depending on the password type.
......@@ -248,7 +266,7 @@ public class JDBCAuthProvider implements AuthProvider {
}
}
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(passwordSQL);
pstmt.setString(1, username);
......@@ -287,7 +305,7 @@ public class JDBCAuthProvider implements AuthProvider {
}
}
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(setPasswordSQL);
pstmt.setString(1, username);
if (passwordType == PasswordType.md5) {
......
......@@ -47,6 +47,13 @@ import java.util.List;
* <li><tt>jdbcGroupProvider.loadAdminsSQL = SELECT username FORM myGroupUsers WHERE groupName=? AND isAdmin='Y'</tt></li>
* </ul>
*
* In order to use the configured JDBC connection provider do not use a JDBC
* connection string, set the following property
*
* <ul>
* <li><tt>jdbcGroupProvider.useConnectionProvider = true</tt></li>
* </ul>
*
* @author David Snopek
*/
public class JDBCGroupProvider implements GroupProvider {
......@@ -59,6 +66,7 @@ public class JDBCGroupProvider implements GroupProvider {
private String userGroupsSQL;
private String loadMembersSQL;
private String loadAdminsSQL;
private boolean useConnectionProvider;
private XMPPServer server = XMPPServer.getInstance();
......@@ -76,16 +84,20 @@ public class JDBCGroupProvider implements GroupProvider {
JiveGlobals.migrateProperty("jdbcGroupProvider.loadMembersSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.loadAdminsSQL");
// Load the JDBC driver and connection string.
String jdbcDriver = JiveGlobals.getProperty("jdbcProvider.driver");
try {
Class.forName(jdbcDriver).newInstance();
}
catch (Exception e) {
Log.error("Unable to load JDBC driver: " + jdbcDriver, e);
return;
useConnectionProvider = JiveGlobals.getBooleanProperty("jdbcGroupProvider.useConnectionProvider");
if (!useConnectionProvider) {
// Load the JDBC driver and connection string.
String jdbcDriver = JiveGlobals.getProperty("jdbcProvider.driver");
try {
Class.forName(jdbcDriver).newInstance();
}
catch (Exception e) {
Log.error("Unable to load JDBC driver: " + jdbcDriver, e);
return;
}
connectionString = JiveGlobals.getProperty("jdbcProvider.connectionString");
}
connectionString = JiveGlobals.getProperty("jdbcProvider.connectionString");
// Load SQL statements
groupCountSQL = JiveGlobals.getProperty("jdbcGroupProvider.groupCountSQL");
......@@ -116,6 +128,12 @@ public class JDBCGroupProvider implements GroupProvider {
throw new UnsupportedOperationException();
}
private Connection getConnection() throws SQLException {
if (useConnectionProvider)
return DbConnectionManager.getConnection();
return DriverManager.getConnection(connectionString);
}
public Group getGroup(String name) throws GroupNotFoundException {
String description = null;
......@@ -123,7 +141,7 @@ public class JDBCGroupProvider implements GroupProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(descriptionSQL);
pstmt.setString(1, name);
rs = pstmt.executeQuery();
......@@ -151,7 +169,7 @@ public class JDBCGroupProvider implements GroupProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
if (adminsOnly) {
if (loadAdminsSQL == null) {
return members;
......@@ -216,7 +234,7 @@ public class JDBCGroupProvider implements GroupProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(groupCountSQL);
rs = pstmt.executeQuery();
if (rs.next()) {
......@@ -243,7 +261,7 @@ public class JDBCGroupProvider implements GroupProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(allGroupsSQL);
rs = pstmt.executeQuery();
while (rs.next()) {
......@@ -265,7 +283,7 @@ public class JDBCGroupProvider implements GroupProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = DbConnectionManager.createScrollablePreparedStatement(con, allGroupsSQL);
rs = pstmt.executeQuery();
DbConnectionManager.scrollResultSet(rs, start);
......@@ -290,7 +308,7 @@ public class JDBCGroupProvider implements GroupProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(userGroupsSQL);
pstmt.setString(1, server.isLocal(user) ? user.getNode() : user.toString());
rs = pstmt.executeQuery();
......@@ -368,4 +386,4 @@ public class JDBCGroupProvider implements GroupProvider {
public boolean isSearchSupported() {
return false;
}
}
\ No newline at end of file
}
......@@ -52,6 +52,14 @@ import java.util.Date;
* <li><tt>jdbcUserProvider.emailField = mymailField</tt></li>
* </ul>
*
* In order to use the configured JDBC connection provider do not use a JDBC
* connection string, set the following property
*
* <ul>
* <li><tt>jdbcUserProvider.useConnectionProvider = true</tt></li>
* </ul>
*
*
* @author Huw Richards huw.richards@gmail.com
*/
public class JDBCUserProvider implements UserProvider {
......@@ -65,6 +73,7 @@ public class JDBCUserProvider implements UserProvider {
private String usernameField;
private String nameField;
private String emailField;
private boolean useConnectionProvider;
/**
* Constructs a new JDBC user provider.
......@@ -81,16 +90,20 @@ public class JDBCUserProvider implements UserProvider {
JiveGlobals.migrateProperty("jdbcUserProvider.nameField");
JiveGlobals.migrateProperty("jdbcUserProvider.emailField");
// Load the JDBC driver and connection string.
String jdbcDriver = JiveGlobals.getProperty("jdbcProvider.driver");
try {
Class.forName(jdbcDriver).newInstance();
}
catch (Exception e) {
Log.error("Unable to load JDBC driver: " + jdbcDriver, e);
return;
useConnectionProvider = JiveGlobals.getBooleanProperty("jdbcUserProvider.useConnectionProvider");
// Load the JDBC driver and connection string.
if (!useConnectionProvider) {
String jdbcDriver = JiveGlobals.getProperty("jdbcProvider.driver");
try {
Class.forName(jdbcDriver).newInstance();
}
catch (Exception e) {
Log.error("Unable to load JDBC driver: " + jdbcDriver, e);
return;
}
connectionString = JiveGlobals.getProperty("jdbcProvider.connectionString");
}
connectionString = JiveGlobals.getProperty("jdbcProvider.connectionString");
// Load database statements for user data.
loadUserSQL = JiveGlobals.getProperty("jdbcUserProvider.loadUserSQL");
......@@ -113,7 +126,7 @@ public class JDBCUserProvider implements UserProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(loadUserSQL);
pstmt.setString(1, username);
rs = pstmt.executeQuery();
......@@ -139,7 +152,7 @@ public class JDBCUserProvider implements UserProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(userCountSQL);
rs = pstmt.executeQuery();
if (rs.next()) {
......@@ -155,6 +168,12 @@ public class JDBCUserProvider implements UserProvider {
return count;
}
private Connection getConnection() throws SQLException {
if (useConnectionProvider)
return DbConnectionManager.getConnection();
return DriverManager.getConnection(connectionString);
}
public Collection<User> getUsers() {
Collection<String> usernames = getUsernames();
return new UserCollection(usernames.toArray(new String[usernames.size()]));
......@@ -166,7 +185,7 @@ public class JDBCUserProvider implements UserProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = con.prepareStatement(allUsersSQL);
rs = pstmt.executeQuery();
// Set the fetch size. This will prevent some JDBC drivers from trying
......@@ -192,7 +211,7 @@ public class JDBCUserProvider implements UserProvider {
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
pstmt = DbConnectionManager.createScrollablePreparedStatement(con, allUsersSQL);
rs = pstmt.executeQuery();
DbConnectionManager.setFetchSize(rs, startIndex + numResults);
......@@ -273,7 +292,7 @@ public class JDBCUserProvider implements UserProvider {
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
stmt = con.createStatement();
StringBuilder sql = new StringBuilder();
sql.append(searchSQL);
......@@ -348,7 +367,7 @@ public class JDBCUserProvider implements UserProvider {
Statement stmt = null;
ResultSet rs = null;
try {
con = DriverManager.getConnection(connectionString);
con = getConnection();
stmt = con.createStatement();
StringBuilder sql = new StringBuilder();
sql.append(searchSQL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment