Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

AS7-3653 Don't expose ProtocolUtils outside a very limited number of …

…modules
  • Loading branch information...
commit 319bd0c0534da084a1c70289656d35c2a946df7c 1 parent f78f351
 Brian Stansberry bstansberry authored

Showing 17 changed files with 149 additions and 31 deletions. Show diff stats Hide diff stats

  1. +2 2 arquillian/common/src/main/java/org/jboss/as/arquillian/container/MBeanServerConnectionProvider.java
  2. +2 2 arquillian/common/src/main/java/org/jboss/as/arquillian/container/ManagementClient.java
  3. +49 0 arquillian/common/src/main/java/org/jboss/as/arquillian/container/NetworkUtils.java
  4. +1 0  build/src/main/resources/modules/org/jboss/as/domain-http-interface/main/module.xml
  5. +1 0  build/src/main/resources/modules/org/jboss/as/jdr/main/module.xml
  6. +14 1 controller-client/src/main/java/org/jboss/as/controller/client/impl/ProtocolConfigurationFactory.java
  7. +4 0 domain-http/interface/pom.xml
  8. +2 2 domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiHandler.java
  9. +3 1 host-controller/src/main/java/org/jboss/as/host/controller/ManagedServer.java
  10. +2 1  host-controller/src/main/java/org/jboss/as/host/controller/RemoteDomainConnectionService.java
  11. +4 0 jdr/jboss-as-jdr/pom.xml
  12. +2 1  jdr/jboss-as-jdr/src/main/java/org/jboss/as/jdr/JdrReportService.java
  13. +9 4 network/pom.xml
  14. +49 0 network/src/main/java/org/jboss/as/network/NetworkUtils.java
  15. +3 3 ...mgmt/ProtocolUtilsTestCase.java → network/src/test/java/org/jboss/as/network/NetworkUtilsTestCase.java
  16. +0 13 protocol/src/main/java/org/jboss/as/protocol/mgmt/ProtocolUtils.java
  17. +2 1  server/src/main/java/org/jboss/as/server/DomainServerMain.java
