Commit 6e11b860 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

CS-6341: System-admin-added events from Clearspace are now being interpreted....

CS-6341: System-admin-added events from Clearspace are now being interpreted. To be reviewed by David.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10658 b35dd754-fafc-0310-a699-88a17e54d16e
parent b1884cd9
......@@ -24,6 +24,8 @@ 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.clearspace.GenerateNonce;
import org.jivesoftware.openfire.commands.clearspace.SystemAdminAdded;
import org.jivesoftware.openfire.commands.clearspace.SystemAdminRemoved;
import org.jivesoftware.openfire.commands.event.*;
import org.jivesoftware.openfire.disco.*;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
......@@ -220,6 +222,8 @@ public class AdHocCommandHandler extends IQHandler
addCommand(new VCardModified());
addCommand(new GetAdminConsoleInfo());
addCommand(new GenerateNonce());
addCommand(new SystemAdminAdded());
addCommand(new SystemAdminRemoved());
}
private void startCommand(AdHocCommand command) {
......
package org.jivesoftware.openfire.commands.clearspace;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.admin.AdminManager;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.dom4j.Element;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
/**
* Notifies that a new system administrator has been added.
*
* @author Armando Jagucki
*/
public class SystemAdminAdded extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#sys-admin-added";
}
public String getDefaultLabel() {
return "System administrator 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 username of the new admin
String adminUsername;
try {
adminUsername = get(data, "adminUsername", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Admin username required parameter.");
return;
}
// Promotes the user to administrator, locally
AdminManager.getInstance().addAdminAccount(adminUsername);
// 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 system admin added event.");
form.addInstruction("Fill out this form to dispatch a system 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 username of the new system administrator.");
field.setVariable("adminUsername");
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;
}
@Override
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
package org.jivesoftware.openfire.commands.clearspace;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.admin.AdminManager;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.dom4j.Element;
import org.xmpp.forms.DataForm;
import org.xmpp.forms.FormField;
import org.xmpp.packet.JID;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
/**
* Notifies that a user has had its system administrator status revoked.
*
* @author Armando Jagucki
*/
public class SystemAdminRemoved extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/event#sys-admin-removed";
}
public String getDefaultLabel() {
return "System administrator status 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 username of the old admin
String username;
try {
username = get(data, "username", 0);
}
catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Username required parameter.");
return;
}
// Revokes administrator status from the user, locally
AdminManager.getInstance().removeAdminAccount(username);
// 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 system admin removed event.");
form.addInstruction("Fill out this form to dispatch a system 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 username whose system administrator status should be revoked.");
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;
}
@Override
public boolean hasPermission(JID requester) {
return super.hasPermission(requester) || InternalComponentManager.getInstance().hasComponent(requester);
}
}
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