Commit 1ba55ad7 authored by Gabriel Guardincerri's avatar Gabriel Guardincerri Committed by gguardin

[JM-1253] Receives users, groups and vcard changes from CS. Reviewer Daniel Henninger.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10081 b35dd754-fafc-0310-a699-88a17e54d16e
parent 063b8b3f
......@@ -22,6 +22,7 @@ import org.jivesoftware.openfire.commands.admin.user.AuthenticateUser;
import org.jivesoftware.openfire.commands.admin.user.ChangeUserPassword;
import org.jivesoftware.openfire.commands.admin.user.UserProperties;
import org.jivesoftware.openfire.commands.clearspace.ChangeSharedSecret;
import org.jivesoftware.openfire.commands.event.*;
import org.jivesoftware.openfire.disco.*;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.handler.IQHandler;
......@@ -202,6 +203,19 @@ public class AdHocCommandHandler extends IQHandler
addCommand(new GetServerStats());
addCommand(new HttpBindStatus());
addCommand(new ChangeSharedSecret());
addCommand(new UserCreated());
addCommand(new UserModified());
addCommand(new UserDeleting());
addCommand(new GroupCreated());
addCommand(new GroupDeleting());
addCommand(new GroupModified());
addCommand(new GroupMemberAdded());
addCommand(new GroupMemberRemoved());
addCommand(new GroupAdminAdded());
addCommand(new GroupAdminRemoved());
addCommand(new VCardCreated());
addCommand(new VCardDeleting());
addCommand(new VCardModified());
}
private void startCommand(AdHocCommand command) {
......
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a admin was added to the group. It can be used by user providers to notify Openfire of the
* aditon of a admin to a group.
*
* @author Gabriel Guarincerri
*/
public class GroupAdminAdded extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-admin-added";
}
public String getDefaultLabel() {
return "Group admin added";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Creates event params.
Map<String, Object> params = null;
try {
// Get the admin
String admin = get(data, "admin", 0);
// Adds the admin
params = new HashMap<String, Object>();
params.put("admin", admin);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Admin required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.admin_added, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group admin added event.");
form.addInstruction("Fill out this form to dispatch a group admin added event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group");
field.setVariable("groupName");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the new admin");
field.setVariable("admin");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a admin was removed from the group. It can be used by user providers to notify Openfire of the
* deletion of a admin of the group.
*
* @author Gabriel Guarincerri
*/
public class GroupAdminRemoved extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-admin-removed";
}
public String getDefaultLabel() {
return "Group admin removed";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Creates event params.
Map<String, Object> params = null;
try {
// Get the admin
String admin = get(data, "admin", 0);
// Adds the admin
params = new HashMap<String, Object>();
params.put("admin", admin);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Admin required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.admin_removed, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group admin removed event.");
form.addInstruction("Fill out this form to dispatch a group admin removed event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group");
field.setVariable("groupName");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the admin");
field.setVariable("admin");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a group was created. It can be used by user providers to notify Openfire of the
* creation of a group.
*
* @author Gabriel Guarincerri
*/
public class GroupCreated extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-created";
}
public String getDefaultLabel() {
return "Group created";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
Map<String, Object> params = Collections.emptyMap();
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_created, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group created event.");
form.addInstruction("Fill out this form to dispatch a group created event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group that was created");
field.setVariable("groupName");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a group is being deleted. It can be used by user providers to notify Openfire of the
* deletion of a group.
*
* @author Gabriel Guarincerri
*/
public class GroupDeleting extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-created";
}
public String getDefaultLabel() {
return "Group deleting";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
Map<String, Object> params = Collections.emptyMap();
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_deleting, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a deleting group event.");
form.addInstruction("Fill out this form to dispatch a deleting group event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group that is being deleted");
field.setVariable("groupName");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a member was added to the group. It can be used by user providers to notify Openfire of the
* aditon of a member to a group.
*
* @author Gabriel Guarincerri
*/
public class GroupMemberAdded extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-member-added";
}
public String getDefaultLabel() {
return "Group member added";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Creates event params.
Map<String, Object> params = null;
try {
// Get the member
String member = get(data, "member", 0);
// Adds the member
params = new HashMap<String, Object>();
params.put("member", member);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Member required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.member_added, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group member added event.");
form.addInstruction("Fill out this form to dispatch a group member added event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group");
field.setVariable("groupName");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Member");
field.setVariable("member");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a member was removed from the group. It can be used by user providers to notify Openfire of the
* deletion of a member of the group.
*
* @author Gabriel Guarincerri
*/
public class GroupMemberRemoved extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-member-removed";
}
public String getDefaultLabel() {
return "Group member removed";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Creates event params.
Map<String, Object> params = null;
try {
// Get the member
String member = get(data, "member", 0);
// Adds the member
params = new HashMap<String, Object>();
params.put("member", member);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Member required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.member_removed, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group member removed event.");
form.addInstruction("Fill out this form to dispatch a group member removed event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group");
field.setVariable("groupName");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Member");
field.setVariable("member");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a group was modified. It can be used by user providers to notify Openfire of the
* modification of a group.
*
* @author Gabriel Guarincerri
*/
public class GroupModified extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#group-modified";
}
public String getDefaultLabel() {
return "Group modified";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Get the modification type
String type;
try {
type = get(data, "changeType", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Change type required parameter.");
return;
}
// Identifies the value variable
String valueVariable = null;
String valueVariableName = null;
if ("nameModified".equals(type) || "descriptionModified".equals(type)) {
valueVariable = "originalValue";
valueVariableName = "Original value";
} else if ("propertyModified".equals(type) || "propertyAdded".equals(type) ||
"propertyDeleted".equals(type)) {
valueVariable = "propertyKey";
valueVariableName = "Property key";
}
// Creates event params.
Map<String, Object> params = new HashMap<String, Object>();
// Gets the value of the change if it exist
String value;
if (valueVariable != null) {
try {
// Gets the value
value = get(data, valueVariable, 0);
// Adds it to the event params
params.put(valueVariable, value);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText(valueVariableName + " required parameter.");
return;
}
}
// Adds the type of change
params.put("type", type);
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_modified, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a group created event.");
form.addInstruction("Fill out this form to dispatch a group created event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The group name of the group that was created");
field.setVariable("groupName");
field.setRequired(true);
field.setType(FormField.Type.list_single);
field.setLabel("Change type");
field.setVariable("changeType");
field.addOption("Name modified", "nameModified");
field.addOption("Description modified", "descriptionModified");
field.addOption("Property modified", "propertyModified");
field.addOption("Property added", "propertyAdded");
field.addOption("Property deleted", "propertyDeleted");
field.addOption("Other", "other");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Original value");
field.setVariable("originalValue");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Name of the property");
field.setVariable("propertyKey");
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a user was created. It can be used by user providers to notify Openfire of the
* creation of a user.
*
* @author Gabriel Guarincerri
*/
public class UserCreated extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#user-created";
}
public String getDefaultLabel() {
return "User created";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the username
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Sends the event
User user;
try {
// Loads the new user
user = UserManager.getUserProvider().loadUser(username);
// Fire event.
Map<String, Object> params = Collections.emptyMap();
UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_created, params);
} catch (UserNotFoundException e) {
note.addAttribute("type", "error");
note.setText("User not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a user created event.");
form.addInstruction("Fill out this form to dispatch a user created event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the user that was created");
field.setVariable("username");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* Notifies the deletion of a user. It can be used by user providers to notify Openfire of the
* deletion of a user.
*
* @author Gabriel Guarincerri
*/
public class UserDeleting extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#user-deleting";
}
public String getDefaultLabel() {
return "Deleting a User";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Gets the username
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Sends the event
User user;
try {
// Gets current user
user = UserManager.getInstance().getUser(username);
Map<String, Object> params = Collections.emptyMap();
UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_deleting, params);
} catch (UserNotFoundException e) {
// It's ok, user doesn't exist, so deleting it is nothing
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a user deleting event.");
form.addInstruction("Fill out this form to dispatch a user deleting event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the user that is being deleted");
field.setVariable("username");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a user was modified. It can be used by user providers to notify Openfire of the
* modification of a user.
*
* @author Gabriel Guarincerri
*/
public class UserModified extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#user-modified";
}
public String getDefaultLabel() {
return "User modified";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the username
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Get the modification type
String type;
try {
type = get(data, "changeType", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Change type required parameter.");
return;
}
// Identifies the value variable
String valueVariable = null;
String valueVariableName = null;
if ("nameModified".equals(type) || "emailModified".equals(type) ||
"creationDateModified".equals(type) || "modificationDateModified".equals(type)) {
valueVariable = "originalValue";
valueVariableName = "Original value";
} else if ("propertyModified".equals(type) || "propertyAdded".equals(type) ||
"propertyDeleted".equals(type)) {
valueVariable = "propertyKey";
valueVariableName = "Property key";
}
// Creates event params.
Map<String, Object> params = new HashMap<String, Object>();
// Gets the value of the change if it exist
String value;
if (valueVariable != null) {
try {
// Gets the value
value = get(data, valueVariable, 0);
// Adds it to the event params
params.put(valueVariable, value);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText(valueVariableName + " required parameter.");
return;
}
}
// Adds the type of change
params.put("type", type);
// Sends the event
User user;
try {
// Loads the updated user
user = UserManager.getUserProvider().loadUser(username);
// Fire event.
UserEventDispatcher.dispatchEvent(user, UserEventDispatcher.EventType.user_modified,
params);
} catch (UserNotFoundException e) {
note.addAttribute("type", "error");
note.setText("User not found.");
return;
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a user updated event.");
form.addInstruction("Fill out this form to dispatch a user updated event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the user that was updated");
field.setVariable("username");
field.setRequired(true);
field.setType(FormField.Type.list_single);
field.setLabel("Change type");
field.setVariable("changeType");
field.addOption("Name modified", "nameModified");
field.addOption("Email modified", "emailModified");
field.addOption("Password modified", "passwordModified");
field.addOption("Creation date modified", "creationDateModified");
field.addOption("Modification date modified", "modificationDateModified");
field.addOption("Property modified", "propertyModified");
field.addOption("Property added", "propertyAdded");
field.addOption("Property deleted", "propertyDeleted");
field.addOption("Other", "other");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Original value");
field.setVariable("originalValue");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Name of the property");
field.setVariable("propertyKey");
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.vcard.VCardEventDispatcher;
import org.jivesoftware.openfire.vcard.VCardManager;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a vcard was created. It can be used by user providers to notify Openfire of the
* creation of a user.
*
* @author Gabriel Guarincerri
*/
public class VCardCreated extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#vcard-created";
}
public String getDefaultLabel() {
return "VCard created";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the username
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Loads the new vCard
Element vCard = VCardManager.getProvider().loadVCard(username);
if (vCard == null) {
note.addAttribute("type", "error");
note.setText("VCard not found.");
return;
}
// Fire event.
VCardEventDispatcher.dispatchVCardCreated(username, vCard);
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a vCard created event.");
form.addInstruction("Fill out this form to dispatch a vCard created event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the user who's vCard was created");
field.setVariable("username");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.vcard.VCardEventDispatcher;
import org.jivesoftware.openfire.vcard.VCardManager;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* Notifies the deletion of a vCard. It can be used by user providers to notify Openfire of the
* deletion of a vCard.
*
* @author Gabriel Guarincerri
*/
public class VCardDeleting extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#vcard-deleting";
}
public String getDefaultLabel() {
return "Deleting a VCard";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Gets the username
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Loads the vCard
Element vCard = VCardManager.getInstance().getVCard(username);
if (vCard == null) {
note.addAttribute("type", "error");
note.setText("VCard not found.");
return;
}
// Fire event.
VCardEventDispatcher.dispatchVCardDeleted(username, vCard);
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a vCard deleting event.");
form.addInstruction("Fill out this form to dispatch a vCard deleting event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the user who's vCard is being deleted");
field.setVariable("username");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
/**
* $RCSfile: $
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.openfire.commands.event;
import org.dom4j.Element;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.vcard.VCardEventDispatcher;
import org.jivesoftware.openfire.vcard.VCardManager;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* Notifies the that a vCard was modified. It can be used by user providers to notify Openfire of the
* modification of a vCard.
*
* @author Gabriel Guarincerri
*/
public class VCardModified extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#vcard-modified";
}
public String getDefaultLabel() {
return "VCard modified";
}
public int getMaxStages(SessionData data) {
return 1;
}
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the username
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Loads the updated vCard
Element vCard = VCardManager.getProvider().loadVCard(username);
if (vCard == null) {
note.addAttribute("type", "error");
note.setText("VCard not found.");
return;
}
// Fire event.
VCardEventDispatcher.dispatchVCardUpdated(username, vCard);
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Dispatching a vCard updated event.");
form.addInstruction("Fill out this form to dispatch a vCard updated event.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("The username of the user who's vCard was updated");
field.setVariable("username");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
protected List<Action> getActions(SessionData data) {
return Arrays.asList(Action.complete);
}
protected Action getExecuteAction(SessionData data) {
return Action.complete;
}
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
\ No newline at end of file
......@@ -14,6 +14,8 @@ package org.jivesoftware.openfire.group;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.event.GroupEventDispatcher;
import org.jivesoftware.openfire.event.GroupEventListener;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.openfire.user.UserNotFoundException;
......@@ -80,10 +82,16 @@ public class GroupManager {
GroupEventDispatcher.addListener(new GroupEventListener() {
public void groupCreated(Group group, Map params) {
// Since the group could be created by the provider, add it possible again
groupCache.put(group.getName(), group);
groupMetaCache.clear();
}
public void groupDeleting(Group group, Map params) {
// Since the group could be deleted by the provider, remove it possible again
groupCache.remove(group.getName());
groupMetaCache.clear();
}
......@@ -131,6 +139,21 @@ public class GroupManager {
// get refreshed with latest version of the object
groupCache.put(group.getName(), group);
}
});
UserEventDispatcher.addListener(new UserEventListener() {
public void userCreated(User user, Map<String, Object> params) {
// ignore
}
public void userDeleting(User user, Map<String, Object> params) {
deleteUser(user);
}
public void userModified(User user, Map<String, Object> params) {
// ignore
}
});
// Pre-load shared groups. This will provide a faster response
......@@ -230,11 +253,9 @@ public class GroupManager {
* Deletes a user from all the groups where he/she belongs. The most probable cause
* for this request is that the user has been deleted from the system.
*
* TODO: remove this method and use events instead.
*
* @param user the deleted user from the system.
*/
public void deleteUser(User user) {
private void deleteUser(User user) {
JID userJID = XMPPServer.getInstance().createJID(user.getUsername(), null);
for (Group group : getGroups(userJID)) {
if (group.getAdmins().contains(userJID)) {
......
......@@ -565,6 +565,8 @@ public class RosterManager extends BasicModule implements GroupEventListener, Us
}
}
}
deleteRoster(userJID);
}
public void userModified(User user, Map params) {
......
......@@ -98,11 +98,13 @@ public class UserManager implements IQResultListener {
UserEventListener userListener = new UserEventListener() {
public void userCreated(User user, Map<String, Object> params) {
// Do nothing
// Since the user could be created by the provider, add it possible again
userCache.put(user.getUsername(), user);
}
public void userDeleting(User user, Map<String, Object> params) {
// Do nothing
// Since the user could be deleted by the provider, remove it possible again
userCache.remove(user.getUsername());
}
public void userModified(User user, Map<String, Object> params) {
......
/**
* $RCSfile$
* $Revision$
* $Date: 2005-07-26 19:10:33 +0200 (Tue, 26 Jul 2005) $
*
* Copyright (C) 2004-2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.openfire.vcard;
import org.dom4j.Element;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* Dispatches vCard events. The following events are supported:
* <ul>
* <li><b>VCardCreated</b> --> A VCard has been created.</li>
* <li><b>VCardDeleted</b> --> A VCard has been deleted.</li>
* <li><b>VCardUpdate</b> --> A VCard has been updated.</li>
* </ul>
* Use {@link #addListener(org.jivesoftware.openfire.vcard.VCardListener)}
* to add or remove {@link org.jivesoftware.openfire.vcard.VCardListener}.
*
* @author Gabriel Guardincerri
*/
public class VCardEventDispatcher {
/**
* List of listeners that will be notified when vCards are created, updated or deleted.
*/
private static List<VCardListener> listeners = new CopyOnWriteArrayList<VCardListener>();
/**
* Registers a listener to receive events when a vCard is created, updated or deleted.
*
* @param listener the listener.
*/
public static void addListener(VCardListener listener) {
if (listener == null) {
throw new NullPointerException();
}
listeners.add(listener);
}
/**
* Unregisters a listener to receive events.
*
* @param listener the listener.
*/
public static void removeListener(VCardListener listener) {
listeners.remove(listener);
}
/**
* Dispatches that a vCard was updated to all listeners.
*
* @param user the user for which the vCard was set.
* @param vCard the vcard updated.
*/
public static void dispatchVCardUpdated(String user, Element vCard) {
for (VCardListener listener : listeners) {
listener.vCardUpdated(user, vCard);
}
}
/**
* Dispatches that a vCard was created to all listeners.
*
* @param user the user for which the vCard was created.
* @param vCard the vcard created.
*/
public static void dispatchVCardCreated(String user, Element vCard) {
for (VCardListener listener : listeners) {
listener.vCardCreated(user, vCard);
}
}
/**
* Dispatches that a vCard was deleted to all listeners.
*
* @param user the user for which the vCard was deleted.
* @param vCard the vcard deleted.
*/
public static void dispatchVCardDeleted(String user, Element vCard) {
for (VCardListener listener : listeners) {
listener.vCardDeleted(user, vCard);
}
}
}
......@@ -11,9 +11,11 @@
package org.jivesoftware.openfire.vcard;
import org.dom4j.Element;
/**
* Interface to listen for vCard changes. Use the
* {@link org.jivesoftware.openfire.vcard.VCardManager#addListener(VCardListener)}
* {@link org.jivesoftware.openfire.vcard.VCardEventDispatcher#addListener(VCardListener)}
* method to register for events.
*
* @author Remko Tron&ccedil;on
......@@ -22,21 +24,24 @@ public interface VCardListener {
/**
* A vCard was created.
*
* @param user the user for which the vCard was created.
* @param username the username for which the vCard was created.
* @param vCard the vcard created.
*/
public void vCardCreated(String user);
public void vCardCreated(String username, Element vCard);
/**
* A vCard was updated.
*
* @param user the user for which the vCard was updated.
* @param username the user for which the vCard was updated.
* @param vCard the vcard updated.
*/
public void vCardUpdated(String user);
public void vCardUpdated(String username, Element vCard);
/**
* A vCard was deleted.
*
* @param user the user for which the vCard was deleted.
* @param username the user for which the vCard was deleted.
* @param vCard the vcard deleted.
*/
public void vCardDeleted(String user);
public void vCardDeleted(String username, Element vCard);
}
......@@ -12,18 +12,20 @@
package org.jivesoftware.openfire.vcard;
import org.dom4j.Element;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.disco.ServerFeaturesProvider;
import org.jivesoftware.openfire.event.UserEventAdapter;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.Cache;
import org.jivesoftware.util.cache.CacheFactory;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
/**
* Manages VCard information for users.
......@@ -35,13 +37,9 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
private VCardProvider provider;
private static VCardManager instance;
private Cache<String, Element> vcardCache;
private EventHandler eventHandler;
/**
* List of listeners that will be notified when vCards are created, updated or deleted.
*/
private List<VCardListener> listeners = new CopyOnWriteArrayList<VCardListener>();
private Cache<String, Element> vcardCache;
public static VCardManager getInstance() {
return instance;
}
......@@ -63,6 +61,25 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
String cacheName = "VCard";
vcardCache = CacheFactory.createCache(cacheName);
this.eventHandler = new EventHandler();
// Keeps the cache updated in case the vCard action was not performed by VCardManager
VCardEventDispatcher.addListener(new VCardListener() {
public void vCardCreated(String username, Element vCard) {
// Since the vCard could be created by the provider, add it to the cache.
vcardCache.put(username, vCard);
}
public void vCardUpdated(String username, Element vCard) {
// Since the vCard could be updated by the provider, update it to the cache.
vcardCache.put(username, vCard);
}
public void vCardDeleted(String username, Element vCard) {
// Since the vCard could be delated by the provider, remove it to the cache.
vcardCache.remove(username);
}
});
}
/**
......@@ -124,18 +141,19 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
throw new UnsupportedOperationException("VCard provider is read-only.");
}
Element oldVCard = getOrLoadVCard(username);
Element newvCard = null;
// See if we need to update the vCard or insert a new one.
if (oldVCard != null) {
// Only update the vCard in the database if the vCard has changed.
if (!oldVCard.equals(vCardElement)) {
try {
Element newvCard = provider.updateVCard(username, vCardElement);
newvCard = provider.updateVCard(username, vCardElement);
vcardCache.put(username, newvCard);
updated = true;
}
catch (NotFoundException e) {
Log.warn("Tried to update a vCard that does not exist", e);
Element newvCard = provider.createVCard(username, vCardElement);
newvCard = provider.createVCard(username, vCardElement);
vcardCache.put(username, newvCard);
created = true;
}
......@@ -143,13 +161,13 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
}
else {
try {
Element newvCard = provider.createVCard(username, vCardElement);
newvCard = provider.createVCard(username, vCardElement);
vcardCache.put(username, newvCard);
created = true;
}
catch (AlreadyExistsException e) {
Log.warn("Tried to create a vCard when one already exist", e);
Element newvCard = provider.updateVCard(username, vCardElement);
newvCard = provider.updateVCard(username, vCardElement);
vcardCache.put(username, newvCard);
updated = true;
}
......@@ -157,10 +175,10 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
// Dispatch vCard events
if (created) {
// Alert listeners that a new vCard has been created
dispatchVCardCreated(username);
VCardEventDispatcher.dispatchVCardCreated(username, newvCard);
} else if (updated) {
// Alert listeners that a vCard has been updated
dispatchVCardUpdated(username);
VCardEventDispatcher.dispatchVCardUpdated(username, newvCard);
}
}
......@@ -181,7 +199,7 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
// Delete the property from the DB if it was present in memory
provider.deleteVCard(username);
// Alert listeners that a vCard has been deleted
dispatchVCardDeleted(username);
VCardEventDispatcher.dispatchVCardDeleted(username, oldVCard);
}
}
......@@ -209,60 +227,6 @@ public class VCardManager extends BasicModule implements ServerFeaturesProvider
return vCardElement;
}
/**
* Registers a listener to receive events when a vCard is created, updated or deleted.
*
* @param listener the listener.
*/
public void addListener(VCardListener listener) {
if (listener == null) {
throw new NullPointerException();
}
listeners.add(listener);
}
/**
* Unregisters a listener to receive events.
*
* @param listener the listener.
*/
public void removeListener(VCardListener listener) {
listeners.remove(listener);
}
/**
* Dispatches that a vCard was updated to all listeners.
*
* @param user the user for which the vCard was set.
*/
private void dispatchVCardUpdated(String user) {
for (VCardListener listener : listeners) {
listener.vCardUpdated(user);
}
}
/**
* Dispatches that a vCard was created to all listeners.
*
* @param user the user for which the vCard was created.
*/
private void dispatchVCardCreated(String user) {
for (VCardListener listener : listeners) {
listener.vCardCreated(user);
}
}
/**
* Dispatches that a vCard was deleted to all listeners.
*
* @param user the user for which the vCard was deleted.
*/
private void dispatchVCardDeleted(String user) {
for (VCardListener listener : listeners) {
listener.vCardDeleted(user);
}
}
public void initialize(XMPPServer server) {
instance = this;
......
......@@ -8,7 +8,7 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.openfire.group.GroupManager,
<%@ page import="org.jivesoftware.openfire.security.SecurityAuditManager,
org.jivesoftware.openfire.session.ClientSession,
org.jivesoftware.openfire.user.User"
errorPage="error.jsp"
......@@ -18,7 +18,6 @@
<%@ page import="org.xmpp.packet.JID" %>
<%@ page import="org.xmpp.packet.StreamError" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="org.jivesoftware.openfire.security.SecurityAuditManager" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
......@@ -44,14 +43,10 @@
if (delete) {
// Delete the user
webManager.getUserManager().deleteUser(user);
// Delete the user's roster
JID userAddress = new JID(username, webManager.getServerInfo().getXMPPDomain(), null);
// Delete the roster of the user
webManager.getRosterManager().deleteRoster(userAddress);
// Delete the user from all the Groups
GroupManager.getInstance().deleteUser(user);
if (!SecurityAuditManager.getSecurityAuditProvider().blockUserEvents()) {
// Log the event
JID userAddress = new JID(username, webManager.getServerInfo().getXMPPDomain(), null);
webManager.logEvent("deleted user "+username, "full jid was "+userAddress);
}
// Close the user's connection
......
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