Commit 3d397f67 authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-610: Restore shared group support for read-only group providers (LDAP)

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13455 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6a5c1107
......@@ -32,7 +32,7 @@ import java.util.Map;
import org.dom4j.Element;
import org.dom4j.Node;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.AbstractReadOnlyGroupProvider;
import org.jivesoftware.openfire.group.AbstractGroupProvider;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupCollection;
import org.jivesoftware.openfire.group.GroupNotFoundException;
......@@ -42,7 +42,7 @@ import org.xmpp.packet.JID;
/**
* @author Daniel Henninger
*/
public class ClearspaceGroupProvider extends AbstractReadOnlyGroupProvider {
public class ClearspaceGroupProvider extends AbstractGroupProvider {
protected static final String URL_PREFIX = "socialGroupService/";
private static final String TYPE_ID_OWNER = "0";
......@@ -66,10 +66,6 @@ public class ClearspaceGroupProvider extends AbstractReadOnlyGroupProvider {
}
}
public boolean isSharingSupported() {
return true;
}
public Collection<String> getSharedGroupNames() {
// Return all social group names since every social group is a shared group
return getGroupNames();
......@@ -127,20 +123,8 @@ public class ClearspaceGroupProvider extends AbstractReadOnlyGroupProvider {
}
}
public Collection<String> search(String query) {
throw new UnsupportedOperationException("Group search is not supported");
}
public Collection<String> search(String query, int startIndex, int numResults) {
throw new UnsupportedOperationException("Group search is not supported");
}
public boolean isSearchSupported() {
return false;
}
/**
* Translate a XML respose of a group to a <code>Group</code>.
* Translate a XML response of a group to a <code>Group</code>.
*
* @param responseNode the XML representation of a CS group.
* @return the group that corresponds to the XML.
......
package org.jivesoftware.openfire.group;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.jivesoftware.database.DbConnectionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
/**
* Shared base class for Openfire GroupProvider implementations. By default
* all mutator methods throw {@link UnsupportedOperationException}. In
* addition, group search operations are disabled.
*
* Subclasses may optionally implement these capabilities, and must also
* at minimum implement the {@link GroupProvider.getGroup(String)} method.
*
* @author Tom Evans
*/
public abstract class AbstractGroupProvider implements GroupProvider {
private static final Logger Log = LoggerFactory.getLogger(AbstractGroupProvider.class);
private static final String GROUPLIST_CONTAINERS =
"SELECT groupName from ofGroupProp " +
"where name='sharedRoster.groupList' " +
"AND propValue LIKE ?";
private static final String PUBLIC_GROUPS =
"SELECT groupName from ofGroupProp " +
"WHERE name='sharedRoster.showInRoster' " +
"AND propValue='everybody'";
private static final String GROUPS_FOR_PROP =
"SELECT groupName from ofGroupProp " +
"WHERE name=? " +
"AND propValue=?";
private static final String LOAD_SHARED_GROUPS =
"SELECT groupName FROM ofGroupProp WHERE name='sharedRoster.showInRoster' " +
"AND propValue IS NOT NULL AND propValue <> 'nobody'";
private static final String LOAD_PROPERTIES =
"SELECT name, propValue FROM ofGroupProp WHERE groupName=?";
// Mutator methods disabled for read-only group providers
/**
* @throws UnsupportedOperationException
*/
public void addMember(String groupName, JID user, boolean administrator)
{
throw new UnsupportedOperationException("Cannot add members to read-only groups");
}
/**
* @throws UnsupportedOperationException
*/
public void updateMember(String groupName, JID user, boolean administrator)
{
throw new UnsupportedOperationException("Cannot update members for read-only groups");
}
/**
* @throws UnsupportedOperationException
*/
public void deleteMember(String groupName, JID user)
{
throw new UnsupportedOperationException("Cannot remove members from read-only groups");
}
/**
* Always true for a read-only provider
*/
public boolean isReadOnly() {
return true;
}
/**
* @throws UnsupportedOperationException
*/
public Group createGroup(String name) {
throw new UnsupportedOperationException("Cannot create groups via read-only provider");
}
/**
* @throws UnsupportedOperationException
*/
public void deleteGroup(String name) {
throw new UnsupportedOperationException("Cannot remove groups via read-only provider");
}
/**
* @throws UnsupportedOperationException
*/
public void setName(String oldName, String newName) throws GroupAlreadyExistsException {
throw new UnsupportedOperationException("Cannot modify read-only groups");
}
/**
* @throws UnsupportedOperationException
*/
public void setDescription(String name, String description) throws GroupNotFoundException {
throw new UnsupportedOperationException("Cannot modify read-only groups");
}
// Search methods may be overridden by read-only group providers
/**
* Returns true if the provider supports group search capability. This implementation
* always returns false.
*/
public boolean isSearchSupported() {
return false;
}
/**
* Returns a collection of group search results. This implementation
* returns an empty collection.
*/
public Collection<String> search(String query) {
return Collections.emptyList();
}
/**
* Returns a collection of group search results. This implementation
* returns an empty collection.
*/
public Collection<String> search(String query, int startIndex, int numResults) {
return Collections.emptyList();
}
// Shared group methods may be overridden by read-only group providers
/**
* Returns the name of the groups that are shared groups.
*
* @return the name of the groups that are shared groups.
*/
public Collection<String> getSharedGroupNames() {
Collection<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_SHARED_GROUPS);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> getSharedGroupNames(JID user) {
Set<String> answer = new HashSet<String>();
Collection<String> userGroups = getGroupNames(user);
answer.addAll(userGroups);
for (String userGroup : userGroups) {
answer.addAll(getVisibleGroupNames(userGroup));
}
answer.addAll(getPublicSharedGroupNames());
return answer;
}
public Collection<String> getVisibleGroupNames(String userGroup) {
Set<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUPLIST_CONTAINERS);
pstmt.setString(1, "%" + userGroup + "%");
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> search(String key, String value) {
Set<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUPS_FOR_PROP);
pstmt.setString(1, key);
pstmt.setString(2, value);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> getPublicSharedGroupNames() {
Set<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(PUBLIC_GROUPS);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public boolean isSharingSupported() {
return true;
}
/**
* Returns a custom {@link Map} that updates the database whenever
* a property value is added, changed, or deleted.
*
* @param name The target group
* @return The properties for the given group
*/
public Map<String,String> loadProperties(Group group) {
// custom map implementation persists group property changes
// whenever one of the standard mutator methods are called
String name = group.getName();
DefaultGroupPropertyMap<String,String> result = new DefaultGroupPropertyMap<String,String>(group);
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_PROPERTIES);
pstmt.setString(1, name);
rs = pstmt.executeQuery();
while (rs.next()) {
String key = rs.getString(1);
String value = rs.getString(2);
if (key != null) {
if (value == null) {
result.remove(key);
Log.warn("Deleted null property " + key + " for group: " + name);
} else {
result.put(key, value, false); // skip persistence during load
}
}
else { // should not happen, but ...
Log.warn("Ignoring null property key for group: " + name);
}
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return result;
}
}
package org.jivesoftware.openfire.group;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.jivesoftware.util.Immutable;
import org.xmpp.packet.JID;
/**
* Common base class for immutable (read-only) GroupProvider implementations.
*
* @author Tom Evans
*/
public abstract class AbstractReadOnlyGroupProvider implements GroupProvider {
// Mutator methods are marked final for read-only group providers
/**
* @throws UnsupportedOperationException
*/
public final void addMember(String groupName, JID user, boolean administrator) throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot add members to read-only groups");
}
/**
* @throws UnsupportedOperationException
*/
public final void updateMember(String groupName, JID user, boolean administrator) throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot update members for read-only groups");
}
/**
* @throws UnsupportedOperationException
*/
public final void deleteMember(String groupName, JID user) throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot remove members from read-only groups");
}
/**
* Always true for a read-only provider
*/
public final boolean isReadOnly() {
return true;
}
/**
* @throws UnsupportedOperationException
*/
public final Group createGroup(String name) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot create groups via read-only provider");
}
/**
* @throws UnsupportedOperationException
*/
public final void deleteGroup(String name) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot remove groups via read-only provider");
}
/**
* @throws UnsupportedOperationException
*/
public final void setName(String oldName, String newName) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot modify read-only groups");
}
/**
* @throws UnsupportedOperationException
*/
public final void setDescription(String name, String description) throws UnsupportedOperationException {
throw new UnsupportedOperationException("Cannot modify read-only groups");
}
// Search methods may be overridden by read-only group providers
/**
* Returns true if the provider supports group search capability. This implementation
* always returns false.
*/
public boolean isSearchSupported() {
return false;
}
/**
* Returns a collection of group search results. This implementation
* returns an empty collection.
*/
public Collection<String> search(String query) {
return Collections.emptyList();
}
/**
* Returns a collection of group search results. This implementation
* returns an empty collection.
*/
public Collection<String> search(String query, int startIndex, int numResults) {
return Collections.emptyList();
}
/**
* Returns a collection of group search results. This implementation
* returns an empty collection.
*/
public Collection<String> search(String key, String value) {
return Collections.emptyList();
}
// Shared group methods may be overridden by read-only group providers
/**
* Returns true if the provider supports group sharing. This implementation
* always returns false.
*/
public boolean isSharingSupported() {
return false;
}
/**
* Returns a collection of shared group names. This implementation
* returns an empty collection.
*/
public Collection<String> getSharedGroupNames() {
return Collections.emptyList();
}
/**
* Returns a collection of shared group names for the given user. This
* implementation returns an empty collection.
*/
public Collection<String> getSharedGroupNames(JID user) {
return Collections.emptyList();
}
/**
* Returns a collection of shared public group names. This
* implementation returns an empty collection.
*/
public Collection<String> getPublicSharedGroupNames() {
return Collections.emptyList();
}
/**
* Returns a collection of groups shared with the given group. This
* implementation returns an empty collection.
*/
public Collection<String> getVisibleGroupNames(String userGroup) {
return Collections.emptyList();
}
/**
* Returns a map of properties for the given group. This
* implementation returns an empty immutable map.
*/
public Map<String, String> loadProperties(Group group) {
return new Immutable.Map<String,String>();
}
}
......@@ -27,10 +27,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer;
......@@ -43,7 +40,7 @@ import org.xmpp.packet.JID;
*
* @author Matt Tucker
*/
public class DefaultGroupProvider implements GroupProvider {
public class DefaultGroupProvider extends AbstractGroupProvider {
private static final Logger Log = LoggerFactory.getLogger(DefaultGroupProvider.class);
......@@ -78,29 +75,12 @@ public class DefaultGroupProvider implements GroupProvider {
"UPDATE ofGroupUser SET administrator=? WHERE groupName=? AND username=?";
private static final String USER_GROUPS =
"SELECT groupName FROM ofGroupUser WHERE username=?";
private static final String GROUPLIST_CONTAINERS =
"SELECT groupName from ofGroupProp " +
"where name='sharedRoster.groupList' " +
"AND propValue LIKE ?";
private static final String PUBLIC_GROUPS =
"SELECT groupName from ofGroupProp " +
"WHERE name='sharedRoster.showInRoster' " +
"AND propValue='everybody'";
private static final String GROUPS_FOR_PROP =
"SELECT groupName from ofGroupProp " +
"WHERE name=? " +
"AND propValue=?";
private static final String ALL_GROUPS = "SELECT groupName FROM ofGroup ORDER BY groupName";
private static final String SEARCH_GROUP_NAME = "SELECT groupName FROM ofGroup WHERE groupName LIKE ? ORDER BY groupName";
private static final String LOAD_SHARED_GROUPS =
"SELECT groupName FROM ofGroupProp WHERE name='sharedRoster.showInRoster' " +
"AND propValue IS NOT NULL AND propValue <> 'nobody'";
private static final String LOAD_PROPERTIES =
"SELECT name, propValue FROM ofGroupProp WHERE groupName=?";
private XMPPServer server = XMPPServer.getInstance();
public Group createGroup(String name) throws GroupAlreadyExistsException {
public Group createGroup(String name) {
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -149,9 +129,7 @@ public class DefaultGroupProvider implements GroupProvider {
return new Group(name, description, members, administrators);
}
public void setDescription(String name, String description)
throws GroupNotFoundException
{
public void setDescription(String name, String description) throws GroupNotFoundException {
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -170,8 +148,7 @@ public class DefaultGroupProvider implements GroupProvider {
}
}
public void setName(String oldName, String newName) throws UnsupportedOperationException,
GroupAlreadyExistsException
public void setName(String oldName, String newName) throws GroupAlreadyExistsException
{
Connection con = null;
PreparedStatement pstmt = null;
......@@ -260,113 +237,6 @@ public class DefaultGroupProvider implements GroupProvider {
return count;
}
/**
* Returns the name of the groups that are shared groups.
*
* @return the name of the groups that are shared groups.
*/
public Collection<String> getSharedGroupNames() {
Collection<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_SHARED_GROUPS);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> getSharedGroupNames(JID user) {
Set<String> answer = new HashSet<String>();
Collection<String> userGroups = getGroupNames(user);
answer.addAll(userGroups);
for (String userGroup : userGroups) {
answer.addAll(getVisibleGroupNames(userGroup));
}
answer.addAll(getPublicSharedGroupNames());
return answer;
}
public Collection<String> getVisibleGroupNames(String userGroup) {
Set<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUPLIST_CONTAINERS);
pstmt.setString(1, "%" + userGroup + "%");
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> search(String key, String value) {
Set<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(GROUPS_FOR_PROP);
pstmt.setString(1, key);
pstmt.setString(2, value);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> getPublicSharedGroupNames() {
Set<String> groupNames = new HashSet<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(PUBLIC_GROUPS);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> getGroupNames() {
List<String> groupNames = new ArrayList<String>();
Connection con = null;
......@@ -597,49 +467,4 @@ public class DefaultGroupProvider implements GroupProvider {
return members;
}
/**
* Returns a custom {@link Map} that updates the database whenever
* a property value is added, changed, or deleted.
*
* @param name The target group
* @return The properties for the given group
*/
public Map<String,String> loadProperties(Group group) {
// custom map implementation persists group property changes
// whenever one of the standard mutator methods are called
String name = group.getName();
DefaultGroupPropertyMap<String,String> result = new DefaultGroupPropertyMap<String,String>(group);
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_PROPERTIES);
pstmt.setString(1, name);
rs = pstmt.executeQuery();
while (rs.next()) {
String key = rs.getString(1);
String value = rs.getString(2);
if (key != null) {
if (value == null) {
result.remove(key);
Log.warn("Deleted null property " + key + " for group: " + name);
} else {
result.put(key, value, false); // skip persistence during load
}
}
else { // should not happen, but ...
Log.warn("Ignoring null property key for group: " + name);
}
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return result;
}
}
\ No newline at end of file
......@@ -116,7 +116,6 @@ public class Group implements Cacheable, Externalizable {
this.properties = provider.loadProperties(this);
if (!provider.isReadOnly()) {
// Apply the given properties to the group
for (Map.Entry<String, String> property : properties.entrySet()) {
if (!property.getValue().equals(this.properties.get(property.getKey()))) {
......@@ -131,7 +130,6 @@ public class Group implements Cacheable, Externalizable {
}
}
}
}
/**
* Returns the name of the group. For example, 'XYZ Admins'.
......
......@@ -38,7 +38,7 @@ import org.xmpp.packet.JID;
* &lt;/group&gt;
* &lt;/provider&gt;</pre>
*
* @see AbstractReadOnlyGroupProvider
* @see AbstractGroupProvider
*
* @author Matt Tucker
*/
......@@ -57,8 +57,7 @@ public interface GroupProvider {
* @throws UnsupportedOperationException if the provider does not
* support the operation.
*/
Group createGroup(String name) throws UnsupportedOperationException,
GroupAlreadyExistsException;
Group createGroup(String name) throws GroupAlreadyExistsException;
/**
* Deletes the group (optional operation).
......@@ -67,7 +66,7 @@ public interface GroupProvider {
* @throws UnsupportedOperationException if the provider does not
* support the operation.
*/
void deleteGroup(String name) throws UnsupportedOperationException;
void deleteGroup(String name);
/**
* Returns a group based on it's name.
......@@ -88,8 +87,7 @@ public interface GroupProvider {
* @throws UnsupportedOperationException if the provider does not
* support the operation.
*/
void setName(String oldName, String newName) throws UnsupportedOperationException,
GroupAlreadyExistsException;
void setName(String oldName, String newName) throws GroupAlreadyExistsException;
/**
* Updates the group's description.
......@@ -98,8 +96,7 @@ public interface GroupProvider {
* @param description the group description.
* @throws GroupNotFoundException if no existing group could be found to update.
*/
void setDescription(String name, String description)
throws GroupNotFoundException;
void setDescription(String name, String description) throws GroupNotFoundException;
/**
* Returns the number of groups in the system.
......@@ -182,8 +179,7 @@ public interface GroupProvider {
* @throws UnsupportedOperationException if the provider does not
* support the operation.
*/
void addMember(String groupName, JID user, boolean administrator)
throws UnsupportedOperationException;
void addMember(String groupName, JID user, boolean administrator);
/**
* Updates the privileges of an entity in a group.
......@@ -194,8 +190,7 @@ public interface GroupProvider {
* @throws UnsupportedOperationException if the provider does not
* support the operation.
*/
void updateMember(String groupName, JID user, boolean administrator)
throws UnsupportedOperationException;
void updateMember(String groupName, JID user, boolean administrator);
/**
* Deletes an entity from a group (optional operation).
......@@ -205,7 +200,7 @@ public interface GroupProvider {
* @throws UnsupportedOperationException if the provider does not
* support the operation.
*/
void deleteMember(String groupName, JID user) throws UnsupportedOperationException;
void deleteMember(String groupName, JID user);
/**
* Returns true if this GroupProvider is read-only. When read-only,
......
......@@ -26,14 +26,10 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.util.Immutable;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -56,9 +52,7 @@ import org.xmpp.packet.JID;
* <li><tt>jdbcProvider.driver = com.mysql.jdbc.Driver</tt></li>
* <li><tt>jdbcProvider.connectionString = jdbc:mysql://localhost/dbname?user=username&amp;password=secret</tt></li>
* <li><tt>jdbcGroupProvider.groupCountSQL = SELECT count(*) FROM myGroups</tt></li>
* <li><tt>jdbcGroupProvider.groupPropsSQL = SELECT propName, propValue FROM myGroupProps WHERE groupName=?</tt></li>
* <li><tt>jdbcGroupProvider.allGroupsSQL = SELECT groupName FROM myGroups</tt></li>
* <li><tt>jdbcGroupProvider.sharedGroupsSQL = SELECT groupName FROM myGroups WHERE shared='true'</tt></li>
* <li><tt>jdbcGroupProvider.userGroupsSQL = SELECT groupName FORM myGroupUsers WHERE username=?</tt></li>
* <li><tt>jdbcGroupProvider.descriptionSQL = SELECT groupDescription FROM myGroups WHERE groupName=?</tt></li>
* <li><tt>jdbcGroupProvider.loadMembersSQL = SELECT username FORM myGroupUsers WHERE groupName=? AND isAdmin='N'</tt></li>
......@@ -74,7 +68,7 @@ import org.xmpp.packet.JID;
*
* @author David Snopek
*/
public class JDBCGroupProvider extends AbstractReadOnlyGroupProvider {
public class JDBCGroupProvider extends AbstractGroupProvider {
private static final Logger Log = LoggerFactory.getLogger(JDBCGroupProvider.class);
......@@ -82,9 +76,7 @@ public class JDBCGroupProvider extends AbstractReadOnlyGroupProvider {
private String groupCountSQL;
private String descriptionSQL;
private String groupPropsSQL;
private String allGroupsSQL;
private String sharedGroupsSQL;
private String userGroupsSQL;
private String loadMembersSQL;
private String loadAdminsSQL;
......@@ -100,9 +92,7 @@ public class JDBCGroupProvider extends AbstractReadOnlyGroupProvider {
JiveGlobals.migrateProperty("jdbcProvider.driver");
JiveGlobals.migrateProperty("jdbcProvider.connectionString");
JiveGlobals.migrateProperty("jdbcGroupProvider.groupCountSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.groupPropsSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.allGroupsSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.sharedGroupsSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.userGroupsSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.descriptionSQL");
JiveGlobals.migrateProperty("jdbcGroupProvider.loadMembersSQL");
......@@ -125,9 +115,7 @@ public class JDBCGroupProvider extends AbstractReadOnlyGroupProvider {
// Load SQL statements
groupCountSQL = JiveGlobals.getProperty("jdbcGroupProvider.groupCountSQL");
groupPropsSQL = JiveGlobals.getProperty("jdbcGroupProvider.groupPropsSQL");
allGroupsSQL = JiveGlobals.getProperty("jdbcGroupProvider.allGroupsSQL");
sharedGroupsSQL = JiveGlobals.getProperty("jdbcGroupProvider.sharedGroupsSQL");
userGroupsSQL = JiveGlobals.getProperty("jdbcGroupProvider.userGroupsSQL");
descriptionSQL = JiveGlobals.getProperty("jdbcGroupProvider.descriptionSQL");
loadMembersSQL = JiveGlobals.getProperty("jdbcGroupProvider.loadMembersSQL");
......@@ -233,31 +221,6 @@ public class JDBCGroupProvider extends AbstractReadOnlyGroupProvider {
return count;
}
public Collection<String> getSharedGroupNames() {
if (sharedGroupsSQL == null) {
return Collections.emptyList();
}
List<String> groupNames = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = getConnection();
pstmt = con.prepareStatement(sharedGroupsSQL);
rs = pstmt.executeQuery();
while (rs.next()) {
groupNames.add(rs.getString(1));
}
}
catch (SQLException e) {
Log.error(e.getMessage(), e);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return groupNames;
}
public Collection<String> getGroupNames() {
List<String> groupNames = new ArrayList<String>();
Connection con = null;
......@@ -327,29 +290,4 @@ public class JDBCGroupProvider extends AbstractReadOnlyGroupProvider {
}
return groupNames;
}
public Map<String, String> loadProperties(Group group) {
Map<String,String> properties = new HashMap<String,String>();
if (groupPropsSQL != null) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(groupPropsSQL);
pstmt.setString(1, group.getName());
rs = pstmt.executeQuery();
while (rs.next()) {
properties.put(rs.getString(1), rs.getString(2));
}
}
catch (SQLException sqle) {
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
}
return new Immutable.Map<String,String>(properties);
}
}
......@@ -38,7 +38,7 @@ import javax.naming.ldap.LdapContext;
import javax.naming.ldap.LdapName;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.AbstractReadOnlyGroupProvider;
import org.jivesoftware.openfire.group.AbstractGroupProvider;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.user.UserManager;
......@@ -54,7 +54,7 @@ import org.xmpp.packet.JID;
*
* @author Matt Tucker, Greg Ferguson and Cameron Moore
*/
public class LdapGroupProvider extends AbstractReadOnlyGroupProvider {
public class LdapGroupProvider extends AbstractGroupProvider {
private static final Logger Log = LoggerFactory.getLogger(LdapGroupProvider.class);
......
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