Skip to content

Commit 62c865f

Browse files
committed
Clean-up access controller tests
(merge main -> ce/main 116094) [git-p4: depot-paths = "//dev/coherence-ce/main/": change = 116117]
1 parent 1a0ccd8 commit 62c865f

File tree

10 files changed

+265
-93
lines changed

10 files changed

+265
-93
lines changed

prj/coherence-core-components/src/main/java/com/tangosol/coherence/component/net/Security.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import com.tangosol.internal.net.security.DefaultSecurityDependencies;
1616
import com.tangosol.internal.net.security.DefaultStandardDependencies;
1717
import com.tangosol.internal.net.security.LegacyXmlStandardHelper;
18+
import com.tangosol.net.CacheFactory;
19+
import com.tangosol.net.ClusterDependencies;
1820
import com.tangosol.net.ClusterPermission;
1921
import com.tangosol.net.security.Authorizer;
2022
import com.tangosol.net.security.DefaultIdentityAsserter;
@@ -280,11 +282,12 @@ public static synchronized void configureSecurity()
280282
deps = new DefaultStandardDependencies();
281283

282284
// internal call equivalent to "CacheFactory.getSecurityConfig();"
283-
XmlElement xmlConfig = Coherence.getServiceConfig("$Security");
285+
XmlElement xmlConfig = Coherence.getServiceConfig("$Security");
286+
ClusterDependencies depsCluster = CacheFactory.getCluster().getDependencies();
284287
if (xmlConfig != null)
285288
{
286289
// load the security dependencies given the xml config
287-
deps = LegacyXmlStandardHelper.fromXml(xmlConfig, deps);
290+
deps = LegacyXmlStandardHelper.fromXml(xmlConfig, deps, depsCluster);
288291

289292
if (deps.isEnabled())
290293
{

prj/coherence-core/src/main/java/com/tangosol/coherence/config/builder/InstanceBuilder.java

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, 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
55
* https://oss.oracle.com/licenses/upl.
@@ -64,7 +64,7 @@ public class InstanceBuilder<T>
6464
*/
6565
public InstanceBuilder()
6666
{
67-
m_exprClassName = new LiteralExpression<String>("undefined");
67+
m_exprClassName = new LiteralExpression<>(UNDEFINED_CLASS_NAME);
6868
m_listConstructorParameters = new ResolvableParameterList();
6969
}
7070

@@ -76,7 +76,7 @@ public InstanceBuilder()
7676
*/
7777
public InstanceBuilder(Class<?> clzToRealize, Object... aConstructorParameters)
7878
{
79-
m_exprClassName = new LiteralExpression<String>(clzToRealize.getName());
79+
m_exprClassName = new LiteralExpression<>(clzToRealize.getName());
8080
m_listConstructorParameters = new SimpleParameterList(aConstructorParameters);
8181
}
8282

@@ -100,7 +100,7 @@ public InstanceBuilder(Expression<String> exprClassName, Object... aConstructorP
100100
*/
101101
public InstanceBuilder(String sClassName, Object... aConstructorParameters)
102102
{
103-
m_exprClassName = new LiteralExpression<String>(sClassName);
103+
m_exprClassName = new LiteralExpression<>(sClassName);
104104
m_listConstructorParameters = new SimpleParameterList(aConstructorParameters);
105105
}
106106

@@ -117,6 +117,18 @@ public Expression<String> getClassName()
117117
return m_exprClassName;
118118
}
119119

120+
/**
121+
* Return true if the class name is undefined.
122+
*
123+
* @return true if the class name is undefined
124+
*/
125+
public boolean isUndefined()
126+
{
127+
return m_exprClassName == null ||
128+
(m_exprClassName instanceof LiteralExpression
129+
&& UNDEFINED_CLASS_NAME.equals(m_exprClassName.evaluate(null)));
130+
}
131+
120132
/**
121133
* Sets the {@link Expression} that when evaluated will produce the name of the class to realize.
122134
*
@@ -275,8 +287,8 @@ public String toString()
275287
@Override
276288
public void readExternal(DataInput in) throws IOException
277289
{
278-
m_exprClassName = (Expression<String>) ExternalizableHelper.readObject(in, null);
279-
m_listConstructorParameters = (ParameterList) ExternalizableHelper.readObject(in, null);
290+
m_exprClassName = ExternalizableHelper.readObject(in, null);
291+
m_listConstructorParameters = ExternalizableHelper.readObject(in, null);
280292
}
281293

282294
/**
@@ -297,8 +309,8 @@ public void writeExternal(DataOutput out) throws IOException
297309
@Override
298310
public void readExternal(PofReader reader) throws IOException
299311
{
300-
m_exprClassName = (Expression<String>) reader.readObject(0);
301-
m_listConstructorParameters = (ParameterList) reader.readObject(1);
312+
m_exprClassName = reader.readObject(0);
313+
m_listConstructorParameters = reader.readObject(1);
302314
}
303315

304316
/**
@@ -311,6 +323,13 @@ public void writeExternal(PofWriter writer) throws IOException
311323
writer.writeObject(1, m_listConstructorParameters);
312324
}
313325

326+
// ----- constants ------------------------------------------------------
327+
328+
/**
329+
* The value of the class name expression if no class name has been set.
330+
*/
331+
public static final String UNDEFINED_CLASS_NAME = "undefined";
332+
314333
// ----- data members ---------------------------------------------------
315334

316335
/**
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
/*
2-
* Copyright (c) 2000, 2022, 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.security;
88

9+
import com.oracle.coherence.common.base.Logger;
10+
911
import com.tangosol.coherence.config.ParameterMacroExpressionParser;
1012

13+
import com.tangosol.coherence.config.builder.InstanceBuilder;
1114
import com.tangosol.coherence.config.builder.ParameterizedBuilder;
15+
import com.tangosol.coherence.config.builder.ParameterizedBuilderRegistry;
1216

1317
import com.tangosol.coherence.config.xml.OperationalConfigNamespaceHandler;
1418

19+
import com.tangosol.coherence.config.xml.processor.InstanceProcessor;
1520
import com.tangosol.coherence.config.xml.processor.PasswordProviderBuilderProcessor;
1621

1722
import com.tangosol.config.xml.DefaultProcessingContext;
1823
import com.tangosol.config.xml.DocumentProcessor;
1924

20-
import com.tangosol.net.CacheFactory;
25+
import com.tangosol.net.ClusterDependencies;
2126
import com.tangosol.net.PasswordProvider;
2227

2328
import com.tangosol.net.security.AccessController;
@@ -36,40 +41,40 @@
3641
/**
3742
* LegacyXmlStandardHelper parses the {@code <security-config>} XML to
3843
* populate the DefaultStandardDependencies.
39-
*
44+
* <p>
4045
* NOTE: This code will eventually be replaced by CODI.
4146
*
4247
* @author der 2011.12.01
4348
* @since Coherence 12.1.2
4449
*/
45-
@SuppressWarnings("deprecation")
4650
public class LegacyXmlStandardHelper
4751
{
4852
/**
4953
* Populate the DefaultStandardDependencies object from the XML
5054
* configuration.
5155
*
52-
* @param xml the <{@code <security-config>} XML element
53-
* @param deps the DefaultStandardDependencies to be populated
56+
* @param xml the <{@code <security-config>} XML element
57+
* @param deps the DefaultStandardDependencies to be populated
58+
* @param depsCluster the cluster dependencies
5459
*
5560
* @return the DefaultStandardDependencies object that was passed in.
5661
*/
57-
public static DefaultStandardDependencies fromXml(XmlElement xml, DefaultStandardDependencies deps)
62+
public static DefaultStandardDependencies fromXml(XmlElement xml, DefaultStandardDependencies deps,
63+
ClusterDependencies depsCluster)
5864
{
5965
LegacyXmlSecurityHelper.fromXml(xml, deps);
6066

6167
if (deps.isEnabled())
6268
{
63-
XmlElement xmlAC = xml.getSafeElement("access-controller");
64-
XmlElement xmlCH = xml.getSafeElement("callback-handler");
65-
66-
AccessController controller = (AccessController) newInstance(xmlAC);
69+
XmlElement xmlAC = xml.getSafeElement("access-controller");
70+
AccessController controller = newAccessController(xmlAC, depsCluster);
6771
if (controller == null)
6872
{
69-
throw new RuntimeException(
70-
"The 'access-controller' configuration element must be specified");
73+
throw new RuntimeException("The 'access-controller' configuration element must be specified");
7174
}
72-
CallbackHandler handler = (CallbackHandler) newInstance(xmlCH);
75+
76+
XmlElement xmlCH = xml.getSafeElement("callback-handler");
77+
CallbackHandler handler = newCallbackHandler(xmlCH, depsCluster);
7378

7479
deps.setAccessController(controller);
7580
deps.setCallbackHandler(handler);
@@ -82,68 +87,99 @@ public static DefaultStandardDependencies fromXml(XmlElement xml, DefaultStandar
8287
// ----- helpers --------------------------------------------------
8388

8489
/**
85-
* Instantiate the callbackHandler and accessController objects
90+
* Instantiate the {@link AccessController} instance
8691
*
87-
* @param xmlConfig the xml configuration for accessController or
88-
* callbackHandler object
92+
* @param xmlConfig the XML configuration for {@link AccessController}
93+
* @param depsCluster the cluster dependencies
8994
*/
90-
private static Object newInstance(XmlElement xmlConfig)
95+
private static AccessController newAccessController(XmlElement xmlConfig, ClusterDependencies depsCluster)
9196
{
9297
String sClass = xmlConfig.getSafeElement("class-name").getString();
9398

94-
if (sClass.length() > 0)
99+
if (sClass.isEmpty())
95100
{
96-
XmlElement xmlParams = xmlConfig.getSafeElement("init-params");
97-
Object[] aoParam = XmlHelper.parseInitParams(xmlParams);
98-
XmlElement xmlPwdProvider = xmlConfig.getElement("password-provider");
101+
return null;
102+
}
103+
104+
XmlElement xmlParams = xmlConfig.getSafeElement("init-params");
105+
Object[] aoParam = XmlHelper.parseInitParams(xmlParams);
106+
XmlElement xmlPwdProvider = xmlConfig.getElement("password-provider");
99107

100-
try
108+
try
109+
{
110+
if (xmlPwdProvider != null)
101111
{
102-
if (xmlPwdProvider != null)
103-
{
104-
OperationalConfigNamespaceHandler nsHandler = new OperationalConfigNamespaceHandler();
105-
DocumentProcessor.Dependencies dependencies =
106-
new DocumentProcessor.DefaultDependencies(nsHandler)
107-
.setExpressionParser(new ParameterMacroExpressionParser());
108-
DefaultProcessingContext ctx = new DefaultProcessingContext(dependencies, null);
109-
ctx.ensureNamespaceHandler("", nsHandler);
112+
ParameterizedBuilderRegistry registry = depsCluster.getBuilderRegistry();
113+
OperationalConfigNamespaceHandler nsHandler = new OperationalConfigNamespaceHandler();
114+
DocumentProcessor.Dependencies dependencies = new DocumentProcessor.DefaultDependencies(nsHandler)
115+
.setExpressionParser(new ParameterMacroExpressionParser());
116+
DefaultProcessingContext ctx = new DefaultProcessingContext(dependencies, null);
110117

111-
ParameterizedBuilder<PasswordProvider> bldr = new PasswordProviderBuilderProcessor().process(ctx, xmlPwdProvider);
112-
PasswordProvider pwdProvider = bldr.realize(null, null, null);
118+
ctx.ensureNamespaceHandler("", nsHandler);
119+
ctx.addCookie(ParameterizedBuilderRegistry.class, registry);
113120

114-
int len = aoParam.length;
121+
ParameterizedBuilder<PasswordProvider> bldr = new PasswordProviderBuilderProcessor().process(ctx, xmlPwdProvider);
122+
PasswordProvider pwdProvider = bldr.realize(null, null, null);
115123

116-
if (len < 4)
117-
{
118-
aoParam = Arrays.copyOf(aoParam, len + 1);
119-
aoParam[len] = pwdProvider;
120-
}
121-
else
124+
int len = aoParam.length;
125+
if (len < 4)
126+
{
127+
aoParam = Arrays.copyOf(aoParam, len + 1);
128+
aoParam[len] = pwdProvider;
129+
}
130+
else
131+
{
132+
if (aoParam[3] instanceof String)
122133
{
123-
if (aoParam[3] instanceof String)
134+
String password = (String) aoParam[3];
135+
if (!password.isEmpty())
124136
{
125-
String password = (String) aoParam[3];
126-
if (!password.isEmpty())
127-
{
128-
CacheFactory.log("Both a password parameter and a PasswordProvider are configured for the AccessController. The PasswordProvider will be used.", Base.LOG_WARN);
129-
}
137+
Logger.warn("Both a password parameter and a PasswordProvider are configured for the AccessController. The PasswordProvider will be used.");
130138
}
131-
132-
aoParam[3] = pwdProvider;
133139
}
134-
}
135140

136-
Class clz = ExternalizableHelper.loadClass(sClass, null, null);
137-
return ClassHelper.newInstance(clz, aoParam);
138-
}
139-
catch (Exception e)
140-
{
141-
throw Base.ensureRuntimeException(e);
141+
aoParam[3] = pwdProvider;
142+
}
142143
}
144+
145+
Class<?> clz = ExternalizableHelper.loadClass(sClass, null, null);
146+
return (AccessController) ClassHelper.newInstance(clz, aoParam);
143147
}
144-
else
148+
catch (Exception e)
149+
{
150+
throw Base.ensureRuntimeException(e);
151+
}
152+
}
153+
154+
/**
155+
* Instantiate the {@link CallbackHandler} instance
156+
*
157+
* @param xmlConfig the XML configuration for {@link AccessController}
158+
* @param depsCluster the cluster dependencies
159+
*/
160+
private static CallbackHandler newCallbackHandler(XmlElement xmlConfig, ClusterDependencies depsCluster)
161+
{
162+
ParameterizedBuilderRegistry registry = depsCluster.getBuilderRegistry();
163+
OperationalConfigNamespaceHandler nsHandler = new OperationalConfigNamespaceHandler();
164+
DocumentProcessor.Dependencies dependencies = new DocumentProcessor.DefaultDependencies(nsHandler)
165+
.setExpressionParser(new ParameterMacroExpressionParser());
166+
DefaultProcessingContext ctx = new DefaultProcessingContext(dependencies, null);
167+
168+
ctx.ensureNamespaceHandler("", nsHandler);
169+
ctx.addCookie(ParameterizedBuilderRegistry.class, registry);
170+
171+
InstanceProcessor processor = new InstanceProcessor();
172+
ParameterizedBuilder<Object> builder = processor.process(ctx, xmlConfig);
173+
174+
if (builder == null)
145175
{
146176
return null;
147177
}
178+
if (builder instanceof InstanceBuilder<Object> && ((InstanceBuilder<Object>) builder).isUndefined())
179+
{
180+
return null;
181+
}
182+
183+
return (CallbackHandler) builder.realize(null, null, null);
148184
}
149185
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -1485,8 +1485,7 @@
14851485
</xsd:annotation>
14861486
<xsd:complexType>
14871487
<xsd:sequence>
1488-
<xsd:element ref="class-name" minOccurs="0" />
1489-
<xsd:element ref="init-params" minOccurs="0" />
1488+
<xsd:group ref="instance" />
14901489
<xsd:element ref="password-provider" minOccurs="0" />
14911490
</xsd:sequence>
14921491
</xsd:complexType>
@@ -1506,8 +1505,7 @@
15061505
</xsd:annotation>
15071506
<xsd:complexType>
15081507
<xsd:sequence>
1509-
<xsd:element ref="class-name" minOccurs="0" />
1510-
<xsd:element ref="init-params" minOccurs="0" />
1508+
<xsd:group ref="instance" />
15111509
</xsd:sequence>
15121510
</xsd:complexType>
15131511
</xsd:element>

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -965,17 +965,20 @@ to find specific notes on changes suggested for production use.
965965
<ssl>
966966
<protocol>TLS</protocol>
967967
<identity-manager>
968+
<algorithm>${coherence.security.keystore.algorithm ${coherence.security.algorithm}}</algorithm>
968969
<key-store>
969970
<url system-property="coherence.security.keystore">file:keystore.jks</url>
970971
<password system-property="coherence.security.password"/>
972+
<type>${coherence.security.keystore.type}</type>
971973
</key-store>
972974
<password>${coherence.security.key.password ${coherence.security.password}}</password>
973975
</identity-manager>
974976
<trust-manager>
975-
<algorithm system-property="coherence.security.algorithm">PeerX509</algorithm>
977+
<algorithm>${coherence.security.truststore.algorithm ${coherence.security.algorithm PeerX509}}</algorithm>
976978
<key-store>
977979
<url>${coherence.security.truststore ${coherence.security.keystore file:keystore.jks}}</url>
978980
<password>${coherence.security.truststore.password ${coherence.security.password}}</password>
981+
<type>${coherence.security.truststore.type ${coherence.security.keystore.type}}</type>
979982
</key-store>
980983
</trust-manager>
981984
<protocol-versions usage="black-list">

0 commit comments

Comments
 (0)