Commit 72248555 authored by Holger Bergunde's avatar Holger Bergunde Committed by holger.bergunde

OF-570 GoJara removes contacts from roster if gateway registration gets deleted

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13296 b35dd754-fafc-0310-a699-88a17e54d16e
parent ddf4de9a
...@@ -44,6 +44,12 @@ ...@@ -44,6 +44,12 @@
GoJara Plugin Changelog GoJara Plugin Changelog
</h1> </h1>
<p><b>1.2.2 Alpha</b> -- Feb 17, 2012</p>
<ul>
<li>Fixed: Remove remote contacts from roster when deleting gateway registration [<a href="http://issues.igniterealtime.org/browse/OF-570">OF-570</a>]</li>
</ul>
<p><b>1.2 Alpha</b> -- Feb 17, 2012</p> <p><b>1.2 Alpha</b> -- Feb 17, 2012</p>
<ul> <ul>
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
<name>GoJara</name> <name>GoJara</name>
<description>ProtoXEP-xxxx: Remote Roster Management support</description> <description>ProtoXEP-xxxx: Remote Roster Management support</description>
<author>Holger Bergunde and Daniel Henninger</author> <author>Holger Bergunde and Daniel Henninger</author>
<version>1.2.1 Alpha</version> <version>1.2.2 Alpha</version>
<date>02/17/2012</date> <date>09/17/2012</date>
<databaseKey>gojara</databaseKey> <databaseKey>gojara</databaseKey>
<databaseVersion>0</databaseVersion> <databaseVersion>0</databaseVersion>
<minServerVersion>3.7.0</minServerVersion> <minServerVersion>3.7.0</minServerVersion>
......
...@@ -102,6 +102,9 @@ public class RemoteRosterInterceptor implements PacketInterceptor { ...@@ -102,6 +102,9 @@ public class RemoteRosterInterceptor implements PacketInterceptor {
* admin panel * admin panel
*/ */
_packetProcessor.get("sparkIQRegistered").process(packet); _packetProcessor.get("sparkIQRegistered").process(packet);
} else if (myPacket.getType().equals(IQ.Type.set) && myPacket.getTo().toString().equals(_mySubdomain)) {
System.out.println("war das ein remove an mich????");
_packetProcessor.get("handleCleanUp").process(packet);
} }
} }
// else if (packet instanceof Presence) { // else if (packet instanceof Presence) {
......
...@@ -2,59 +2,64 @@ package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.proce ...@@ -2,59 +2,64 @@ package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.proce
import java.util.Collection; import java.util.Collection;
import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.roster.Roster; import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem; import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.roster.RosterManager; import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/** /**
* This class is a part of the command pattern used in
* {@link RemoteRosterInterceptor}. If the remote contacts should not be saved
* permanently in the users roster this command will clean up the users roster.
* If the remote contact went offline it will get removed from user's roster.
* *
* @author Holger Bergunde * This class cleans up a roster from contacts if the user removes/deletes the
* gateway registration. After deleting a registration there should not be any
* gateway related contacts left
*
* @author holger.bergunde
* *
*/ */
public class CleanUpRosterProcessor extends AbstractRemoteRosterProcessor { public class CleanUpRosterProcessor extends AbstractRemoteRosterProcessor {
private String _myDomain;
private RosterManager _rosterManager; private RosterManager _rosterManager;
private String _subDomain;
public CleanUpRosterProcessor(RosterManager rostermananger, String subdomain) { public CleanUpRosterProcessor(RosterManager rosterMananger, String mySubdomain) {
Log.debug("Createt CleanUpRosterProcessor for " + subdomain); Log.debug("Created CleanUpRosterProcessor for " + mySubdomain);
_rosterManager = rostermananger; _myDomain = mySubdomain;
_subDomain = subdomain; _rosterManager = rosterMananger;
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in CleanUpRosterProcessor for " + _subDomain); if (packet instanceof IQ) {
Presence myPacket = (Presence) packet; IQ iqPacket = (IQ) packet;
String to = myPacket.getTo().toString();
String username = getUsernameFromJid(to); if (findNodesInDocument(iqPacket.getElement().getDocument(), "//register:remove").size() > 0) {
if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable)) { String username = getUsernameFromJid(packet.getFrom().toString());
try {
Roster roster = _rosterManager.getRoster(username); Roster roster;
try {
Collection<RosterItem> items = roster.getRosterItems(); roster = _rosterManager.getRoster(username);
for (RosterItem item : items) { Collection<RosterItem> items = roster.getRosterItems();
String itemName = item.getJid().toString();
if (itemName.contains(_subDomain) && !itemName.equals(_subDomain)) { for (RosterItem item : items) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list."); String itemName = item.getJid().toString();
roster.deleteRosterItem(item.getJid(), false); if (itemName.contains(_myDomain) && !itemName.equals(_myDomain)) {
Log.debug("Removing contact " + username + " from contact list.");
roster.deleteRosterItem(item.getJid(), false);
}
} }
} catch (UserNotFoundException e) {
Log.debug("Could not found user while cleaning up the roster in GoJara for user " + username, e);
} catch (SharedGroupException e) {
// We should ignore this. External contacts cannot be in
// shared groups
} }
} catch (Exception e) {
Log.debug("Execption occured when cleaning up the Roster.", e);
e.printStackTrace();
} }
} }
} }
}
} \ No newline at end of file
...@@ -24,7 +24,7 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces ...@@ -24,7 +24,7 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces
private String _myDomain; private String _myDomain;
public ClientToComponentUpdateProcessor(String mySubdomain) { public ClientToComponentUpdateProcessor(String mySubdomain) {
Log.debug("Createt ClientToComponentUpdateProcessor for " + mySubdomain); Log.debug("Created ClientToComponentUpdateProcessor for " + mySubdomain);
_myDomain = mySubdomain; _myDomain = mySubdomain;
} }
......
...@@ -32,7 +32,7 @@ public class DiscoIQResigteredProcessor extends AbstractRemoteRosterProcessor { ...@@ -32,7 +32,7 @@ public class DiscoIQResigteredProcessor extends AbstractRemoteRosterProcessor {
private String _mySubdoman; private String _mySubdoman;
public DiscoIQResigteredProcessor(String subdomain) { public DiscoIQResigteredProcessor(String subdomain) {
Log.debug("Createt DiscoIQResigteredProcessor for " + subdomain); Log.debug("Created DiscoIQResigteredProcessor for " + subdomain);
_mySubdoman = subdomain; _mySubdoman = subdomain;
} }
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
import java.util.Collection;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.roster.RosterManager;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
/**
* This class is a part of the command pattern used in
* {@link RemoteRosterInterceptor}. If the remote contacts should not be saved
* permanently in the users roster this command will clean up the users roster.
* If the remote contact went offline it will get removed from user's roster.
*
* @author Holger Bergunde
*
*/
public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager;
private String _subDomain;
public NonPersistantRosterProcessor(RosterManager rostermananger, String subdomain) {
Log.debug("Created CleanUpRosterProcessor for " + subdomain);
_rosterManager = rostermananger;
_subDomain = subdomain;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in CleanUpRosterProcessor for " + _subDomain);
Presence myPacket = (Presence) packet;
String to = myPacket.getTo().toString();
String username = getUsernameFromJid(to);
if (myPacket.getType() != null && myPacket.getType().equals(Presence.Type.unavailable)) {
try {
Roster roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
String itemName = item.getJid().toString();
if (itemName.contains(_subDomain) && !itemName.equals(_subDomain)) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list.");
roster.deleteRosterItem(item.getJid(), false);
}
}
} catch (Exception e) {
Log.debug("Execption occured when cleaning up the Roster.", e);
e.printStackTrace();
}
}
}
}
...@@ -34,7 +34,7 @@ public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProces ...@@ -34,7 +34,7 @@ public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProces
public ReceiveComponentUpdatesProcessor(RosterManager rosterManager, String subdomain) { public ReceiveComponentUpdatesProcessor(RosterManager rosterManager, String subdomain) {
_mySubdomain = subdomain; _mySubdomain = subdomain;
Log.debug("Createt ReceiveComponentUpdatesProcessor for " + _mySubdomain); Log.debug("Created ReceiveComponentUpdatesProcessor for " + _mySubdomain);
_rosterManager = rosterManager; _rosterManager = rosterManager;
} }
......
...@@ -32,7 +32,7 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor { ...@@ -32,7 +32,7 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
private String _componentName; private String _componentName;
public SendRosterProcessor(RosterManager rosterMananger, String componentName) { public SendRosterProcessor(RosterManager rosterMananger, String componentName) {
Log.debug("Createt SendRosterProcessor for " + componentName); Log.debug("Created SendRosterProcessor for " + componentName);
_rosterManager = rosterMananger; _rosterManager = rosterMananger;
_componentName = componentName; _componentName = componentName;
} }
......
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