Commit b3406dfd authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Created ExternalComponentManagerListener that could reject an attempt to...

Created ExternalComponentManagerListener that could reject an attempt to modify an ExternalComponentManager setting. JM-1267

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9886 b35dd754-fafc-0310-a699-88a17e54d16e
parent daf25719
......@@ -2199,4 +2199,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -2185,4 +2185,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -1294,6 +1294,7 @@ component.settings.defaultSecret=Default shared secret:
component.settings.valid.defaultSecret=Please specify a default secret key.
component.settings.valid.subdomain=Please specify the subdomain of the component.
component.settings.valid.secret=Please specify the secret key of the component.
component.settings.modification.denied=Requested operation is not allowed.
component.settings.allowed=Allowed to Connect
component.settings.anyone=Anyone
component.settings.anyone_info=Any component is allowed to connect to this server. Use the table \
......
......@@ -2241,4 +2241,5 @@ sidebar.system-clustering.descr=Haga clic para administrar seteos de cluster
user.roster.filter=Mostrar
user.roster.filter.all=Todos los contactos
user.roster.filter.noshared=Grupos no Compartidos
user.roster.filter.onlyshared=Solo Grupos Compartidos
\ No newline at end of file
user.roster.filter.onlyshared=Solo Grupos Compartidos
component.settings.modification.denied=Operaci\u00f3n requerida no esta permitida.
\ No newline at end of file
......@@ -1807,4 +1807,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -2332,4 +2332,5 @@ httpbind.settings.script.label_disable=Disable
httpbind.settings.script.label_disable_info=Does not allow clients with limited access to connect to the server
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -2196,4 +2196,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -2165,4 +2165,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -2199,4 +2199,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -1976,4 +1976,5 @@ system.clustering.starting=Clustering is being started. It may take up to 30 sec
sidebar.system-clustering=Clustering
sidebar.system-clustering.descr=Click to manage clustering settings
sidebar.stun=STUN Settings
sidebar.user-roster=Roster
\ No newline at end of file
sidebar.user-roster=Roster
component.settings.modification.denied=Requested operation is not allowed.
\ No newline at end of file
......@@ -16,8 +16,10 @@ public class ExternalComponentConfiguration {
private String secret;
public ExternalComponentConfiguration(String subdomain) {
public ExternalComponentConfiguration(String subdomain, Permission permission, String secret) {
this.subdomain = subdomain;
this.permission = permission;
this.secret = secret;
}
public String getSubdomain() {
......@@ -28,7 +30,7 @@ public class ExternalComponentConfiguration {
return permission;
}
public void setPermission(Permission permission) {
void setPermission(Permission permission) {
this.permission = permission;
}
......@@ -36,7 +38,7 @@ public class ExternalComponentConfiguration {
return secret;
}
public void setSecret(String secret) {
void setSecret(String secret) {
this.secret = secret;
}
......
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2008 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.component;
import org.jivesoftware.util.ModificationNotAllowedException;
/**
* Listener that will be alerted when an external component is disabled/enabled,
* the port is changed or configuration about an external component is modified.<p>
*
* All listeners of the event will be alerted. Moreover, listeners have the chance
* to deny a change from happening. If a single listener denied the operation then
* it will not be allowed.
*
* @author Gaston Dombiak
*/
public interface ExternalComponentManagerListener {
/**
* Notification indicating whether the service is being enabled or disabled. The
* listener may throw an exception to not allow the change from taking place.
*
* @param enabled true if the service is being enabled.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void serviceEnabled(boolean enabled) throws ModificationNotAllowedException;
/**
* Notification indicating that the port used by external components is being
* modified. The listener may throw an exception to not allow the change from
* taking place.
*
* @param newPort new default secret being set.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void portChanged(int newPort) throws ModificationNotAllowedException;
/**
* Notification indicating that the default secret is being modified. The
* listener may throw an exception to not allow the change from taking place.
*
* @param newSecret new default secret being set.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void defaultSecretChanged(String newSecret) throws ModificationNotAllowedException;
/**
* Notification indicating that the permission policy is being modified. See
* {@link ExternalComponentManager.PermissionPolicy} for more information. The
* listener may throw an exception to not allow the change from taking place.
*
* @param newPolicy new permission policy being set.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void permissionPolicyChanged(ExternalComponentManager.PermissionPolicy newPolicy) throws ModificationNotAllowedException;
/**
* Notification indicating that a new component was allowed to connect using a
* given configuration. The listener may throw an exception to not allow the
* change from taking place.
*
* @param subdomain subdomain of the added component.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void componentAllowed(String subdomain) throws ModificationNotAllowedException;
/**
* Notification indicating that a component was blocked to connect to the server.
* The listener may throw an exception to not allow the change from taking place.
*
* @param subdomain subdomain of the blocked component.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void componentBlocked(String subdomain) throws ModificationNotAllowedException;
/**
* Notification indicating that the configuration of a component, that was either
* blocked or allowed to connect, is being deleted. The listener may throw an exception
* to not allow the change from taking place.
*
* @param subdomain subdomain of the component.
* @param newSecret new secret being set for the component.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void componentSecretUpdated(String subdomain, String newSecret) throws ModificationNotAllowedException;
/**
* Notification indicating that the configuration of a component, that was either
* blocked or allowed to connect, is being deleted. The listener may throw an
* exception to not allow the change from taking place.
*
* @param subdomain subdomain of the component.
* @throws ModificationNotAllowedException if the operation was denied.
*/
void componentConfigurationDeleted(String subdomain) throws ModificationNotAllowedException;
}
/**
* $Revision:$
* $Date:$
*
* Copyright (C) 2008 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.util;
/**
* Exception thrown when a modification was not allowed.
*/
public class ModificationNotAllowedException extends Exception {
public ModificationNotAllowedException() {
super();
}
public ModificationNotAllowedException(String message) {
super(message);
}
public ModificationNotAllowedException(String message, Throwable cause) {
super(message, cause);
}
public ModificationNotAllowedException(Throwable cause) {
super(cause);
}
}
......@@ -44,10 +44,9 @@
boolean allowSuccess = false;
boolean blockSuccess = false;
boolean deleteSuccess = false;
boolean operationFailed = false;
String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager();
// Update the session kick policy if requested
Map<String, String> errors = new HashMap<String, String>();
......@@ -63,26 +62,41 @@
}
// If no errors, continue:
if (errors.isEmpty()) {
if (!componentEnabled) {
connectionManager.enableComponentListener(false);
try {
if (!componentEnabled) {
ExternalComponentManager.setServiceEnabled(false);
}
else {
ExternalComponentManager.setServiceEnabled(true);
ExternalComponentManager.setServicePort(port);
ExternalComponentManager.setDefaultSecret(defaultSecret);
}
updateSucess = true;
}
else {
connectionManager.enableComponentListener(true);
connectionManager.setComponentListenerPort(port);
ExternalComponentManager.setDefaultSecret(defaultSecret);
catch (ModificationNotAllowedException e) {
operationFailed = true;
}
updateSucess = true;
}
}
if (permissionUpdate) {
ExternalComponentManager.setPermissionPolicy(permissionFilter);
updateSucess = true;
try {
ExternalComponentManager.setPermissionPolicy(permissionFilter);
updateSucess = true;
}
catch (ModificationNotAllowedException e) {
operationFailed = true;
}
}
if (configToDelete != null && configToDelete.trim().length() != 0) {
ExternalComponentManager.deleteConfiguration(configToDelete);
deleteSuccess = true;
try {
ExternalComponentManager.deleteConfiguration(configToDelete);
deleteSuccess = true;
}
catch (ModificationNotAllowedException e) {
operationFailed = true;
}
}
if (componentAllowed) {
......@@ -97,11 +111,15 @@
if (errors.isEmpty()) {
// Remove the hostname if the user is not sending just the subdomain
subdomain = subdomain.replace("." + serverName, "");
ExternalComponentConfiguration configuration = new ExternalComponentConfiguration(subdomain);
configuration.setSecret(secret);
configuration.setPermission(ExternalComponentConfiguration.Permission.allowed);
ExternalComponentManager.allowAccess(configuration);
allowSuccess = true;
ExternalComponentConfiguration configuration = new ExternalComponentConfiguration(subdomain,
ExternalComponentConfiguration.Permission.allowed, secret);
try {
ExternalComponentManager.allowAccess(configuration);
allowSuccess = true;
}
catch (ModificationNotAllowedException e) {
operationFailed = true;
}
}
}
......@@ -114,15 +132,20 @@
if (errors.isEmpty()) {
// Remove the hostname if the user is not sending just the subdomain
subdomain = subdomain.replace("." + serverName, "");
ExternalComponentManager.blockAccess(subdomain);
blockSuccess = true;
try {
ExternalComponentManager.blockAccess(subdomain);
blockSuccess = true;
}
catch (ModificationNotAllowedException e) {
operationFailed = true;
}
}
}
// Set page vars
if (errors.size() == 0) {
componentEnabled = connectionManager.isComponentListenerEnabled();
port = connectionManager.getComponentListenerPort();
componentEnabled = ExternalComponentManager.isServiceEnabled();
port = ExternalComponentManager.getServicePort();
defaultSecret = ExternalComponentManager.getDefaultSecret();
permissionFilter = ExternalComponentManager.getPermissionPolicy().toString();
subdomain = "";
......@@ -130,7 +153,7 @@
}
else {
if (port == 0) {
port = connectionManager.getComponentListenerPort();
port = ExternalComponentManager.getServicePort();
}
if (defaultSecret == null) {
defaultSecret = ExternalComponentManager.getDefaultSecret();
......@@ -179,6 +202,22 @@
</div>
<br>
<% } else if (operationFailed) { %>
<div class="jive-error">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0"/></td>
<td class="jive-icon-label">
<fmt:message key="component.settings.modification.denied" />
</td>
</tr>
</tbody>
</table>
</div>
<br>
<% } else if (updateSucess || allowSuccess || blockSuccess || deleteSuccess) { %>
<div class="jive-success">
......
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