|
62 | 62 | import org.opensearch.security.support.Base64Helper;
|
63 | 63 | import org.opensearch.security.support.ConfigConstants;
|
64 | 64 | import org.opensearch.security.support.HeaderHelper;
|
| 65 | +import org.opensearch.security.support.SerializationFormat; |
65 | 66 | import org.opensearch.security.user.User;
|
66 | 67 | import org.opensearch.threadpool.ThreadPool;
|
67 | 68 | import org.opensearch.transport.Transport.Connection;
|
@@ -150,7 +151,8 @@ public <T extends TransportResponse> void sendRequestDecorate(
|
150 | 151 | final String origCCSTransientMf = getThreadContext().getTransient(ConfigConstants.OPENDISTRO_SECURITY_MASKED_FIELD_CCS);
|
151 | 152 |
|
152 | 153 | final boolean isDebugEnabled = log.isDebugEnabled();
|
153 |
| - final boolean useJDKSerialization = connection.getVersion().before(ConfigConstants.FIRST_CUSTOM_SERIALIZATION_SUPPORTED_OS_VERSION); |
| 154 | + |
| 155 | + final var serializationFormat = SerializationFormat.determineFormat(connection.getVersion()); |
154 | 156 | final boolean isSameNodeRequest = localNode != null && localNode.equals(connection.getNode());
|
155 | 157 |
|
156 | 158 | try (ThreadContext.StoredContext stashedContext = getThreadContext().stashContext()) {
|
@@ -228,25 +230,28 @@ && getThreadContext().getHeader(ConfigConstants.OPENDISTRO_SECURITY_INJECTED_ROL
|
228 | 230 | );
|
229 | 231 | }
|
230 | 232 |
|
231 |
| - if (useJDKSerialization) { |
232 |
| - Map<String, String> jdkSerializedHeaders = new HashMap<>(); |
233 |
| - HeaderHelper.getAllSerializedHeaderNames() |
234 |
| - .stream() |
235 |
| - .filter(k -> headerMap.get(k) != null) |
236 |
| - .forEach(k -> jdkSerializedHeaders.put(k, Base64Helper.ensureJDKSerialized(headerMap.get(k)))); |
237 |
| - headerMap.putAll(jdkSerializedHeaders); |
| 233 | + try { |
| 234 | + if (serializationFormat == SerializationFormat.JDK) { |
| 235 | + Map<String, String> jdkSerializedHeaders = new HashMap<>(); |
| 236 | + HeaderHelper.getAllSerializedHeaderNames() |
| 237 | + .stream() |
| 238 | + .filter(k -> headerMap.get(k) != null) |
| 239 | + .forEach(k -> jdkSerializedHeaders.put(k, Base64Helper.ensureJDKSerialized(headerMap.get(k)))); |
| 240 | + headerMap.putAll(jdkSerializedHeaders); |
| 241 | + } |
| 242 | + getThreadContext().putHeader(headerMap); |
| 243 | + } catch (IllegalArgumentException iae) { |
| 244 | + log.debug("Failed to add headers information onto on thread context", iae); |
238 | 245 | }
|
239 | 246 |
|
240 |
| - getThreadContext().putHeader(headerMap); |
241 |
| - |
242 | 247 | ensureCorrectHeaders(
|
243 | 248 | remoteAddress0,
|
244 | 249 | user0,
|
245 | 250 | origin0,
|
246 | 251 | injectedUserString,
|
247 | 252 | injectedRolesString,
|
248 | 253 | isSameNodeRequest,
|
249 |
| - useJDKSerialization |
| 254 | + serializationFormat |
250 | 255 | );
|
251 | 256 |
|
252 | 257 | if (actionTraceEnabled.get()) {
|
@@ -275,7 +280,7 @@ private void ensureCorrectHeaders(
|
275 | 280 | final String injectedUserString,
|
276 | 281 | final String injectedRolesString,
|
277 | 282 | final boolean isSameNodeRequest,
|
278 |
| - final boolean useJDKSerialization |
| 283 | + final SerializationFormat format |
279 | 284 | ) {
|
280 | 285 | // keep original address
|
281 | 286 |
|
@@ -313,6 +318,7 @@ && getThreadContext().getHeader(ConfigConstants.OPENDISTRO_SECURITY_ORIGIN_HEADE
|
313 | 318 | getThreadContext().putTransient(ConfigConstants.OPENDISTRO_SECURITY_INJECTED_USER, injectedUserString);
|
314 | 319 | }
|
315 | 320 | } else {
|
| 321 | + final var useJDKSerialization = format == SerializationFormat.JDK; |
316 | 322 | if (transportAddress != null) {
|
317 | 323 | getThreadContext().putHeader(
|
318 | 324 | ConfigConstants.OPENDISTRO_SECURITY_REMOTE_ADDRESS_HEADER,
|
|
0 commit comments