Commit 8776b51a authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Admin settings interface now completly functional for enabling and disabling.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/branches@5773 b35dd754-fafc-0310-a699-88a17e54d16e
parent 50c39cf8
...@@ -42,14 +42,24 @@ public class HttpServerManager { ...@@ -42,14 +42,24 @@ public class HttpServerManager {
public static final String ADMIN_CONSOLE_PORT = "adminConsole.port"; public static final String ADMIN_CONSOLE_PORT = "adminConsole.port";
public static final int ADMIN_CONSOLE_PORT_DEFAULT = 9090;
public static final String ADMIN_CONOSLE_SECURE_PORT = "adminConsole.securePort"; public static final String ADMIN_CONOSLE_SECURE_PORT = "adminConsole.securePort";
public static final int ADMIN_CONSOLE_SECURE_PORT_DEFAULT = 9091;
public static final String HTTP_BIND_ENABLED = "httpbind.enabled"; public static final String HTTP_BIND_ENABLED = "httpbind.enabled";
public static final boolean HTTP_BIND_ENABLED_DEFAULT = true;
public static final String HTTP_BIND_PORT = "httpbind.port.plain"; public static final String HTTP_BIND_PORT = "httpbind.port.plain";
public static final int HTTP_BIND_PORT_DEFAULT = 8080;
public static final String HTTP_BIND_SECURE_PORT = "httpbind.port.secure"; public static final String HTTP_BIND_SECURE_PORT = "httpbind.port.secure";
public static final int HTTP_BIND_SECURE_PORT_DEFAULT = 8483;
public static HttpServerManager getInstance() { public static HttpServerManager getInstance() {
return instance; return instance;
} }
...@@ -76,8 +86,9 @@ public class HttpServerManager { ...@@ -76,8 +86,9 @@ public class HttpServerManager {
} }
private void createHttpBindServer() { private void createHttpBindServer() {
port = JiveGlobals.getIntProperty(HTTP_BIND_PORT, 9090); port = JiveGlobals.getIntProperty(HTTP_BIND_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
securePort = JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 9091); securePort = JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
createHttpBindServer(port, securePort); createHttpBindServer(port, securePort);
} }
...@@ -94,8 +105,9 @@ public class HttpServerManager { ...@@ -94,8 +105,9 @@ public class HttpServerManager {
} }
private void createAdminConsoleServer() { private void createAdminConsoleServer() {
int port = JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, 9090); int port = JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
int securePort = JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT, 9091); int securePort = JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
boolean loadConnectors = true; boolean loadConnectors = true;
if(httpBindServer != null) { if(httpBindServer != null) {
if(port == this.port && securePort == this.securePort) { if(port == this.port && securePort == this.securePort) {
...@@ -138,7 +150,7 @@ public class HttpServerManager { ...@@ -138,7 +150,7 @@ public class HttpServerManager {
} }
public void startup() { public void startup() {
if(httpBindContext != null) { if(httpBindContext != null && isHttpBindServiceEnabled()) {
createHttpBindServer(); createHttpBindServer();
} }
if(adminConsoleContext != null) { if(adminConsoleContext != null) {
...@@ -165,6 +177,10 @@ public class HttpServerManager { ...@@ -165,6 +177,10 @@ public class HttpServerManager {
} }
} }
private boolean isHttpBindServiceEnabled() {
return JiveGlobals.getBooleanProperty(HTTP_BIND_ENABLED, HTTP_BIND_ENABLED_DEFAULT);
}
private void addContexts() { private void addContexts() {
if(httpBindServer == adminServer && httpBindServer != null) { if(httpBindServer == adminServer && httpBindServer != null) {
adminConsoleContext.addServlet(httpBindContext, httpBindPath); adminConsoleContext.addServlet(httpBindContext, httpBindPath);
...@@ -280,7 +296,7 @@ public class HttpServerManager { ...@@ -280,7 +296,7 @@ public class HttpServerManager {
* @return the HTTP binding port which does not use SSL. * @return the HTTP binding port which does not use SSL.
*/ */
public int getHttpBindUnsecurePort() { public int getHttpBindUnsecurePort() {
return JiveGlobals.getIntProperty(HTTP_BIND_PORT, 8080); return JiveGlobals.getIntProperty(HTTP_BIND_PORT, HTTP_BIND_PORT_DEFAULT);
} }
/** /**
...@@ -289,7 +305,7 @@ public class HttpServerManager { ...@@ -289,7 +305,7 @@ public class HttpServerManager {
* @return the HTTP binding port which uses SSL. * @return the HTTP binding port which uses SSL.
*/ */
public int getHttpBindSecurePort() { public int getHttpBindSecurePort() {
return JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 8483); return JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, HTTP_BIND_SECURE_PORT_DEFAULT);
} }
/** /**
...@@ -300,7 +316,10 @@ public class HttpServerManager { ...@@ -300,7 +316,10 @@ public class HttpServerManager {
* console. * console.
*/ */
public boolean isSeperateHttpBindServerConfigured() { public boolean isSeperateHttpBindServerConfigured() {
return httpBindServer != adminServer; return (httpBindServer != null && httpBindServer != adminServer) || (httpBindServer == null
&& (getAdminUnsecurePort() != JiveGlobals.getIntProperty(HTTP_BIND_PORT, 9090)
|| getAdminSecurePort()
!= JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT, 9091)));
} }
public void setHttpBindEnabled(boolean isEnabled) { public void setHttpBindEnabled(boolean isEnabled) {
...@@ -314,26 +333,40 @@ public class HttpServerManager { ...@@ -314,26 +333,40 @@ public class HttpServerManager {
* @param securePort the secured connection port which clients can connect to. * @param securePort the secured connection port which clients can connect to.
*/ */
public void setHttpBindPorts(int unsecurePort, int securePort) { public void setHttpBindPorts(int unsecurePort, int securePort) {
if(unsecurePort < 0 && securePort < 0) {
throw new IllegalArgumentException("At least one port must be greater than zero.");
}
if(unsecurePort == securePort) {
throw new IllegalArgumentException("Ports must be distinct.");
}
changeHttpBindPorts(unsecurePort, securePort); changeHttpBindPorts(unsecurePort, securePort);
port = unsecurePort;
this.securePort = securePort;
if (unsecurePort != getAdminUnsecurePort()) { if (unsecurePort != getAdminUnsecurePort()) {
JiveGlobals.setProperty(HTTP_BIND_PORT, String.valueOf(unsecurePort)); JiveGlobals.setProperty(HTTP_BIND_PORT, String.valueOf(unsecurePort));
} }
else {
JiveGlobals.deleteProperty(HTTP_BIND_PORT);
}
if (securePort != getAdminSecurePort()) { if (securePort != getAdminSecurePort()) {
JiveGlobals.setProperty(HTTP_BIND_SECURE_PORT, String.valueOf(securePort)); JiveGlobals.setProperty(HTTP_BIND_SECURE_PORT, String.valueOf(securePort));
} }
else {
JiveGlobals.deleteProperty(HTTP_BIND_SECURE_PORT);
}
} }
private void changeHttpBindPorts(int unsecurePort, int securePort) { private void changeHttpBindPorts(int unsecurePort, int securePort) {
int adminPort = JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, 9090); if(unsecurePort < 0 && securePort < 0) {
int adminSecurePort = JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT, 9091); throw new IllegalArgumentException("At least one port must be greater than zero.");
if (unsecurePort == adminPort && securePort == adminSecurePort) { }
if(unsecurePort == securePort) {
throw new IllegalArgumentException("Ports must be distinct.");
}
int adminPort = JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
int adminSecurePort = JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
if (checkPorts(new int[]{unsecurePort, securePort},
new int[]{adminPort, adminSecurePort}))
{
if(unsecurePort != adminPort || securePort != adminSecurePort) {
Log.warn("Http bind ports must be either the same or distinct from admin console" +
" ports, http binding will run on the admin console ports.");
}
if (httpBindServer == adminServer) { if (httpBindServer == adminServer) {
return; return;
} }
...@@ -350,10 +383,6 @@ public class HttpServerManager { ...@@ -350,10 +383,6 @@ public class HttpServerManager {
addContexts(); addContexts();
return; return;
} }
else if (checkPorts(new int[]{unsecurePort, securePort},
new int[]{adminPort, adminSecurePort})) {
throw new IllegalArgumentException("Ports must be distinct from admin console ports.");
}
if (httpBindServer != adminServer) { if (httpBindServer != adminServer) {
try { try {
...@@ -374,19 +403,106 @@ public class HttpServerManager { ...@@ -374,19 +403,106 @@ public class HttpServerManager {
} }
public int getAdminUnsecurePort() { public int getAdminUnsecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, 9090); return JiveGlobals.getXMLProperty(ADMIN_CONSOLE_PORT, ADMIN_CONSOLE_PORT_DEFAULT);
} }
public int getAdminSecurePort() { public int getAdminSecurePort() {
return JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT, 9091); return JiveGlobals.getXMLProperty(ADMIN_CONOSLE_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
}
private void doEnableHttpBind(boolean shouldEnable) {
if(shouldEnable && httpBindServer == null) {
changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT,
ADMIN_CONSOLE_PORT_DEFAULT),JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT));
}
else if(!shouldEnable && httpBindServer != null) {
if (httpBindServer != adminServer) {
try {
httpBindServer.stop();
}
catch (Exception e) {
Log.error("Error stopping http bind service", e);
}
httpBindServer = null;
}
else {
removeHttpBindServlet(adminConsoleContext);
httpBindServer = null;
}
}
}
private void setUnsecureHttpBindPort(int value) {
if (value == port) {
return;
}
try {
changeHttpBindPorts(value, JiveGlobals.getIntProperty(HTTP_BIND_SECURE_PORT,
ADMIN_CONSOLE_SECURE_PORT_DEFAULT));
port = value;
}
catch (Exception ex) {
Log.error("Error setting http bind ports", ex);
}
} }
private void setSecureHttpBindPort(int value) {
if (value == securePort) {
return;
}
try {
changeHttpBindPorts(JiveGlobals.getIntProperty(HTTP_BIND_PORT,
ADMIN_CONSOLE_PORT_DEFAULT), value);
securePort = value;
}
catch (Exception ex) {
Log.error("Error setting http bind ports", ex);
}
}
private class HttpServerPropertyListener implements PropertyEventListener { private class HttpServerPropertyListener implements PropertyEventListener {
public void propertySet(String property, Map params) { public void propertySet(String property, Map params) {
if (property.equalsIgnoreCase(HTTP_BIND_ENABLED)) {
doEnableHttpBind(Boolean.valueOf(params.get("value").toString()));
}
else if (property.equalsIgnoreCase(HTTP_BIND_PORT)) {
int value;
try {
value = Integer.valueOf(params.get("value").toString());
}
catch (NumberFormatException ne) {
JiveGlobals.deleteProperty(HTTP_BIND_PORT);
return;
}
setUnsecureHttpBindPort(value);
}
else if (property.equalsIgnoreCase(HTTP_BIND_SECURE_PORT)) {
int value;
try {
value = Integer.valueOf(params.get("value").toString());
}
catch (NumberFormatException ne) {
JiveGlobals.deleteProperty(HTTP_BIND_SECURE_PORT);
return;
}
setSecureHttpBindPort(value);
}
} }
public void propertyDeleted(String property, Map params) { public void propertyDeleted(String property, Map params) {
if(property.equalsIgnoreCase(HTTP_BIND_ENABLED)) {
doEnableHttpBind(HTTP_BIND_ENABLED_DEFAULT);
}
else if (property.equalsIgnoreCase(HTTP_BIND_PORT)) {
setUnsecureHttpBindPort(ADMIN_CONSOLE_PORT_DEFAULT);
}
else if (property.equalsIgnoreCase(HTTP_BIND_SECURE_PORT)) {
setSecureHttpBindPort(ADMIN_CONSOLE_SECURE_PORT_DEFAULT);
}
} }
public void xmlPropertySet(String property, Map params) { public void xmlPropertySet(String property, Map params) {
......
...@@ -19,24 +19,28 @@ ...@@ -19,24 +19,28 @@
Map<String, String> errorMap = new HashMap<String, String>(); Map<String, String> errorMap = new HashMap<String, String>();
if (request.getParameter("update") != null) { if (request.getParameter("update") != null) {
boolean httpPortsDistinct = ParamUtils.getBooleanParameter(request, "httpPortsDistinct", boolean isEnabled = ParamUtils.getBooleanParameter(request, "httpBindEnabled");
false); if (isEnabled) {
int requestedPort; boolean httpPortsDistinct = ParamUtils.getBooleanParameter(request, "httpPortsDistinct",
int requestedSecurePort; false);
if (httpPortsDistinct) { int requestedPort;
requestedPort = ParamUtils.getIntParameter(request, "port", -1); int requestedSecurePort;
requestedSecurePort = ParamUtils.getIntParameter(request, "securePort", -1); if (httpPortsDistinct) {
} requestedPort = ParamUtils.getIntParameter(request, "port", -1);
else { requestedSecurePort = ParamUtils.getIntParameter(request, "securePort", -1);
requestedPort = serverManager.getAdminUnsecurePort(); }
requestedSecurePort = serverManager.getAdminSecurePort(); else {
} requestedPort = serverManager.getAdminUnsecurePort();
try { requestedSecurePort = serverManager.getAdminSecurePort();
serverManager.setHttpBindPorts(requestedPort, requestedSecurePort); }
} try {
catch (Exception e) { serverManager.setHttpBindPorts(requestedPort, requestedSecurePort);
errorMap.put("port", e.getMessage()); }
catch (Exception e) {
errorMap.put("port", e.getMessage());
}
} }
serverManager.setHttpBindEnabled(isEnabled);
} }
boolean isHttpBindEnabled = serverManager.isHttpBindEnabled(); boolean isHttpBindEnabled = serverManager.isHttpBindEnabled();
......
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