4 arquillian/common/src/main/java/org/jboss/as/arquillian/container/MBeanServerConnectionProvider.java
@@ -53,7 +53,7 @@ public MBeanServerConnectionProvider(InetAddress hostAddr, int port) {
53 53
54 54 public MBeanServerConnection getConnection() {
55 55 String host = hostAddr.getHostAddress();
56   - String urlString = System.getProperty("jmx.service.url", "service:jmx:rmi:///jndi/rmi://" + ProtocolUtils.formatPossibleIpv6Address(host) + ":" + port + "/jmxrmi");
  56 + String urlString = System.getProperty("jmx.service.url", "service:jmx:rmi:///jndi/rmi://" + NetworkUtils.formatPossibleIpv6Address(host) + ":" + port + "/jmxrmi");
57 57 try {
58 58 if (jmxConnector == null) {
59 59 log.debug("Connecting JMXConnector to: " + urlString);
@@ -82,4 +82,4 @@ public MBeanServerConnection getConnection(long timeout) {
82 82 }
83 83 throw new IllegalStateException("MBeanServerConnection not available");
84 84 }
85   -}
  85 +}
4 arquillian/common/src/main/java/org/jboss/as/arquillian/container/ManagementClient.java
@@ -202,7 +202,7 @@ private URI getBinding(final String socketBinding) {
202 202 portOp.get(NAME).set("bound-port");
203 203 final int port = executeForResult(portOp).asInt();
204 204
205   - return URI.create(socketBinding + "://" + ProtocolUtils.formatPossibleIpv6Address(ip) + ":" + port);
  205 + return URI.create(socketBinding + "://" + NetworkUtils.formatPossibleIpv6Address(ip) + ":" + port);
206 206 } catch (Exception e) {
207 207 throw new RuntimeException(e);
208 208 }
@@ -327,7 +327,7 @@ private MBeanServerConnection getConnection() {
327 327
328 328 private JMXServiceURL getRemoteJMXURL() {
329 329 try {
330   - return new JMXServiceURL("service:jmx:remoting-jmx://" + ProtocolUtils.formatPossibleIpv6Address(mgmtAddress) + ":" + mgmtPort);
  330 + return new JMXServiceURL("service:jmx:remoting-jmx://" + NetworkUtils.formatPossibleIpv6Address(mgmtAddress) + ":" + mgmtPort);
331 331 } catch (Exception e) {
332 332 throw new RuntimeException("Could not create JMXServiceURL:" + this, e);
333 333 }
49 arquillian/common/src/main/java/org/jboss/as/arquillian/container/NetworkUtils.java
... ... @@ -0,0 +1,49 @@
  1 +/*
  2 + * JBoss, Home of Professional Open Source.
  3 + * Copyright 2011, 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.arquillian.container;
  24 +
  25 +/**
  26 + * Utility methods related to networking.
  27 + *
  28 + * @author Brian Stansberry (c) 2011 Red Hat Inc.
  29 + */
  30 +public class NetworkUtils {
  31 +
  32 + public static String formatPossibleIpv6Address(String address) {
  33 + if (address == null) {
  34 + return address;
  35 + }
  36 + if (!address.contains(":")) {
  37 + return address;
  38 + }
  39 + if (address.startsWith("[") && address.endsWith("]")) {
  40 + return address;
  41 + }
  42 + return "[" + address + "]";
  43 + }
  44 +
  45 + // No instantiation
  46 + private NetworkUtils() {
  47 +
  48 + }
  49 +}
1  build/src/main/resources/modules/org/jboss/as/domain-http-interface/main/module.xml
@@ -34,6 +34,7 @@
34 34 <dependencies>
35 35 <module name="org.jboss.as.controller"/>
36 36 <module name="org.jboss.as.domain-management"/>
  37 + <module name="org.jboss.as.network"/>
37 38 <module name="org.jboss.com.sun.httpserver"/>
38 39 <module name="org.jboss.dmr"/>
39 40 <module name="org.jboss.logging"/>
1  build/src/main/resources/modules/org/jboss/as/jdr/main/module.xml
@@ -38,6 +38,7 @@
38 38 <module name="org.apache.commons.cli"/>
39 39 <module name="org.jboss.staxmapper"/>
40 40 <module name="org.jboss.as.controller"/>
  41 + <module name="org.jboss.as.network"/>
41 42 <module name="org.jboss.as.server"/>
42 43 <module name="org.jboss.modules"/>
43 44 <module name="org.jboss.as.threads"/>
15 controller-client/src/main/java/org/jboss/as/controller/client/impl/ProtocolConfigurationFactory.java
@@ -40,7 +40,7 @@
40 40 static ProtocolChannelClient.Configuration create(final ModelControllerClientConfiguration client) throws URISyntaxException {
41 41 final ProtocolChannelClient.Configuration configuration = new ProtocolChannelClient.Configuration();
42 42
43   - configuration.setUri(new URI("remote://" + ProtocolUtils.formatPossibleIpv6Address(client.getHost()) + ":" + client.getPort()));
  43 + configuration.setUri(new URI("remote://" + formatPossibleIpv6Address(client.getHost()) + ":" + client.getPort()));
44 44 final long timeout = client.getConnectionTimeout();
45 45 if(timeout > 0) {
46 46 configuration.setConnectionTimeout(timeout);
@@ -48,4 +48,17 @@
48 48 return configuration;
49 49 }
50 50
  51 + private static String formatPossibleIpv6Address(String address) {
  52 + if (address == null) {
  53 + return address;
  54 + }
  55 + if (!address.contains(":")) {
  56 + return address;
  57 + }
  58 + if (address.startsWith("[") && address.endsWith("]")) {
  59 + return address;
  60 + }
  61 + return "[" + address + "]";
  62 + }
  63 +
51 64 }
4 domain-http/interface/pom.xml
@@ -75,6 +75,10 @@
75 75 <artifactId>jboss-as-domain-management</artifactId>
76 76 </dependency>
77 77 <dependency>
  78 + <groupId>org.jboss.as</groupId>
  79 + <artifactId>jboss-as-network</artifactId>
  80 + </dependency>
  81 + <dependency>
78 82 <groupId>org.jboss.com.sun.httpserver</groupId>
79 83 <artifactId>httpserver</artifactId>
80 84 </dependency>
4 domain-http/interface/src/main/java/org/jboss/as/domain/http/server/DomainApiHandler.java
@@ -71,7 +71,7 @@
71 71 import org.jboss.as.domain.http.server.security.SubjectAssociationHandler;
72 72 import org.jboss.as.domain.management.SecurityRealm;
73 73 import org.jboss.as.domain.management.security.DomainCallbackHandler;
74   -import org.jboss.as.protocol.mgmt.ProtocolUtils;
  74 +import org.jboss.as.network.NetworkUtils;
75 75 import org.jboss.com.sun.net.httpserver.Authenticator;
76 76 import org.jboss.com.sun.net.httpserver.Filter;
77 77 import org.jboss.com.sun.net.httpserver.Headers;
@@ -157,7 +157,7 @@ private void doHandle(HttpExchange http) throws IOException {
157 157 String origin = headers.getFirst(ORIGIN);
158 158 String host = headers.getFirst(HOST);
159 159 String protocol = http.getHttpContext().getServer() instanceof HttpServer ? HTTP : HTTPS;
160   - String allowedOrigin = protocol + "://" + ProtocolUtils.formatPossibleIpv6Address(host);
  160 + String allowedOrigin = protocol + "://" + NetworkUtils.formatPossibleIpv6Address(host);
161 161
162 162 // This will reject multi-origin Origin headers due to the exact match.
163 163 if (origin.equals(allowedOrigin) == false) {
4 host-controller/src/main/java/org/jboss/as/host/controller/ManagedServer.java
@@ -45,6 +45,8 @@
45 45 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SYSTEM_PROPERTIES;
46 46 import org.jboss.as.controller.remote.RemoteProxyController;
47 47 import static org.jboss.as.host.controller.HostControllerLogger.ROOT_LOGGER;
  48 +
  49 +import org.jboss.as.network.NetworkUtils;
48 50 import org.jboss.as.process.ProcessControllerClient;
49 51 import org.jboss.as.protocol.mgmt.ManagementChannelHandler;
50 52 import org.jboss.as.protocol.mgmt.ManagementRequestHandler;
@@ -669,7 +671,7 @@ public void execute(ManagedServer server) throws Exception {
669 671 // Reconnect
670 672 final String hostName = InetAddress.getByName(managementSocket.getHostName()).getHostName();
671 673 final int port = managementSocket.getPort();
672   - processControllerClient.reconnectProcess(serverProcessName, ProtocolUtils.formatPossibleIpv6Address(hostName), port, bootConfiguration.isManagementSubsystemEndpoint(), authKey);
  674 + processControllerClient.reconnectProcess(serverProcessName, NetworkUtils.formatPossibleIpv6Address(hostName), port, bootConfiguration.isManagementSubsystemEndpoint(), authKey);
673 675 }
674 676 }
675 677
3  host-controller/src/main/java/org/jboss/as/host/controller/RemoteDomainConnectionService.java
@@ -66,6 +66,7 @@
66 66 import org.jboss.as.domain.management.security.SecurityRealmService;
67 67 import org.jboss.as.host.controller.mgmt.DomainControllerProtocol;
68 68 import org.jboss.as.host.controller.mgmt.DomainRemoteFileRequestAndHandler;
  69 +import org.jboss.as.network.NetworkUtils;
69 70 import org.jboss.as.protocol.ProtocolChannelClient;
70 71 import org.jboss.as.protocol.StreamUtils;
71 72 import org.jboss.as.protocol.mgmt.AbstractManagementRequest;
@@ -261,7 +262,7 @@ public synchronized void start(StartContext context) throws StartException {
261 262
262 263 // Gather the required information to connect to the remote DC
263 264 final ProtocolChannelClient.Configuration configuration = new ProtocolChannelClient.Configuration();
264   - configuration.setUri(new URI("remote://" + ProtocolUtils.formatPossibleIpv6Address(localHostInfo.getRemoteDomainControllerHost()) + ":" + localHostInfo.getRemoteDomainControllertPort()));
  265 + configuration.setUri(new URI("remote://" + NetworkUtils.formatPossibleIpv6Address(localHostInfo.getRemoteDomainControllerHost()) + ":" + localHostInfo.getRemoteDomainControllertPort()));
265 266 configuration.setEndpoint(endpointInjector.getValue());
266 267
267 268 final SecurityRealm realm = securityRealmInjector.getOptionalValue();
4 jdr/jboss-as-jdr/pom.xml
@@ -46,6 +46,10 @@
46 46 </dependency>
47 47 <dependency>
48 48 <groupId>org.jboss.as</groupId>
  49 + <artifactId>jboss-as-network</artifactId>
  50 + </dependency>
  51 + <dependency>
  52 + <groupId>org.jboss.as</groupId>
49 53 <artifactId>jboss-as-server</artifactId>
50 54 </dependency>
51 55 <dependency>
3  jdr/jboss-as-jdr/src/main/java/org/jboss/as/jdr/JdrReportService.java
@@ -34,6 +34,7 @@
34 34 import org.jboss.as.controller.OperationFailedException;
35 35 import org.jboss.as.controller.ServiceVerificationHandler;
36 36 import org.jboss.as.controller.client.ModelControllerClient;
  37 +import org.jboss.as.network.NetworkUtils;
37 38 import org.jboss.as.protocol.mgmt.ProtocolUtils;
38 39 import org.jboss.as.server.ServerEnvironment;
39 40 import org.jboss.as.server.ServerEnvironmentService;
@@ -96,7 +97,7 @@ public JdrReport standaloneCollect(String host, String port) throws OperationFai
96 97 boolean must_auth = false;
97 98
98 99 try {
99   - URL managementApi = new URL("http://" + ProtocolUtils.formatPossibleIpv6Address(host) + ":" + port + "/management");
  100 + URL managementApi = new URL("http://" + NetworkUtils.formatPossibleIpv6Address(host) + ":" + port + "/management");
100 101 HttpURLConnection conn = (HttpURLConnection) managementApi.openConnection();
101 102 int code = conn.getResponseCode();
102 103 if (code != 200) {
13 network/pom.xml
@@ -67,9 +67,14 @@
67 67 <scope>provided</scope>
68 68 <optional>true</optional>
69 69 </dependency>
70   - <dependency>
71   - <groupId>org.jboss.msc</groupId>
72   - <artifactId>jboss-msc</artifactId>
73   - </dependency>
  70 + <dependency>
  71 + <groupId>org.jboss.msc</groupId>
  72 + <artifactId>jboss-msc</artifactId>
  73 + </dependency>
  74 + <dependency>
  75 + <groupId>junit</groupId>
  76 + <artifactId>junit</artifactId>
  77 + <scope>test</scope>
  78 + </dependency>
74 79 </dependencies>
75 80 </project>
49 network/src/main/java/org/jboss/as/network/NetworkUtils.java
... ... @@ -0,0 +1,49 @@
  1 +/*
  2 + * JBoss, Home of Professional Open Source.
  3 + * Copyright 2011, 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.network;
  24 +
  25 +/**
  26 + * Utility methods related to networking.
  27 + *
  28 + * @author Brian Stansberry (c) 2011 Red Hat Inc.
  29 + */
  30 +public class NetworkUtils {
  31 +
  32 + public static String formatPossibleIpv6Address(String address) {
  33 + if (address == null) {
  34 + return address;
  35 + }
  36 + if (!address.contains(":")) {
  37 + return address;
  38 + }
  39 + if (address.startsWith("[") && address.endsWith("]")) {
  40 + return address;
  41 + }
  42 + return "[" + address + "]";
  43 + }
  44 +
  45 + // No instantiation
  46 + private NetworkUtils() {
  47 +
  48 + }
  49 +}
6 ...jboss/as/protocol/mgmt/ProtocolUtilsTestCase.java → ...va/org/jboss/as/network/NetworkUtilsTestCase.java
@@ -19,7 +19,7 @@
19 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 21 */
22   -package org.jboss.as.protocol.mgmt;
  22 +package org.jboss.as.network;
23 23
24 24 import junit.framework.Assert;
25 25
@@ -29,7 +29,7 @@
29 29 *
30 30 * @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
31 31 */
32   -public class ProtocolUtilsTestCase {
  32 +public class NetworkUtilsTestCase {
33 33
34 34 @Test
35 35 public void testFormatIPv6Test() {
@@ -47,6 +47,6 @@ private void checkSameFormat(String nochange) {
47 47 }
48 48
49 49 private void checkEqualFormat(String expected, String input) {
50   - Assert.assertEquals(expected, ProtocolUtils.formatPossibleIpv6Address(input));
  50 + Assert.assertEquals(expected, NetworkUtils.formatPossibleIpv6Address(input));
51 51 }
52 52 }
13 protocol/src/main/java/org/jboss/as/protocol/mgmt/ProtocolUtils.java
@@ -115,19 +115,6 @@ public static byte readByte(final InputStream stream) throws IOException {
115 115 return (byte) b;
116 116 }
117 117
118   - public static String formatPossibleIpv6Address(String address) {
119   - if (address == null) {
120   - return address;
121   - }
122   - if (!address.contains(":")) {
123   - return address;
124   - }
125   - if (address.startsWith("[") && address.endsWith("]")) {
126   - return address;
127   - }
128   - return "[" + address + "]";
129   - }
130   -
131 118 public static interface ResponseWriter {
132 119
133 120 ResponseWriter EMPTY = new ResponseWriter() {
3  server/src/main/java/org/jboss/as/server/DomainServerMain.java
@@ -34,6 +34,7 @@
34 34 import java.util.Arrays;
35 35
36 36 import org.jboss.as.controller.ModelController;
  37 +import org.jboss.as.network.NetworkUtils;
37 38 import org.jboss.as.process.protocol.StreamUtils;
38 39 import org.jboss.as.protocol.mgmt.ProtocolUtils;
39 40 import org.jboss.as.remoting.EndpointService;
@@ -187,7 +188,7 @@ private static void addCommunicationServices(final ServiceTarget serviceTarget,
187 188
188 189 try {
189 190 final int port = managementSocket.getPort();
190   - final String host = ProtocolUtils.formatPossibleIpv6Address(InetAddress.getByName(managementSocket.getHostName()).getHostName());
  191 + final String host = NetworkUtils.formatPossibleIpv6Address(InetAddress.getByName(managementSocket.getHostName()).getHostName());
191 192 final HostControllerServerClient client = new HostControllerServerClient(serverName, serverProcessName, host, port, authKey);
192 193 serviceTarget.addService(HostControllerServerClient.SERVICE_NAME, client)
193 194 .addDependency(endpointName, Endpoint.class, client.getEndpointInjector())

0 comments on commit 319bd0c

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