Commit 6d4cc5da authored by Gabriel Guardincerri's avatar Gabriel Guardincerri Committed by gguardin

[CS-3530] Fixed, Changing shared secret do not reconnect automatically. Reviewer: Daniel Henninger

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10063 b35dd754-fafc-0310-a699-88a17e54d16e
parent 466bfbf3
...@@ -355,8 +355,6 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -355,8 +355,6 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
* @param sharedSecret the password configured in Clearspace to authenticate Openfire. * @param sharedSecret the password configured in Clearspace to authenticate Openfire.
*/ */
public void setSharedSecret(String sharedSecret) { public void setSharedSecret(String sharedSecret) {
this.sharedSecret = sharedSecret;
properties.put("clearspace.sharedSecret", sharedSecret);
// Set new password for external component // Set new password for external component
ExternalComponentConfiguration configuration = new ExternalComponentConfiguration("clearspace", ExternalComponentConfiguration configuration = new ExternalComponentConfiguration("clearspace",
ExternalComponentConfiguration.Permission.allowed, sharedSecret); ExternalComponentConfiguration.Permission.allowed, sharedSecret);
...@@ -366,6 +364,12 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM ...@@ -366,6 +364,12 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
catch (ModificationNotAllowedException e) { catch (ModificationNotAllowedException e) {
Log.warn("Failed to configure password for Clearspace", e); Log.warn("Failed to configure password for Clearspace", e);
} }
// After updating the component information we can update the field, but not before.
// If it is done before, OF won't be able to execute the updateSharedsecret webservice
// since it would try with the new password.
this.sharedSecret = sharedSecret;
properties.put("clearspace.sharedSecret", sharedSecret);
} }
/** /**
......
...@@ -21,6 +21,7 @@ import org.jivesoftware.openfire.commands.admin.user.AddUser; ...@@ -21,6 +21,7 @@ import org.jivesoftware.openfire.commands.admin.user.AddUser;
import org.jivesoftware.openfire.commands.admin.user.AuthenticateUser; import org.jivesoftware.openfire.commands.admin.user.AuthenticateUser;
import org.jivesoftware.openfire.commands.admin.user.ChangeUserPassword; import org.jivesoftware.openfire.commands.admin.user.ChangeUserPassword;
import org.jivesoftware.openfire.commands.admin.user.UserProperties; import org.jivesoftware.openfire.commands.admin.user.UserProperties;
import org.jivesoftware.openfire.commands.clearspace.ChangeSharedSecret;
import org.jivesoftware.openfire.disco.*; import org.jivesoftware.openfire.disco.*;
import org.jivesoftware.openfire.forms.spi.XDataFormImpl; import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
import org.jivesoftware.openfire.handler.IQHandler; import org.jivesoftware.openfire.handler.IQHandler;
...@@ -200,6 +201,7 @@ public class AdHocCommandHandler extends IQHandler ...@@ -200,6 +201,7 @@ public class AdHocCommandHandler extends IQHandler
addCommand(new PacketsNotification()); addCommand(new PacketsNotification());
addCommand(new GetServerStats()); addCommand(new GetServerStats());
addCommand(new HttpBindStatus()); addCommand(new HttpBindStatus());
addCommand(new ChangeSharedSecret());
} }
private void startCommand(AdHocCommand command) { 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.clearspace;
import org.dom4j.Element;
import org.jivesoftware.openfire.clearspace.ClearspaceManager;
import org.jivesoftware.openfire.commands.AdHocCommand;
import org.jivesoftware.openfire.commands.SessionData;
import org.jivesoftware.openfire.component.InternalComponentManager;
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;
/**
* Changes the shared secret between Openfire and Clearspace
*
* @author Gabriel Guardincerri
*/
public class ChangeSharedSecret extends AdHocCommand {
public String getCode() {
return "http://jabber.org/protocol/clearspace#change-sharedsecret";
}
public String getDefaultLabel() {
return "Change the share secret";
}
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 old shared secret
String oldSharedSecret = get(data, "oldSharedSecret", 0);
if (oldSharedSecret == null || "".equals(oldSharedSecret)) {
note.addAttribute("type", "error");
note.setText("Old shared secret is empty or do not match.");
return;
}
// Gets the new shared secret
String newSharedSecret = get(data, "newSharedSecret", 0);
if (newSharedSecret == null || "".equals(newSharedSecret)) {
note.addAttribute("type", "error");
note.setText("New shared secret is empty or do not match.");
return;
}
// Checks if the old shared secret is OK
ClearspaceManager manager = ClearspaceManager.getInstance();
if (!manager.getSharedSecret().equals(oldSharedSecret)) {
note.addAttribute("type", "error");
note.setText("Old shared secret is not valid.");
return;
}
// Sets the new shared secret
ClearspaceManager.getInstance().setSharedSecret(newSharedSecret);
// 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("Changing the share secret");
form.addInstruction("Fill out this form to change the shared secret.");
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_private);
field.setLabel("The old shared secret");
field.setVariable("oldSharedSecret");
field.setRequired(true);
field = form.addField();
field.setType(FormField.Type.text_private);
field.setLabel("The new shared secret");
field.setVariable("newSharedSecret");
field.setRequired(true);
// Add the form to the command
command.add(form.getElement());
}
private String get(Map<String, List<String>> data, String key, int value) {
List<String> list = data.get(key);
if (list == null) {
return null;
}
else {
return list.get(value);
}
}
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
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