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