Skip to content
Browse files

AS7-6223 Temporary system prop based client bind address configuration

  • Loading branch information...
1 parent e9a3a1a commit b8a9198566e13901ccf5f5f43a7a6fe0c9f4a658 William DeCoste committed with jaikiran Dec 19, 2012
View
25 protocol/src/main/java/org/jboss/as/protocol/ProtocolConnectionConfiguration.java
@@ -23,16 +23,17 @@
package org.jboss.as.protocol;
import static org.jboss.as.protocol.ProtocolMessages.MESSAGES;
-import org.jboss.remoting3.Endpoint;
-import org.jboss.remoting3.RemotingOptions;
-import org.xnio.OptionMap;
-import javax.net.ssl.SSLContext;
-import javax.security.auth.callback.CallbackHandler;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
+import javax.net.ssl.SSLContext;
+import javax.security.auth.callback.CallbackHandler;
+
+import org.jboss.remoting3.Endpoint;
+import org.xnio.OptionMap;
+
/**
* @author Emanuel Muckenhuber
*/
@@ -41,6 +42,7 @@
public static final int DEFAULT_WINDOW_SIZE = 0x8000;
private static final long DEFAULT_CONNECT_TIMEOUT = 5000;
+ private static final String JBOSS_CLIENT_SOCKET_BIND_ADDRESS = "jboss.management.client_socket_bind_address";
private URI uri;
private Endpoint endpoint;
@@ -49,9 +51,11 @@
private CallbackHandler callbackHandler;
private Map<String, String> saslOptions = Collections.emptyMap();
private SSLContext sslContext;
+ private String clientBindAddress;
protected ProtocolConnectionConfiguration() {
- //
+ // TODO AS7-6223 propagate clientBindAddress configuration up to end user level and get rid of this system property
+ this.clientBindAddress = SecurityActions.getSystemProperty(JBOSS_CLIENT_SOCKET_BIND_ADDRESS);
}
protected void validate() {
@@ -122,6 +126,14 @@ public void setSslContext(SSLContext sslContext) {
this.sslContext = sslContext;
}
+ public String getClientBindAddress() {
+ return clientBindAddress;
+ }
+
+ public void setClientBindAddress(String clientBindAddress) {
+ this.clientBindAddress = clientBindAddress;
+ }
+
public ProtocolConnectionConfiguration copy() {
return copy(this);
}
@@ -147,6 +159,7 @@ public static ProtocolConnectionConfiguration copy(final ProtocolConnectionConfi
configuration.callbackHandler = old.callbackHandler;
configuration.saslOptions = old.saslOptions;
configuration.sslContext = old.sslContext;
+ configuration.clientBindAddress = old.clientBindAddress;
return configuration;
}
View
12 protocol/src/main/java/org/jboss/as/protocol/ProtocolConnectionUtils.java
@@ -38,6 +38,7 @@
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.URI;
import java.util.ArrayList;
@@ -55,6 +56,7 @@
public class ProtocolConnectionUtils {
private static final String JBOSS_LOCAL_USER = "JBOSS-LOCAL-USER";
+ private static final String REMOTE_PROTOCOL = "remote";
/**
* Connect.
@@ -71,7 +73,15 @@
final Endpoint endpoint = configuration.getEndpoint();
final OptionMap options = getOptions(configuration);
final CallbackHandler actualHandler = handler != null ? handler : new AnonymousCallbackHandler();
- return endpoint.connect(configuration.getUri(), options, actualHandler, configuration.getSslContext());
+
+ String clientBindAddress = configuration.getClientBindAddress();
+ if (clientBindAddress == null) {
+ return endpoint.connect(configuration.getUri(), options, actualHandler, configuration.getSslContext());
+ } else {
+ InetSocketAddress bindAddr = new InetSocketAddress(clientBindAddress, 0);
+ InetSocketAddress destAddr = new InetSocketAddress(configuration.getUri().getHost(), configuration.getUri().getPort());
+ return endpoint.connect(REMOTE_PROTOCOL, bindAddr, destAddr, options, actualHandler, configuration.getSslContext());
+ }
}
/**
View
54 protocol/src/main/java/org/jboss/as/protocol/SecurityActions.java
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.as.protocol;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Security actions to access system environment information. No methods in
+ * this class are to be made public under any circumstances!
+ *
+ * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
+ */
+final class SecurityActions {
+
+ private SecurityActions() {
+ }
+
+ static String getSystemProperty(final String key) {
+ if (System.getSecurityManager() == null) {
+ return System.getProperty(key);
+ }
+
+ return AccessController.doPrivileged(new PrivilegedAction<String>() {
+
+ @Override
+ public String run() {
+ return System.getProperty(key);
+ }
+ });
+ }
+}

0 comments on commit b8a9198

Please sign in to comment.
Something went wrong with that request. Please try again.