Skip to content

Commit 96dc266

Browse files
RyanL1997cwperks
authored andcommitted
Adapt MediaType library change in core (#3050)
* Adapt the MediaType changes in core Signed-off-by: Ryan Liang <jiallian@amazon.com>
1 parent 912b7b8 commit 96dc266

6 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/main/java/com/amazon/dlic/auth/http/saml/AuthTokenProcessorHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private boolean handleLowLevel(RestRequest restRequest, RestChannel restChannel)
194194
XPathExpressionException, ParserConfigurationException, SAXException, SettingsException {
195195
try {
196196

197-
if (restRequest.getXContentType() != XContentType.JSON) {
197+
if (restRequest.getMediaType() != XContentType.JSON) {
198198
throw new OpenSearchSecurityException(
199199
"/_opendistro/_security/api/authtoken expects content with type application/json",
200200
RestStatus.UNSUPPORTED_MEDIA_TYPE

src/main/java/org/opensearch/security/auditlog/impl/AbstractAuditLog.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.opensearch.common.settings.Settings;
4949
import org.opensearch.common.transport.TransportAddress;
5050
import org.opensearch.common.xcontent.XContentHelper;
51+
import org.opensearch.core.xcontent.MediaType;
5152
import org.opensearch.common.xcontent.XContentType;
5253
import org.opensearch.common.xcontent.json.JsonXContent;
5354
import org.opensearch.core.xcontent.NamedXContentRegistry;
@@ -656,7 +657,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index
656657
// originalResult.internalSourceRef()));
657658

658659
// current source, normally not null or empty
659-
msg.addTupleToRequestBody(new Tuple<XContentType, BytesReference>(XContentType.JSON, currentIndex.source()));
660+
msg.addTupleToRequestBody(new Tuple<MediaType, BytesReference>(XContentType.JSON, currentIndex.source()));
660661
}
661662

662663
}

src/main/java/org/opensearch/security/auditlog/impl/AuditMessage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.opensearch.common.collect.Tuple;
3939
import org.opensearch.common.transport.TransportAddress;
4040
import org.opensearch.common.xcontent.XContentHelper;
41+
import org.opensearch.core.xcontent.MediaType;
4142
import org.opensearch.common.xcontent.XContentType;
4243
import org.opensearch.common.xcontent.json.JsonXContent;
4344
import org.opensearch.core.common.Strings;
@@ -206,7 +207,7 @@ void addSecurityConfigWriteDiffSource(final String diff, final String id) {
206207
// }
207208
// }
208209

209-
public void addTupleToRequestBody(Tuple<XContentType, BytesReference> xContentTuple) {
210+
public void addTupleToRequestBody(Tuple<MediaType, BytesReference> xContentTuple) {
210211
if (xContentTuple != null) {
211212
try {
212213
auditInfo.put(REQUEST_BODY, XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1()));
@@ -378,7 +379,7 @@ void addRestRequestInfo(final RestRequest request, final AuditConfig.Filter filt
378379
addRestMethod(request.method());
379380
if (filter.shouldLogRequestBody() && request.hasContentOrSourceParam()) {
380381
try {
381-
final Tuple<XContentType, BytesReference> xContentTuple = request.contentOrSourceParam();
382+
final Tuple<MediaType, BytesReference> xContentTuple = request.contentOrSourceParam();
382383
final String requestBody = XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1());
383384
if (path != null
384385
&& requestBody != null

src/main/java/org/opensearch/security/auditlog/impl/RequestResolver.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.opensearch.common.settings.Settings;
4848
import org.opensearch.common.transport.TransportAddress;
4949
import org.opensearch.common.xcontent.XContentFactory;
50+
import org.opensearch.core.xcontent.MediaType;
5051
import org.opensearch.common.xcontent.XContentType;
5152
import org.opensearch.core.xcontent.XContentBuilder;
5253
import org.opensearch.core.index.Index;
@@ -381,7 +382,7 @@ private static void addIndicesSourceSafe(
381382
final String[] indices,
382383
final IndexNameExpressionResolver resolver,
383384
final ClusterService cs,
384-
final XContentType xContentType,
385+
final MediaType mediaType,
385386
final Object source,
386387
final Settings settings,
387388
boolean resolveIndices,
@@ -423,27 +424,27 @@ private static void addIndicesSourceSafe(
423424
if (sourceIsSensitive && source != null) {
424425
if (!allIndicesMatcher.test(securityIndex)) {
425426
if (source instanceof BytesReference) {
426-
msg.addTupleToRequestBody(convertSource(xContentType, (BytesReference) source));
427+
msg.addTupleToRequestBody(convertSource(mediaType, (BytesReference) source));
427428
} else {
428429
msg.addMapToRequestBody((Map) source);
429430
}
430431
}
431432
} else if (source != null) {
432433
if (source instanceof BytesReference) {
433-
msg.addTupleToRequestBody(convertSource(xContentType, (BytesReference) source));
434+
msg.addTupleToRequestBody(convertSource(mediaType, (BytesReference) source));
434435
} else {
435436
msg.addMapToRequestBody((Map) source);
436437
}
437438
}
438439
}
439440
}
440441

441-
private static Tuple<XContentType, BytesReference> convertSource(XContentType type, BytesReference bytes) {
442+
private static Tuple<MediaType, BytesReference> convertSource(MediaType type, BytesReference bytes) {
442443
if (type == null) {
443444
type = XContentType.JSON;
444445
}
445446

446-
return new Tuple<XContentType, BytesReference>(type, bytes);
447+
return new Tuple<MediaType, BytesReference>(type, bytes);
447448
}
448449

449450
private static String[] arrayOrEmpty(String[] array) {

src/main/java/org/opensearch/security/dlic/rest/api/PatchableResourceApiAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public PatchableResourceApiAction(
7171
}
7272

7373
private void handlePatch(RestChannel channel, final RestRequest request, final Client client) throws IOException {
74-
if (request.getXContentType() != XContentType.JSON) {
74+
if (request.getMediaType() != XContentType.JSON) {
7575
badRequestResponse(channel, "PATCH accepts only application/json");
7676
return;
7777
}

src/test/java/com/amazon/dlic/auth/http/saml/HTTPSamlAuthenticatorTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.opensearch.core.common.bytes.BytesReference;
4646
import org.opensearch.common.io.stream.BytesStreamOutput;
4747
import org.opensearch.common.settings.Settings;
48-
import org.opensearch.common.xcontent.XContentType;
48+
import org.opensearch.core.xcontent.MediaType;
4949
import org.opensearch.core.xcontent.XContentBuilder;
5050
import org.opensearch.rest.RestChannel;
5151
import org.opensearch.rest.RestRequest;
@@ -992,7 +992,7 @@ public XContentBuilder newErrorBuilder() throws IOException {
992992
}
993993

994994
@Override
995-
public XContentBuilder newBuilder(XContentType xContentType, boolean useFiltering) throws IOException {
995+
public XContentBuilder newBuilder(MediaType mediaType, boolean useFiltering) throws IOException {
996996
return null;
997997
}
998998

@@ -1018,8 +1018,7 @@ public void sendResponse(RestResponse response) {
10181018
}
10191019

10201020
@Override
1021-
public XContentBuilder newBuilder(XContentType xContentType, XContentType responseContentType, boolean useFiltering)
1022-
throws IOException {
1021+
public XContentBuilder newBuilder(MediaType mediaType, MediaType responseContentType, boolean useFiltering) throws IOException {
10231022
return null;
10241023
}
10251024

0 commit comments

Comments
 (0)