1
1
/*
2
- * Copyright (c) 2000, 2022 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2000, 2025 , Oracle and/or its affiliates.
3
3
*
4
4
* 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.
6
6
*/
7
7
package com .tangosol .internal .net .security ;
8
8
9
+ import com .oracle .coherence .common .base .Logger ;
10
+
9
11
import com .tangosol .coherence .config .ParameterMacroExpressionParser ;
10
12
13
+ import com .tangosol .coherence .config .builder .InstanceBuilder ;
11
14
import com .tangosol .coherence .config .builder .ParameterizedBuilder ;
15
+ import com .tangosol .coherence .config .builder .ParameterizedBuilderRegistry ;
12
16
13
17
import com .tangosol .coherence .config .xml .OperationalConfigNamespaceHandler ;
14
18
19
+ import com .tangosol .coherence .config .xml .processor .InstanceProcessor ;
15
20
import com .tangosol .coherence .config .xml .processor .PasswordProviderBuilderProcessor ;
16
21
17
22
import com .tangosol .config .xml .DefaultProcessingContext ;
18
23
import com .tangosol .config .xml .DocumentProcessor ;
19
24
20
- import com .tangosol .net .CacheFactory ;
25
+ import com .tangosol .net .ClusterDependencies ;
21
26
import com .tangosol .net .PasswordProvider ;
22
27
23
28
import com .tangosol .net .security .AccessController ;
36
41
/**
37
42
* LegacyXmlStandardHelper parses the {@code <security-config>} XML to
38
43
* populate the DefaultStandardDependencies.
39
- *
44
+ * <p>
40
45
* NOTE: This code will eventually be replaced by CODI.
41
46
*
42
47
* @author der 2011.12.01
43
48
* @since Coherence 12.1.2
44
49
*/
45
- @ SuppressWarnings ("deprecation" )
46
50
public class LegacyXmlStandardHelper
47
51
{
48
52
/**
49
53
* Populate the DefaultStandardDependencies object from the XML
50
54
* configuration.
51
55
*
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
54
59
*
55
60
* @return the DefaultStandardDependencies object that was passed in.
56
61
*/
57
- public static DefaultStandardDependencies fromXml (XmlElement xml , DefaultStandardDependencies deps )
62
+ public static DefaultStandardDependencies fromXml (XmlElement xml , DefaultStandardDependencies deps ,
63
+ ClusterDependencies depsCluster )
58
64
{
59
65
LegacyXmlSecurityHelper .fromXml (xml , deps );
60
66
61
67
if (deps .isEnabled ())
62
68
{
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 );
67
71
if (controller == null )
68
72
{
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" );
71
74
}
72
- CallbackHandler handler = (CallbackHandler ) newInstance (xmlCH );
75
+
76
+ XmlElement xmlCH = xml .getSafeElement ("callback-handler" );
77
+ CallbackHandler handler = newCallbackHandler (xmlCH , depsCluster );
73
78
74
79
deps .setAccessController (controller );
75
80
deps .setCallbackHandler (handler );
@@ -82,68 +87,99 @@ public static DefaultStandardDependencies fromXml(XmlElement xml, DefaultStandar
82
87
// ----- helpers --------------------------------------------------
83
88
84
89
/**
85
- * Instantiate the callbackHandler and accessController objects
90
+ * Instantiate the {@link AccessController} instance
86
91
*
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
89
94
*/
90
- private static Object newInstance (XmlElement xmlConfig )
95
+ private static AccessController newAccessController (XmlElement xmlConfig , ClusterDependencies depsCluster )
91
96
{
92
97
String sClass = xmlConfig .getSafeElement ("class-name" ).getString ();
93
98
94
- if (sClass .length () > 0 )
99
+ if (sClass .isEmpty () )
95
100
{
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" );
99
107
100
- try
108
+ try
109
+ {
110
+ if (xmlPwdProvider != null )
101
111
{
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 );
110
117
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 );
113
120
114
- int len = aoParam .length ;
121
+ ParameterizedBuilder <PasswordProvider > bldr = new PasswordProviderBuilderProcessor ().process (ctx , xmlPwdProvider );
122
+ PasswordProvider pwdProvider = bldr .realize (null , null , null );
115
123
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 )
122
133
{
123
- if (aoParam [3 ] instanceof String )
134
+ String password = (String ) aoParam [3 ];
135
+ if (!password .isEmpty ())
124
136
{
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." );
130
138
}
131
-
132
- aoParam [3 ] = pwdProvider ;
133
139
}
134
- }
135
140
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
+ }
142
143
}
144
+
145
+ Class <?> clz = ExternalizableHelper .loadClass (sClass , null , null );
146
+ return (AccessController ) ClassHelper .newInstance (clz , aoParam );
143
147
}
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 )
145
175
{
146
176
return null ;
147
177
}
178
+ if (builder instanceof InstanceBuilder <Object > && ((InstanceBuilder <Object >) builder ).isUndefined ())
179
+ {
180
+ return null ;
181
+ }
182
+
183
+ return (CallbackHandler ) builder .realize (null , null , null );
148
184
}
149
185
}
0 commit comments