Skip to content

Commit fbabcb2

Browse files
committed
Enhancement Request 37862184 - [37669786->25.09] ENH: Add support for comma separated list of hosts for the authorized-hosts host-address element (main->ce-main)
Remote remote.full on coherence-ce/main success, changes 115813, synced @115813, job.9.20250423025227.8218 [git-p4: depot-paths = "//dev/coherence-ce/main/": change = 115816]
1 parent 2cefd8a commit fbabcb2

File tree

12 files changed

+610
-18
lines changed

12 files changed

+610
-18
lines changed

prj/coherence-core/src/main/java/com/tangosol/coherence/config/xml/processor/AuthorizedHostsProcessor.java

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
package com.tangosol.coherence.config.xml.processor;
88

@@ -19,6 +19,7 @@
1919

2020
import com.tangosol.util.Filter;
2121

22+
import java.util.Arrays;
2223
import java.util.Iterator;
2324

2425
/**
@@ -32,7 +33,10 @@ public class AuthorizedHostsProcessor
3233
implements ElementProcessor<ParameterizedBuilder<Filter>>
3334
{
3435
/**
35-
* {@inheritDoc}
36+
* An {@link ElementProcessor} for &lt;authorized-hosts&gt; Configuration Elements.
37+
* <p>
38+
* Since 25.03.1, the {@code authorized-hosts.host-address} value can be either an IP host address or
39+
* a comma separated list of IP host addresses.
3640
*/
3741
@Override
3842
public ParameterizedBuilder<Filter> process(ProcessingContext context, XmlElement xmlElement)
@@ -54,9 +58,18 @@ public ParameterizedBuilder<Filter> process(ProcessingContext context, XmlElemen
5458
// <host-address>
5559
for (Iterator iter = xmlElement.getElements("host-address"); iter.hasNext(); )
5660
{
57-
XmlElement xmlHost = (XmlElement) iter.next();
61+
String hostString = ((XmlElement) iter.next()).getString();
5862

59-
builder.addAuthorizedHostsToFilter(xmlHost.getString(), null);
63+
if (hostString.contains(","))
64+
{
65+
Arrays.stream(hostString.split(","))
66+
.map(String::trim)
67+
.forEach(s -> builder.addAuthorizedHostsToFilter(s, null));
68+
}
69+
else
70+
{
71+
builder.addAuthorizedHostsToFilter(hostString, null);
72+
}
6073
}
6174

6275
// <host-range>

prj/coherence-core/src/main/java/com/tangosol/internal/net/LegacyXmlConfigHelper.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
package com.tangosol.internal.net;
88

@@ -28,6 +28,7 @@
2828
import java.net.InetSocketAddress;
2929

3030
import java.util.ArrayList;
31+
import java.util.Arrays;
3132
import java.util.Collections;
3233
import java.util.Iterator;
3334
import java.util.List;
@@ -94,6 +95,9 @@ else if (!xml.getElementList().isEmpty())
9495

9596
/**
9697
* Parse the XML and return the authorized hosts filter.
98+
* <p>
99+
* Since 25.03.1, the {@code authorized-hosts.host-address} element's value can be either an IP host address or
100+
* a comma separated list of IP host addresses.
97101
*
98102
* @param xml the parent of the authorized-hosts XML element
99103
*
@@ -122,7 +126,19 @@ public static ParameterizedBuilder<Filter> parseAuthorizedHosts(XmlElement xml)
122126
{
123127
xmlVal = (XmlElement) iter.next();
124128

125-
builder.addAuthorizedHostsToFilter(xmlVal.getString(), null);
129+
String hostString = xmlVal.getString();
130+
131+
// enable comma separated list of host for coherence.extend.authorized.hosts system property for host-address element.
132+
if (hostString.contains(","))
133+
{
134+
Arrays.stream(hostString.split(","))
135+
.map(String::trim)
136+
.forEach(s -> builder.addAuthorizedHostsToFilter(s, null));
137+
}
138+
else
139+
{
140+
builder.addAuthorizedHostsToFilter(hostString, null);
141+
}
126142
}
127143

128144
// <host-range>

prj/coherence-core/src/main/java/com/tangosol/internal/net/cluster/LegacyXmlClusterDependencies.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ private void configureOutgoingMessageHandler(XmlElement xml)
675675

676676
/**
677677
* Configure the authorized hosts fields.
678+
* <p>
679+
* Since 25.03.1, the {@code authorized-hosts.host-address} element's value can be either an IP host address or
680+
* a comma separated list of IP host addresses.
678681
*
679682
* @param xml the authorized-hosts xml element
680683
*/
@@ -701,10 +704,25 @@ private void configureAuthorizedHosts(XmlElement xml)
701704
// <host-address>
702705
for (Iterator iter = xmlCat.getElements("host-address"); iter.hasNext(); )
703706
{
704-
xmlVal = (XmlElement) iter.next();
705-
if (addAuthorizedHostsToFilter(filter, xmlVal.getString(), /* sAddrTo */ null))
707+
String hostString = ((XmlElement) iter.next()).getString();
708+
709+
// enable comma separated list of hosts for coherence.authorized.hosts system property for host-address element.
710+
if (hostString.contains(","))
706711
{
707-
fFilterAdded = true;
712+
for (String host : hostString.split(","))
713+
{
714+
if (addAuthorizedHostsToFilter(filter, host, /* sAddrTo */ null))
715+
{
716+
fFilterAdded = true;
717+
}
718+
}
719+
}
720+
else
721+
{
722+
if (addAuthorizedHostsToFilter(filter, hostString, /* sAddrTo */ null))
723+
{
724+
fFilterAdded = true;
725+
}
708726
}
709727
}
710728

prj/coherence-core/src/main/resources/coherence-config-base.xsd

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<!--
3-
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
44
55
Licensed under the Universal Permissive License v 1.0 as shown at
66
https://oss.oracle.com/licenses/upl.
@@ -1821,6 +1821,7 @@
18211821
<xsd:annotation>
18221822
<xsd:documentation>
18231823
The host-address element specifies a host IP address.
1824+
Since 25.03.1, it also can be a comma separated list of host IP addresses.
18241825

18251826
Used in: authorized-hosts
18261827
</xsd:documentation>

prj/coherence-core/src/main/resources/com/oracle/coherence/defaults/coherence-cache-config.xml

+3
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ class path, or module path, of the JVM.
323323
<address system-property="coherence.extend.address"/>
324324
<port system-property="coherence.extend.port"/>
325325
</local-address>
326+
<authorized-hosts>
327+
<host-address system-property="coherence.extend.authorized.hosts"></host-address>
328+
</authorized-hosts>
326329
</tcp-acceptor>
327330
<serializer>${coherence.extend.serializer ${coherence.serializer}}</serializer>
328331
</acceptor-config>

prj/coherence-core/src/main/resources/tangosol-coherence.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ to find specific notes on changes suggested for production use.
191191
</outgoing-message-handler>
192192

193193
<authorized-hosts>
194-
<host-address></host-address>
194+
<host-address system-property="coherence.authorized.hosts"></host-address>
195195
<host-range>
196196
<from-address></from-address>
197197
<to-address></to-address>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
package extend;
8+
9+
import java.util.Properties;
10+
import org.junit.AfterClass;
11+
import org.junit.BeforeClass;
12+
import org.junit.Test;
13+
14+
import com.oracle.coherence.testing.AbstractFunctionalTest;
15+
16+
import static org.junit.Assert.*;
17+
18+
/**
19+
* A collection of functional tests for a Coherence*Extend proxy that uses
20+
* system property coherence.extend.authorized hosts addresses and try to connect to an address that is not
21+
* authorized.
22+
*
23+
* @author jf 2025.04.17
24+
*/
25+
public class AuthorizedHostsRejectedBySystemPropertyTests
26+
extends AbstractFunctionalTest
27+
{
28+
// ----- constructors ---------------------------------------------------
29+
30+
/**
31+
* Default constructor.
32+
*/
33+
public AuthorizedHostsRejectedBySystemPropertyTests()
34+
{
35+
super(AbstractExtendTests.FILE_CLIENT_CFG_CACHE);
36+
}
37+
38+
// ----- test lifecycle -------------------------------------------------
39+
40+
/**
41+
* Initialize the test class.
42+
*/
43+
@BeforeClass
44+
public static void startup()
45+
{
46+
Properties props = new Properties();
47+
48+
props.put("coherence.extend.authorized.hosts", "baddomain.bad,2.3.4.5");
49+
startCacheServer("AuthorizedHostsRejectedBySystemPropertyTests", "extend",
50+
"authorized-hosts-cache-config-sysprop.xml", props);
51+
}
52+
53+
/**
54+
* Shutdown the test class.
55+
*/
56+
@AfterClass
57+
public static void shutdown()
58+
{
59+
stopCacheServer("AuthorizedHostsRejectedBySystemPropertyTests");
60+
}
61+
62+
// ----- AuthorizedHostsRejectedBySystemPropertyTests tests -----------------------------
63+
64+
/**
65+
* Ensure that non-authorized hosts fails.
66+
*/
67+
@Test
68+
public void connect()
69+
{
70+
try
71+
{
72+
getNamedCache("dist-extend-direct");
73+
// we should not get here. If it does it means that an non-authorized host failed
74+
// to be rejected
75+
fail("Authorized hosts check did not work");
76+
}
77+
catch (Exception e)
78+
{
79+
// this will cause an exception due to the unauthorized host.
80+
assertTrue("Did not get expected exception", e.getMessage().indexOf("could not establish a connection") != -1);
81+
}
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
4+
5+
Licensed under the Universal Permissive License v 1.0 as shown at
6+
https://oss.oracle.com/licenses/upl.
7+
-->
8+
<cache-config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xmlns="http://xmlns.oracle.com/coherence/coherence-cache-config"
10+
xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-cache-config coherence-cache-config.xsd">
11+
12+
<caching-scheme-mapping>
13+
<cache-mapping>
14+
<cache-name>dist-*</cache-name>
15+
<scheme-name>dist-default</scheme-name>
16+
</cache-mapping>
17+
</caching-scheme-mapping>
18+
19+
<caching-schemes>
20+
<distributed-scheme>
21+
<scheme-name>dist-default</scheme-name>
22+
<lease-granularity>member</lease-granularity>
23+
<backing-map-scheme>
24+
<local-scheme/>
25+
</backing-map-scheme>
26+
<autostart>true</autostart>
27+
</distributed-scheme>
28+
29+
<proxy-scheme>
30+
<service-name>ProxyService</service-name>
31+
<acceptor-config>
32+
<tcp-acceptor>
33+
<local-address>
34+
<address system-property="test.extend.address.local">127.0.0.1</address>
35+
<port system-property="test.extend.port">9999</port>
36+
</local-address>
37+
<authorized-hosts>
38+
<!-- an arbitrary hostname that should never be valid -->
39+
<host-address system-property="coherence.extend.authorized.hosts">127.0.0.1</host-address>
40+
</authorized-hosts>
41+
</tcp-acceptor>
42+
<outgoing-message-handler>
43+
<heartbeat-interval>5s</heartbeat-interval>
44+
<heartbeat-timeout>2s</heartbeat-timeout>
45+
<request-timeout>5s</request-timeout>
46+
</outgoing-message-handler>
47+
<serializer>
48+
<instance>
49+
<class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
50+
<init-params>
51+
<init-param>
52+
<param-type>string</param-type>
53+
<param-value>extend/test-pof-config.xml</param-value>
54+
</init-param>
55+
</init-params>
56+
</instance>
57+
</serializer>
58+
</acceptor-config>
59+
<autostart system-property="test.extend.enabled">true</autostart>
60+
</proxy-scheme>
61+
</caching-schemes>
62+
</cache-config>

0 commit comments

Comments
 (0)