Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

AS7-6223 Temporary system prop based client bind address configuration

  • Loading branch information...
commit b8a9198566e13901ccf5f5f43a7a6fe0c9f4a658 1 parent e9a3a1a
William DeCoste authored jaikiran committed
25 protocol/src/main/java/org/jboss/as/protocol/ProtocolConnectionConfiguration.java
@@ -23,16 +23,17 @@
23 23 package org.jboss.as.protocol;
24 24
25 25 import static org.jboss.as.protocol.ProtocolMessages.MESSAGES;
26   -import org.jboss.remoting3.Endpoint;
27   -import org.jboss.remoting3.RemotingOptions;
28   -import org.xnio.OptionMap;
29 26
30   -import javax.net.ssl.SSLContext;
31   -import javax.security.auth.callback.CallbackHandler;
32 27 import java.net.URI;
33 28 import java.util.Collections;
34 29 import java.util.Map;
35 30
  31 +import javax.net.ssl.SSLContext;
  32 +import javax.security.auth.callback.CallbackHandler;
  33 +
  34 +import org.jboss.remoting3.Endpoint;
  35 +import org.xnio.OptionMap;
  36 +
36 37 /**
37 38 * @author Emanuel Muckenhuber
38 39 */
@@ -41,6 +42,7 @@
41 42 public static final int DEFAULT_WINDOW_SIZE = 0x8000;
42 43
43 44 private static final long DEFAULT_CONNECT_TIMEOUT = 5000;
  45 + private static final String JBOSS_CLIENT_SOCKET_BIND_ADDRESS = "jboss.management.client_socket_bind_address";
44 46
45 47 private URI uri;
46 48 private Endpoint endpoint;
@@ -49,9 +51,11 @@
49 51 private CallbackHandler callbackHandler;
50 52 private Map<String, String> saslOptions = Collections.emptyMap();
51 53 private SSLContext sslContext;
  54 + private String clientBindAddress;
52 55
53 56 protected ProtocolConnectionConfiguration() {
54   - //
  57 + // TODO AS7-6223 propagate clientBindAddress configuration up to end user level and get rid of this system property
  58 + this.clientBindAddress = SecurityActions.getSystemProperty(JBOSS_CLIENT_SOCKET_BIND_ADDRESS);
55 59 }
56 60
57 61 protected void validate() {
@@ -122,6 +126,14 @@ public void setSslContext(SSLContext sslContext) {
122 126 this.sslContext = sslContext;
123 127 }
124 128
  129 + public String getClientBindAddress() {
  130 + return clientBindAddress;
  131 + }
  132 +
  133 + public void setClientBindAddress(String clientBindAddress) {
  134 + this.clientBindAddress = clientBindAddress;
  135 + }
  136 +
125 137 public ProtocolConnectionConfiguration copy() {
126 138 return copy(this);
127 139 }
@@ -147,6 +159,7 @@ public static ProtocolConnectionConfiguration copy(final ProtocolConnectionConfi
147 159 configuration.callbackHandler = old.callbackHandler;
148 160 configuration.saslOptions = old.saslOptions;
149 161 configuration.sslContext = old.sslContext;
  162 + configuration.clientBindAddress = old.clientBindAddress;
150 163 return configuration;
151 164 }
152 165
12 protocol/src/main/java/org/jboss/as/protocol/ProtocolConnectionUtils.java
@@ -38,6 +38,7 @@
38 38 import javax.security.auth.callback.UnsupportedCallbackException;
39 39 import java.io.IOException;
40 40 import java.net.InetAddress;
  41 +import java.net.InetSocketAddress;
41 42 import java.net.NetworkInterface;
42 43 import java.net.URI;
43 44 import java.util.ArrayList;
@@ -55,6 +56,7 @@
55 56 public class ProtocolConnectionUtils {
56 57
57 58 private static final String JBOSS_LOCAL_USER = "JBOSS-LOCAL-USER";
  59 + private static final String REMOTE_PROTOCOL = "remote";
58 60
59 61 /**
60 62 * Connect.
@@ -71,7 +73,15 @@
71 73 final Endpoint endpoint = configuration.getEndpoint();
72 74 final OptionMap options = getOptions(configuration);
73 75 final CallbackHandler actualHandler = handler != null ? handler : new AnonymousCallbackHandler();
74   - return endpoint.connect(configuration.getUri(), options, actualHandler, configuration.getSslContext());
  76 +
  77 + String clientBindAddress = configuration.getClientBindAddress();
  78 + if (clientBindAddress == null) {
  79 + return endpoint.connect(configuration.getUri(), options, actualHandler, configuration.getSslContext());
  80 + } else {
  81 + InetSocketAddress bindAddr = new InetSocketAddress(clientBindAddress, 0);
  82 + InetSocketAddress destAddr = new InetSocketAddress(configuration.getUri().getHost(), configuration.getUri().getPort());
  83 + return endpoint.connect(REMOTE_PROTOCOL, bindAddr, destAddr, options, actualHandler, configuration.getSslContext());
  84 + }
75 85 }
76 86
77 87 /**
54 protocol/src/main/java/org/jboss/as/protocol/SecurityActions.java
... ... @@ -0,0 +1,54 @@
  1 +/*
  2 + * JBoss, Home of Professional Open Source.
  3 + * Copyright 2010, Red Hat, Inc., and individual contributors
  4 + * as indicated by the @author tags. See the copyright.txt file in the
  5 + * distribution for a full listing of individual contributors.
  6 + *
  7 + * This is free software; you can redistribute it and/or modify it
  8 + * under the terms of the GNU Lesser General Public License as
  9 + * published by the Free Software Foundation; either version 2.1 of
  10 + * the License, or (at your option) any later version.
  11 + *
  12 + * This software is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15 + * Lesser General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU Lesser General Public
  18 + * License along with this software; if not, write to the Free
  19 + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20 + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21 + */
  22 +
  23 +package org.jboss.as.protocol;
  24 +
  25 +import java.security.AccessController;
  26 +import java.security.PrivilegedAction;
  27 +import java.util.Map;
  28 +import java.util.Properties;
  29 +
  30 +/**
  31 + * Security actions to access system environment information. No methods in
  32 + * this class are to be made public under any circumstances!
  33 + *
  34 + * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
  35 + */
  36 +final class SecurityActions {
  37 +
  38 + private SecurityActions() {
  39 + }
  40 +
  41 + static String getSystemProperty(final String key) {
  42 + if (System.getSecurityManager() == null) {
  43 + return System.getProperty(key);
  44 + }
  45 +
  46 + return AccessController.doPrivileged(new PrivilegedAction<String>() {
  47 +
  48 + @Override
  49 + public String run() {
  50 + return System.getProperty(key);
  51 + }
  52 + });
  53 + }
  54 +}

0 comments on commit b8a9198

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