diff --git a/src/integrationTest/java/org/opensearch/test/framework/cluster/LocalOpenSearchCluster.java b/src/integrationTest/java/org/opensearch/test/framework/cluster/LocalOpenSearchCluster.java index 2a4b417145..b2dafe297c 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/cluster/LocalOpenSearchCluster.java +++ b/src/integrationTest/java/org/opensearch/test/framework/cluster/LocalOpenSearchCluster.java @@ -60,7 +60,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.http.BindHttpException; import org.opensearch.node.PluginAwareNode; import org.opensearch.plugins.Plugin; @@ -324,7 +324,7 @@ public void waitForCluster(ClusterHealthStatus status, TimeValue timeout, int ex .actionGet(); if (log.isDebugEnabled()) { - log.debug("Current ClusterState:\n{}", Strings.toString(XContentType.JSON, healthResponse)); + log.debug("Current ClusterState:\n{}", Strings.toString(MediaType.JSON, healthResponse)); } if (healthResponse.isTimedOut()) { diff --git a/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java b/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java index f446cac933..757699eff5 100644 --- a/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java +++ b/src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java @@ -70,7 +70,7 @@ import org.apache.logging.log4j.Logger; import org.opensearch.common.Strings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContentObject; import org.opensearch.security.DefaultObjectMapper; @@ -163,7 +163,7 @@ private StringEntity toStringEntity(String body) { } public HttpResponse putJson(String path, ToXContentObject body) { - return putJson(path, Strings.toString(XContentType.JSON, body)); + return putJson(path, Strings.toString(MediaType.JSON, body)); } public HttpResponse put(String path) { @@ -182,7 +182,7 @@ public HttpResponse postJson(String path, String body, Header... headers) { } public HttpResponse postJson(String path, ToXContentObject body) { - return postJson(path, Strings.toString(XContentType.JSON, body)); + return postJson(path, Strings.toString(MediaType.JSON, body)); } public HttpResponse post(String path) { diff --git a/src/main/java/com/amazon/dlic/auth/http/saml/AuthTokenProcessorHandler.java b/src/main/java/com/amazon/dlic/auth/http/saml/AuthTokenProcessorHandler.java index fe995b3287..3b06a6c55d 100644 --- a/src/main/java/com/amazon/dlic/auth/http/saml/AuthTokenProcessorHandler.java +++ b/src/main/java/com/amazon/dlic/auth/http/saml/AuthTokenProcessorHandler.java @@ -55,7 +55,7 @@ import org.opensearch.SpecialPermission; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.rest.BytesRestResponse; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; @@ -192,7 +192,7 @@ private boolean handleLowLevel(RestRequest restRequest, RestChannel restChannel) XPathExpressionException, ParserConfigurationException, SAXException, SettingsException { try { - if (restRequest.getXContentType() != XContentType.JSON) { + if (restRequest.getMediaType() != MediaType.JSON) { throw new OpenSearchSecurityException( "/_opendistro/_security/api/authtoken expects content with type application/json", RestStatus.UNSUPPORTED_MEDIA_TYPE diff --git a/src/main/java/org/opensearch/security/action/whoami/WhoAmIResponse.java b/src/main/java/org/opensearch/security/action/whoami/WhoAmIResponse.java index 0b30aeb94b..e474e29aa9 100644 --- a/src/main/java/org/opensearch/security/action/whoami/WhoAmIResponse.java +++ b/src/main/java/org/opensearch/security/action/whoami/WhoAmIResponse.java @@ -32,7 +32,7 @@ import org.opensearch.common.Strings; import org.opensearch.core.common.io.stream.StreamInput; import org.opensearch.core.common.io.stream.StreamOutput; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; @@ -105,6 +105,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws @Override public String toString() { - return Strings.toString(XContentType.JSON, this, true, true); + return Strings.toString(MediaType.JSON, this, true, true); } } diff --git a/src/main/java/org/opensearch/security/auditlog/impl/AbstractAuditLog.java b/src/main/java/org/opensearch/security/auditlog/impl/AbstractAuditLog.java index d4cc756697..d204ca4b49 100644 --- a/src/main/java/org/opensearch/security/auditlog/impl/AbstractAuditLog.java +++ b/src/main/java/org/opensearch/security/auditlog/impl/AbstractAuditLog.java @@ -48,7 +48,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -572,14 +572,14 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, originalResult.internalSourceRef(), - XContentType.JSON + MediaType.JSON ) ) { Object base64 = parser.map().values().iterator().next(); if (base64 instanceof String) { originalSource = (new String(BaseEncoding.base64().decode((String) base64), StandardCharsets.UTF_8)); } else { - originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, XContentType.JSON); + originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, MediaType.JSON); } } catch (Exception e) { log.error(e.toString()); @@ -590,14 +590,14 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, currentIndex.source(), - XContentType.JSON + MediaType.JSON ) ) { Object base64 = parser.map().values().iterator().next(); if (base64 instanceof String) { currentSource = new String(BaseEncoding.base64().decode((String) base64), StandardCharsets.UTF_8); } else { - currentSource = XContentHelper.convertToJson(currentIndex.source(), false, XContentType.JSON); + currentSource = XContentHelper.convertToJson(currentIndex.source(), false, MediaType.JSON); } } catch (Exception e) { log.error(e.toString()); @@ -608,8 +608,8 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index ); msg.addSecurityConfigWriteDiffSource(diffnode.size() == 0 ? "" : diffnode.toString(), id); } else { - originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, XContentType.JSON); - currentSource = XContentHelper.convertToJson(currentIndex.source(), false, XContentType.JSON); + originalSource = XContentHelper.convertToJson(originalResult.internalSourceRef(), false, MediaType.JSON); + currentSource = XContentHelper.convertToJson(currentIndex.source(), false, MediaType.JSON); final JsonNode diffnode = JsonDiff.asJson( DefaultObjectMapper.objectMapper.readTree(originalSource), DefaultObjectMapper.objectMapper.readTree(currentSource) @@ -629,7 +629,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, currentIndex.source(), - XContentType.JSON + MediaType.JSON ) ) { Object base64 = parser.map().values().iterator().next(); @@ -640,7 +640,7 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index ); } else { msg.addSecurityConfigTupleToRequestBody( - new Tuple(XContentType.JSON, currentIndex.source()), + new Tuple(MediaType.JSON, currentIndex.source()), id ); } @@ -653,11 +653,11 @@ public void logDocumentWritten(ShardId shardId, GetResult originalResult, Index } else { // previous source, can be null if document is a new one - // msg.ComplianceWritePreviousSource(new Tuple(XContentType.JSON, + // msg.ComplianceWritePreviousSource(new Tuple(MediaType.JSON, // originalResult.internalSourceRef())); // current source, normally not null or empty - msg.addTupleToRequestBody(new Tuple(XContentType.JSON, currentIndex.source())); + msg.addTupleToRequestBody(new Tuple(MediaType.JSON, currentIndex.source())); } } @@ -728,7 +728,7 @@ public Map run() { final String sha256 = DigestUtils.sha256Hex(configAsMap.toString() + envAsMap.toString() + propsAsMap.toString()); AuditMessage msg = new AuditMessage(AuditCategory.COMPLIANCE_EXTERNAL_CONFIG, clusterService, null, null); - try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { + try (XContentBuilder builder = XContentBuilder.builder(MediaType.JSON.xContent())) { builder.startObject(); builder.startObject("external_configuration"); builder.field("opensearch_yml", configAsMap); diff --git a/src/main/java/org/opensearch/security/auditlog/impl/AuditMessage.java b/src/main/java/org/opensearch/security/auditlog/impl/AuditMessage.java index f7e4255e03..0891561b3c 100644 --- a/src/main/java/org/opensearch/security/auditlog/impl/AuditMessage.java +++ b/src/main/java/org/opensearch/security/auditlog/impl/AuditMessage.java @@ -38,7 +38,7 @@ import org.opensearch.common.collect.Tuple; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.common.Strings; import org.opensearch.core.index.shard.ShardId; @@ -205,7 +205,7 @@ void addSecurityConfigWriteDiffSource(final String diff, final String id) { // } // } - public void addTupleToRequestBody(Tuple xContentTuple) { + public void addTupleToRequestBody(Tuple xContentTuple) { if (xContentTuple != null) { try { auditInfo.put(REQUEST_BODY, XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1())); @@ -241,7 +241,7 @@ void addSecurityConfigContentToRequestBody(final String source, final String id) } } - void addSecurityConfigTupleToRequestBody(final Tuple xContentTuple, final String id) { + void addSecurityConfigTupleToRequestBody(final Tuple xContentTuple, final String id) { if (xContentTuple != null) { try { addSecurityConfigContentToRequestBody(XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1()), id); @@ -377,7 +377,7 @@ void addRestRequestInfo(final RestRequest request, final AuditConfig.Filter filt addRestMethod(request.method()); if (filter.shouldLogRequestBody() && request.hasContentOrSourceParam()) { try { - final Tuple xContentTuple = request.contentOrSourceParam(); + final Tuple xContentTuple = request.contentOrSourceParam(); final String requestBody = XContentHelper.convertToJson(xContentTuple.v2(), false, xContentTuple.v1()); if (path != null && requestBody != null diff --git a/src/main/java/org/opensearch/security/auditlog/impl/RequestResolver.java b/src/main/java/org/opensearch/security/auditlog/impl/RequestResolver.java index c37247e7db..8b264c98f1 100644 --- a/src/main/java/org/opensearch/security/auditlog/impl/RequestResolver.java +++ b/src/main/java/org/opensearch/security/auditlog/impl/RequestResolver.java @@ -47,7 +47,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.index.Index; import org.opensearch.index.reindex.DeleteByQueryRequest; @@ -287,7 +287,7 @@ private static AuditMessage resolveInner( indices, resolver, cs, - XContentType.JSON, + MediaType.JSON, sourceAsMap, settings, resolveIndices, @@ -381,7 +381,7 @@ private static void addIndicesSourceSafe( final String[] indices, final IndexNameExpressionResolver resolver, final ClusterService cs, - final XContentType xContentType, + final MediaType xContentType, final Object source, final Settings settings, boolean resolveIndices, @@ -438,12 +438,12 @@ private static void addIndicesSourceSafe( } } - private static Tuple convertSource(XContentType type, BytesReference bytes) { + private static Tuple convertSource(MediaType type, BytesReference bytes) { if (type == null) { - type = XContentType.JSON; + type = MediaType.JSON; } - return new Tuple(type, bytes); + return new Tuple(type, bytes); } private static String[] arrayOrEmpty(String[] array) { diff --git a/src/main/java/org/opensearch/security/configuration/ConfigurationLoaderSecurity7.java b/src/main/java/org/opensearch/security/configuration/ConfigurationLoaderSecurity7.java index 3cf7ce534c..5044b90fdb 100644 --- a/src/main/java/org/opensearch/security/configuration/ConfigurationLoaderSecurity7.java +++ b/src/main/java/org/opensearch/security/configuration/ConfigurationLoaderSecurity7.java @@ -51,7 +51,7 @@ import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.security.DefaultObjectMapper; @@ -277,7 +277,7 @@ private SecurityDynamicConfiguration toConfig(GetResponse singleGetResponse, XContentParser parser = null; try { - parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, ref, XContentType.JSON); + parser = XContentHelper.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, ref, MediaType.JSON); parser.nextToken(); parser.nextToken(); diff --git a/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java b/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java index c6ecbc9ac4..b2b060bc4c 100644 --- a/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java +++ b/src/main/java/org/opensearch/security/configuration/ConfigurationRepository.java @@ -63,7 +63,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.util.concurrent.ThreadContext.StoredContext; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.env.Environment; import org.opensearch.core.rest.RestStatus; import org.opensearch.security.auditlog.AuditLog; @@ -464,7 +464,7 @@ public Map> getConfigurationsFromIndex( if (logComplianceEvent && auditLog.getComplianceConfig().isEnabled()) { CType configurationType = configTypes.iterator().next(); Map fields = new HashMap(); - fields.put(configurationType.toLCString(), Strings.toString(XContentType.JSON, retVal.get(configurationType))); + fields.put(configurationType.toLCString(), Strings.toString(MediaType.JSON, retVal.get(configurationType))); auditLog.logDocumentRead(this.securityIndex, configurationType.toLCString(), null, fields); } diff --git a/src/main/java/org/opensearch/security/configuration/DlsFlsFilterLeafReader.java b/src/main/java/org/opensearch/security/configuration/DlsFlsFilterLeafReader.java index 508c3dd9b4..ca67cdeb2b 100644 --- a/src/main/java/org/opensearch/security/configuration/DlsFlsFilterLeafReader.java +++ b/src/main/java/org/opensearch/security/configuration/DlsFlsFilterLeafReader.java @@ -70,7 +70,7 @@ import org.opensearch.common.lucene.index.SequentialStoredFieldsLeafReader; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.common.xcontent.support.XContentMapValues; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.index.IndexService; @@ -697,10 +697,10 @@ public void binaryField(final FieldInfo fieldInfo, final byte[] value) throws IO if (fieldInfo.name.equals("_source")) { final BytesReference bytesRef = new BytesArray(value); - final Tuple> bytesRefTuple = XContentHelper.convertToMap( + final Tuple> bytesRefTuple = XContentHelper.convertToMap( bytesRef, false, - XContentType.JSON + MediaType.JSON ); Map filteredSource = bytesRefTuple.v2(); MapUtils.deepTraverseMap(filteredSource, HASH_CB); diff --git a/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java b/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java index de7ffe1fc2..c70c91dc29 100644 --- a/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java +++ b/src/main/java/org/opensearch/security/configuration/DlsFlsValveImpl.java @@ -51,7 +51,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.index.query.ParsedQuery; import org.opensearch.core.rest.RestStatus; @@ -230,10 +230,10 @@ public boolean invoke( StringBuilder sb = new StringBuilder(); if (searchRequest.source() != null) { - sb.append(Strings.toString(XContentType.JSON, searchRequest.source()) + System.lineSeparator()); + sb.append(Strings.toString(MediaType.JSON, searchRequest.source()) + System.lineSeparator()); } - sb.append(Strings.toString(XContentType.JSON, af) + System.lineSeparator()); + sb.append(Strings.toString(MediaType.JSON, af) + System.lineSeparator()); LogManager.getLogger("debuglogger").error(sb.toString()); @@ -245,7 +245,7 @@ public boolean invoke( LogManager.getLogger("debuglogger") .error( "Shard requestcache enabled for " - + (searchRequest.source() == null ? "" : Strings.toString(XContentType.JSON, searchRequest.source())) + + (searchRequest.source() == null ? "" : Strings.toString(MediaType.JSON, searchRequest.source())) ); } diff --git a/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java b/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java index 727624e4e4..65f347e19d 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java +++ b/src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java @@ -34,7 +34,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext.StoredContext; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.index.engine.VersionConflictEngineException; @@ -376,7 +376,7 @@ public static void saveAndUpdateConfigs( .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .setIfSeqNo(configuration.getSeqNo()) .setIfPrimaryTerm(configuration.getPrimaryTerm()) - .source(id, XContentHelper.toXContent(configuration, XContentType.JSON, false)), + .source(id, XContentHelper.toXContent(configuration, MediaType.JSON, false)), new ConfigUpdatingActionListener<>(new String[] { id }, client, actionListener) ); } catch (IOException e) { diff --git a/src/main/java/org/opensearch/security/dlic/rest/api/MigrateApiAction.java b/src/main/java/org/opensearch/security/dlic/rest/api/MigrateApiAction.java index ff82af9426..9692a63a9d 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/api/MigrateApiAction.java +++ b/src/main/java/org/opensearch/security/dlic/rest/api/MigrateApiAction.java @@ -36,7 +36,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.Settings.Builder; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestController; import org.opensearch.rest.RestRequest; @@ -208,7 +208,7 @@ public void onResponse(CreateIndexResponse response) { final String id = dynamicConfiguration.getCType().toLCString(); final BytesReference xContent = XContentHelper.toXContent( dynamicConfiguration, - XContentType.JSON, + MediaType.JSON, false ); br.add(new IndexRequest().id(id).source(id, xContent)); diff --git a/src/main/java/org/opensearch/security/dlic/rest/api/PatchableResourceApiAction.java b/src/main/java/org/opensearch/security/dlic/rest/api/PatchableResourceApiAction.java index 6050b9785e..7c0ae02fe9 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/api/PatchableResourceApiAction.java +++ b/src/main/java/org/opensearch/security/dlic/rest/api/PatchableResourceApiAction.java @@ -31,7 +31,7 @@ import org.opensearch.core.common.bytes.BytesArray; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.common.Strings; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestController; @@ -71,7 +71,7 @@ public PatchableResourceApiAction( } private void handlePatch(RestChannel channel, final RestRequest request, final Client client) throws IOException { - if (request.getXContentType() != XContentType.JSON) { + if (request.getMediaType() != MediaType.JSON) { badRequestResponse(channel, "PATCH accepts only application/json"); return; } diff --git a/src/main/java/org/opensearch/security/dlic/rest/support/Utils.java b/src/main/java/org/opensearch/security/dlic/rest/support/Utils.java index 52220b2450..4d283c3844 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/support/Utils.java +++ b/src/main/java/org/opensearch/security/dlic/rest/support/Utils.java @@ -39,7 +39,7 @@ import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.util.concurrent.ThreadContext; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.ToXContent; @@ -60,8 +60,8 @@ public class Utils { public static Map convertJsonToxToStructuredMap(ToXContent jsonContent) { Map map = null; try { - final BytesReference bytes = XContentHelper.toXContent(jsonContent, XContentType.JSON, false); - map = XContentHelper.convertToMap(bytes, false, XContentType.JSON).v2(); + final BytesReference bytes = XContentHelper.toXContent(jsonContent, MediaType.JSON, false); + map = XContentHelper.convertToMap(bytes, false, MediaType.JSON).v2(); } catch (IOException e1) { throw ExceptionsHelper.convertToOpenSearchException(e1); } @@ -71,7 +71,7 @@ public static Map convertJsonToxToStructuredMap(ToXContent jsonC public static Map convertJsonToxToStructuredMap(String jsonContent) { try ( - XContentParser parser = XContentType.JSON.xContent() + XContentParser parser = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, jsonContent) ) { return parser.map(); @@ -90,7 +90,7 @@ private static BytesReference convertStructuredMapToBytes(Map structu public static String convertStructuredMapToJson(Map structuredMap) { try { - return XContentHelper.convertToJson(convertStructuredMapToBytes(structuredMap), false, XContentType.JSON); + return XContentHelper.convertToJson(convertStructuredMapToBytes(structuredMap), false, MediaType.JSON); } catch (IOException e) { throw new OpenSearchParseException("Failed to convert map", e); } @@ -111,7 +111,7 @@ public static JsonNode convertJsonToJackson(ToXContent jsonContent, boolean omit pm.put("omit_defaults", String.valueOf(omitDefaults)); ToXContent.MapParams params = new ToXContent.MapParams(pm); - final BytesReference bytes = XContentHelper.toXContent(jsonContent, XContentType.JSON, params, false); + final BytesReference bytes = XContentHelper.toXContent(jsonContent, MediaType.JSON, params, false); return DefaultObjectMapper.readTree(bytes.utf8ToString()); } catch (IOException e1) { throw ExceptionsHelper.convertToOpenSearchException(e1); @@ -126,7 +126,7 @@ public static T serializeToXContentToPojo(ToXContent jsonContent, Class c return serializeToXContentToPojo(((BytesReference) jsonContent).utf8ToString(), clazz); } - final BytesReference bytes = XContentHelper.toXContent(jsonContent, XContentType.JSON, false); + final BytesReference bytes = XContentHelper.toXContent(jsonContent, MediaType.JSON, false); return DefaultObjectMapper.readValue(bytes.utf8ToString(), clazz); } catch (IOException e1) { throw ExceptionsHelper.convertToOpenSearchException(e1); diff --git a/src/main/java/org/opensearch/security/dlic/rest/validation/AbstractConfigurationValidator.java b/src/main/java/org/opensearch/security/dlic/rest/validation/AbstractConfigurationValidator.java index 543ad4b4a7..bfa50c3be4 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/validation/AbstractConfigurationValidator.java +++ b/src/main/java/org/opensearch/security/dlic/rest/validation/AbstractConfigurationValidator.java @@ -31,7 +31,7 @@ import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; @@ -202,7 +202,7 @@ public boolean validate() { } private boolean checkDatatypes() throws Exception { - String contentAsJson = XContentHelper.convertToJson(content, false, XContentType.JSON); + String contentAsJson = XContentHelper.convertToJson(content, false, MediaType.JSON); try (JsonParser parser = factory.createParser(contentAsJson)) { JsonToken token = null; while ((token = parser.nextToken()) != null) { diff --git a/src/main/java/org/opensearch/security/dlic/rest/validation/CredentialsValidator.java b/src/main/java/org/opensearch/security/dlic/rest/validation/CredentialsValidator.java index 283af8dd00..7d9cb324d4 100644 --- a/src/main/java/org/opensearch/security/dlic/rest/validation/CredentialsValidator.java +++ b/src/main/java/org/opensearch/security/dlic/rest/validation/CredentialsValidator.java @@ -17,7 +17,7 @@ import org.opensearch.core.common.compress.NotXContentException; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.common.Strings; import org.opensearch.rest.RestRequest; import org.opensearch.security.ssl.util.Utils; @@ -50,7 +50,7 @@ public boolean validate() { && this.content != null && this.content.length() > 1) { try { - final Map contentAsMap = XContentHelper.convertToMap(this.content, false, XContentType.JSON).v2(); + final Map contentAsMap = XContentHelper.convertToMap(this.content, false, MediaType.JSON).v2(); final String password = (String) contentAsMap.get("password"); if (password != null) { // Password is not allowed to be empty if present. diff --git a/src/main/java/org/opensearch/security/httpclient/HttpClient.java b/src/main/java/org/opensearch/security/httpclient/HttpClient.java index ba788a2c13..951cd53c52 100644 --- a/src/main/java/org/opensearch/security/httpclient/HttpClient.java +++ b/src/main/java/org/opensearch/security/httpclient/HttpClient.java @@ -61,7 +61,7 @@ import org.opensearch.client.RestClient; import org.opensearch.client.RestClientBuilder; import org.opensearch.client.RestHighLevelClient; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; public class HttpClient implements Closeable { @@ -216,7 +216,7 @@ public boolean index(final String content, final String index, final String type final IndexRequest ir = new IndexRequest(index); final IndexResponse response = rclient.index( - ir.setRefreshPolicy(refresh ? RefreshPolicy.IMMEDIATE : RefreshPolicy.NONE).source(content, XContentType.JSON), + ir.setRefreshPolicy(refresh ? RefreshPolicy.IMMEDIATE : RefreshPolicy.NONE).source(content, MediaType.JSON), RequestOptions.DEFAULT ); diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java index 994989416b..baefad98de 100644 --- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java +++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV6.java @@ -45,7 +45,7 @@ import com.google.common.collect.Multimaps; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.auth.AuthDomain; import org.opensearch.security.auth.AuthFailureListener; import org.opensearch.security.auth.AuthenticationBackend; @@ -247,7 +247,7 @@ private void buildAAA() { // DynamicConfiguration.checkKeyFunction()).build(), configPath); .put( Settings.builder() - .loadFromSource(ad.getValue().authorization_backend.configAsJson(), XContentType.JSON) + .loadFromSource(ad.getValue().authorization_backend.configAsJson(), MediaType.JSON) .build() ) .build(), @@ -298,7 +298,7 @@ private void buildAAA() { // DynamicConfiguration.checkKeyFunction()).build() .put( Settings.builder() - .loadFromSource(ad.getValue().authentication_backend.configAsJson(), XContentType.JSON) + .loadFromSource(ad.getValue().authentication_backend.configAsJson(), MediaType.JSON) .build() ) .build(), @@ -318,7 +318,7 @@ private void buildAAA() { // DynamicConfiguration.checkKeyFunction()).build(), .put( Settings.builder() - .loadFromSource(ad.getValue().http_authenticator.configAsJson(), XContentType.JSON) + .loadFromSource(ad.getValue().http_authenticator.configAsJson(), MediaType.JSON) .build() ) .build() @@ -429,7 +429,7 @@ private void createAuthFailureListeners( Settings entrySettings = Settings.builder() .put(opensearchSettings) - .put(Settings.builder().loadFromSource(entry.getValue().asJson(), XContentType.JSON).build()) + .put(Settings.builder().loadFromSource(entry.getValue().asJson(), MediaType.JSON).build()) .build(); String type = entry.getValue().type; diff --git a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java index 60637e4b8c..251aa32847 100644 --- a/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java +++ b/src/main/java/org/opensearch/security/securityconf/DynamicConfigModelV7.java @@ -48,7 +48,7 @@ import org.opensearch.SpecialPermission; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.auth.AuthDomain; import org.opensearch.security.auth.AuthFailureListener; import org.opensearch.security.auth.AuthenticationBackend; @@ -249,7 +249,7 @@ private void buildAAA() { // DynamicConfiguration.checkKeyFunction()).build(), configPath); .put( Settings.builder() - .loadFromSource(ad.getValue().authorization_backend.configAsJson(), XContentType.JSON) + .loadFromSource(ad.getValue().authorization_backend.configAsJson(), MediaType.JSON) .build() ) .build(), @@ -299,7 +299,7 @@ private void buildAAA() { // DynamicConfiguration.checkKeyFunction()).build() .put( Settings.builder() - .loadFromSource(ad.getValue().authentication_backend.configAsJson(), XContentType.JSON) + .loadFromSource(ad.getValue().authentication_backend.configAsJson(), MediaType.JSON) .build() ) .build(), @@ -319,7 +319,7 @@ private void buildAAA() { // DynamicConfiguration.checkKeyFunction()).build(), .put( Settings.builder() - .loadFromSource(ad.getValue().http_authenticator.configAsJson(), XContentType.JSON) + .loadFromSource(ad.getValue().http_authenticator.configAsJson(), MediaType.JSON) .build() ) .build() @@ -427,7 +427,7 @@ private void createAuthFailureListeners( Settings entrySettings = Settings.builder() .put(opensearchSettings) - .put(Settings.builder().loadFromSource(entry.getValue().asJson(), XContentType.JSON).build()) + .put(Settings.builder().loadFromSource(entry.getValue().asJson(), MediaType.JSON).build()) .build(); String type = entry.getValue().type; diff --git a/src/main/java/org/opensearch/security/support/ConfigHelper.java b/src/main/java/org/opensearch/security/support/ConfigHelper.java index 92bf069028..d9174d9de5 100644 --- a/src/main/java/org/opensearch/security/support/ConfigHelper.java +++ b/src/main/java/org/opensearch/security/support/ConfigHelper.java @@ -44,7 +44,7 @@ import org.opensearch.client.Client; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; @@ -93,7 +93,7 @@ public static void uploadFile( final IndexRequest indexRequest = new IndexRequest(index).id(configType) .opType(OpType.CREATE) .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source(configType, readXContent(reader, XContentType.YAML)); + .source(configType, readXContent(reader, MediaType.YAML)); final String res = tc.index(indexRequest).actionGet().getId(); if (!configType.equals(res)) { diff --git a/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java b/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java index 267ab2bc18..a62399a7da 100644 --- a/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java +++ b/src/main/java/org/opensearch/security/tools/AuditConfigMigrater.java @@ -26,7 +26,7 @@ import org.apache.commons.cli.Options; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.ToXContent; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.security.DefaultObjectMapper; @@ -116,7 +116,7 @@ public static void main(String[] args) { // write to opensearch.output.yml try (FileOutputStream outputStream = new FileOutputStream(opensearchOutput)) { - XContentBuilder builder = new XContentBuilder(XContentType.YAML.xContent(), outputStream); + XContentBuilder builder = new XContentBuilder(MediaType.YAML.xContent(), outputStream); builder.startObject(); settingsBuilder.build().toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("flat_settings", "true"))); builder.endObject(); diff --git a/src/main/java/org/opensearch/security/tools/SecurityAdmin.java b/src/main/java/org/opensearch/security/tools/SecurityAdmin.java index d2dc85f9d2..a8d4aa0136 100644 --- a/src/main/java/org/opensearch/security/tools/SecurityAdmin.java +++ b/src/main/java/org/opensearch/security/tools/SecurityAdmin.java @@ -115,7 +115,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; @@ -1101,7 +1101,7 @@ private static boolean uploadFile( final String res = restHighLevelClient.index( new IndexRequest(index).id(id) .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source(_id, readXContent(resolveEnvVars ? replaceEnvVars(content, Settings.EMPTY) : content, XContentType.YAML)), + .source(_id, readXContent(resolveEnvVars ? replaceEnvVars(content, Settings.EMPTY) : content, MediaType.YAML)), RequestOptions.DEFAULT ).getId(); @@ -1239,7 +1239,7 @@ private static String convertToYaml(String type, BytesReference bytes, boolean p if (prettyPrint) { builder.prettyPrint(); } - builder.rawValue(new ByteArrayInputStream(parser.binaryValue()), XContentType.YAML); + builder.rawValue(new ByteArrayInputStream(parser.binaryValue()), MediaType.YAML); return Strings.toString(builder); } } @@ -1267,7 +1267,7 @@ protected static void generateDiagnoseTrace(final RestHighLevelClient restHighLe try { sb.append("ClusterHealthRequest:" + System.lineSeparator()); ClusterHealthResponse nir = restHighLevelClient.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT); - sb.append(Strings.toString(XContentType.JSON, nir, true, true)); + sb.append(Strings.toString(MediaType.JSON, nir, true, true)); } catch (Exception e1) { sb.append(ExceptionsHelper.stackTrace(e1)); } diff --git a/src/main/java/org/opensearch/security/user/UserService.java b/src/main/java/org/opensearch/security/user/UserService.java index 0653948a38..6dc90982d2 100644 --- a/src/main/java/org/opensearch/security/user/UserService.java +++ b/src/main/java/org/opensearch/security/user/UserService.java @@ -34,7 +34,7 @@ import org.opensearch.common.inject.Inject; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.configuration.ConfigurationRepository; import org.opensearch.security.securityconf.DynamicConfigFactory; @@ -287,7 +287,7 @@ public static void saveAndUpdateConfigs( .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .setIfSeqNo(configuration.getSeqNo()) .setIfPrimaryTerm(configuration.getPrimaryTerm()) - .source(id, XContentHelper.toXContent(configuration, XContentType.JSON, false)) + .source(id, XContentHelper.toXContent(configuration, MediaType.JSON, false)) ); } catch (IOException e) { throw ExceptionsHelper.convertToOpenSearchException(e); diff --git a/src/test/java/com/amazon/dlic/auth/http/saml/HTTPSamlAuthenticatorTest.java b/src/test/java/com/amazon/dlic/auth/http/saml/HTTPSamlAuthenticatorTest.java index eec2ff76b7..24caa4f803 100644 --- a/src/test/java/com/amazon/dlic/auth/http/saml/HTTPSamlAuthenticatorTest.java +++ b/src/test/java/com/amazon/dlic/auth/http/saml/HTTPSamlAuthenticatorTest.java @@ -45,7 +45,7 @@ import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.io.stream.BytesStreamOutput; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.rest.RestChannel; import org.opensearch.rest.RestRequest; @@ -992,7 +992,7 @@ public XContentBuilder newErrorBuilder() throws IOException { } @Override - public XContentBuilder newBuilder(XContentType xContentType, boolean useFiltering) throws IOException { + public XContentBuilder newBuilder(MediaType xContentType, boolean useFiltering) throws IOException { return null; } @@ -1018,7 +1018,7 @@ public void sendResponse(RestResponse response) { } @Override - public XContentBuilder newBuilder(XContentType xContentType, XContentType responseContentType, boolean useFiltering) + public XContentBuilder newBuilder(MediaType xContentType, MediaType responseContentType, boolean useFiltering) throws IOException { return null; } diff --git a/src/test/java/org/opensearch/security/AggregationTests.java b/src/test/java/org/opensearch/security/AggregationTests.java index 728965f82d..ff17e6478e 100644 --- a/src/test/java/org/opensearch/security/AggregationTests.java +++ b/src/test/java/org/opensearch/security/AggregationTests.java @@ -37,7 +37,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.SingleClusterTest; import org.opensearch.security.test.helper.rest.RestHelper; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -53,31 +53,31 @@ public void testBasicAggregations() throws Exception { try (Client tc = getClient()) { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("xyz").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("xyz").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() diff --git a/src/test/java/org/opensearch/security/ConfigTests.java b/src/test/java/org/opensearch/security/ConfigTests.java index c64ca55318..2f295a5ed8 100644 --- a/src/test/java/org/opensearch/security/ConfigTests.java +++ b/src/test/java/org/opensearch/security/ConfigTests.java @@ -29,7 +29,7 @@ import org.opensearch.common.Strings; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.securityconf.Migration; import org.opensearch.security.securityconf.impl.CType; import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration; @@ -63,25 +63,25 @@ public void testMigrate() throws Exception { (SecurityDynamicConfiguration) load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING) ); - System.out.println(Strings.toString(XContentType.JSON, rolesResult.v2(), true, false)); - System.out.println(Strings.toString(XContentType.JSON, rolesResult.v1(), true, false)); + System.out.println(Strings.toString(MediaType.JSON, rolesResult.v2(), true, false)); + System.out.println(Strings.toString(MediaType.JSON, rolesResult.v1(), true, false)); SecurityDynamicConfiguration actionGroupsResult = Migration.migrateActionGroups( (SecurityDynamicConfiguration) load("./legacy/securityconfig_v6/action_groups.yml", CType.ACTIONGROUPS) ); - System.out.println(Strings.toString(XContentType.JSON, actionGroupsResult, true, false)); + System.out.println(Strings.toString(MediaType.JSON, actionGroupsResult, true, false)); SecurityDynamicConfiguration configResult = Migration.migrateConfig( (SecurityDynamicConfiguration) load("./legacy/securityconfig_v6/config.yml", CType.CONFIG) ); - System.out.println(Strings.toString(XContentType.JSON, configResult, true, false)); + System.out.println(Strings.toString(MediaType.JSON, configResult, true, false)); SecurityDynamicConfiguration internalUsersResult = Migration.migrateInternalUsers( (SecurityDynamicConfiguration) load("./legacy/securityconfig_v6/internal_users.yml", CType.INTERNALUSERS) ); - System.out.println(Strings.toString(XContentType.JSON, internalUsersResult, true, false)); + System.out.println(Strings.toString(MediaType.JSON, internalUsersResult, true, false)); SecurityDynamicConfiguration rolemappingsResult = Migration.migrateRoleMappings( (SecurityDynamicConfiguration) load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING) ); - System.out.println(Strings.toString(XContentType.JSON, rolemappingsResult, true, false)); + System.out.println(Strings.toString(MediaType.JSON, rolemappingsResult, true, false)); } @Test @@ -123,7 +123,7 @@ private void check(String file, CType cType) throws Exception { // Assert.assertTrue(dc.getCEntries().size() > 0); String jsonSerialize = DefaultObjectMapper.objectMapper.writeValueAsString(dc); SecurityDynamicConfiguration conf = SecurityDynamicConfiguration.fromJson(jsonSerialize, cType, configVersion, 0, 0); - SecurityDynamicConfiguration.fromJson(Strings.toString(XContentType.JSON, conf), cType, configVersion, 0, 0); + SecurityDynamicConfiguration.fromJson(Strings.toString(MediaType.JSON, conf), cType, configVersion, 0, 0); } diff --git a/src/test/java/org/opensearch/security/HttpIntegrationTests.java b/src/test/java/org/opensearch/security/HttpIntegrationTests.java index be3feafaaa..7a50f663b5 100644 --- a/src/test/java/org/opensearch/security/HttpIntegrationTests.java +++ b/src/test/java/org/opensearch/security/HttpIntegrationTests.java @@ -40,7 +40,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.action.configupdate.ConfigUpdateAction; import org.opensearch.security.action.configupdate.ConfigUpdateRequest; import org.opensearch.security.action.configupdate.ConfigUpdateResponse; @@ -70,32 +70,32 @@ public void testHTTPBasic() throws Exception { try (Client tc = getClient()) { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("v2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("v2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("v3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("v3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -531,7 +531,7 @@ public void testHTTPClientCert() throws Exception { try (Client tc = getClient()) { - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); ConfigUpdateResponse cur = tc.execute( @@ -685,33 +685,33 @@ public void testHTTPBasic2() throws Exception { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -947,14 +947,14 @@ public void test557() throws Exception { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -986,15 +986,15 @@ public void testITT1635() throws Exception { try (Client tc = getClient()) { - tc.index(new IndexRequest("esb-prod-1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("esb-prod-1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("esb-prod-2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest("esb-prod-2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("esb-prod-3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", XContentType.JSON)) + tc.index(new IndexRequest("esb-prod-3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("esb-prod-4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":4}", XContentType.JSON)) + tc.index(new IndexRequest("esb-prod-4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":4}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("esb-prod-5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":5}", XContentType.JSON)) + tc.index(new IndexRequest("esb-prod-5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":5}", MediaType.JSON)) .actionGet(); tc.admin() @@ -1062,37 +1062,37 @@ public void testTenantInfo() throws Exception { try (Client tc = getClient()) { - tc.index(new IndexRequest(".kibana-6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest(".kibana-6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); tc.index( new IndexRequest(".kibana_-1139640511_admin1").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":3}", XContentType.JSON) + .source("{\"content\":3}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest(".kibana_-1386441176_praxisrw").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":3}", XContentType.JSON) + .source("{\"content\":3}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest(".kibana_-634608247_abcdef22").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":3}", XContentType.JSON) + .source("{\"content\":3}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest(".kibana_-12345_123456").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":3}", XContentType.JSON) + .source("{\"content\":3}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest(".kibana2_-12345_123456").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":3}", XContentType.JSON) + .source("{\"content\":3}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest(".kibana_9876_xxx_ccc").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":3}", XContentType.JSON) + .source("{\"content\":3}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest(".kibana_fff_eee").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", XContentType.JSON) + new IndexRequest(".kibana_fff_eee").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("esb-prod-5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":5}", XContentType.JSON)) + tc.index(new IndexRequest("esb-prod-5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":5}", MediaType.JSON)) .actionGet(); tc.admin() @@ -1178,7 +1178,7 @@ public void testAll() throws Exception { final RestHelper rh = nonSslRestHelper(); try (Client tc = getClient()) { - tc.index(new IndexRequest("abcdef").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("abcdef").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); } diff --git a/src/test/java/org/opensearch/security/IndexIntegrationTests.java b/src/test/java/org/opensearch/security/IndexIntegrationTests.java index 6a8703842e..d2b59713c0 100644 --- a/src/test/java/org/opensearch/security/IndexIntegrationTests.java +++ b/src/test/java/org/opensearch/security/IndexIntegrationTests.java @@ -45,7 +45,7 @@ import org.opensearch.cluster.health.ClusterHealthStatus; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.index.query.QueryBuilders; import org.opensearch.indices.InvalidIndexNameException; import org.opensearch.security.support.ConfigConstants; @@ -69,12 +69,12 @@ public void testComposite() throws Exception { final RestHelper rh = nonSslRestHelper(); try (Client tc = getClient()) { - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); } @@ -107,9 +107,9 @@ public void testBulkShards() throws Exception { try (Client tc = getClient()) { // create indices and mapping upfront - tc.index(new IndexRequest("test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", XContentType.JSON)) + tc.index(new IndexRequest("test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("lorem").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", XContentType.JSON)) + tc.index(new IndexRequest("lorem").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", MediaType.JSON)) .actionGet(); } @@ -219,9 +219,9 @@ public void testFilteredAlias() throws Exception { try (Client tc = getClient()) { - tc.index(new IndexRequest("theindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("theindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("otherindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("otherindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() .indices() @@ -275,20 +275,20 @@ public void testIndexTypeEvaluation() throws Exception { try (Client tc = getClient()) { tc.index( - new IndexRequest("foo1").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("foo1").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("foo2").id("2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON) + new IndexRequest("foo2").id("2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("foo").id("3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", XContentType.JSON)) + tc.index(new IndexRequest("foo").id("3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("fooba").id("4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":4}", XContentType.JSON) + new IndexRequest("fooba").id("4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":4}", MediaType.JSON) ).actionGet(); try { tc.index( - new IndexRequest("x#a").id("4a").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":4}", XContentType.JSON) + new IndexRequest("x#a").id("4a").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":4}", MediaType.JSON) ).actionGet(); Assert.fail("Indexname can contain #"); } catch (InvalidIndexNameException e) { @@ -346,16 +346,16 @@ public void testIndices() throws Exception { setup(); try (Client tc = getClient()) { - tc.index(new IndexRequest("nopermindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("nopermindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd", SecurityUtils.EN_Locale); @@ -363,7 +363,7 @@ public void testIndices() throws Exception { String date = sdf.format(new Date()); tc.index( - new IndexRequest("logstash-" + date).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("logstash-" + date).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -530,29 +530,29 @@ public void testAliases() throws Exception { setup(settings); try (Client tc = getClient()) { - tc.index(new IndexRequest("nopermindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("nopermindex").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("logstash-5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("logstash-5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("logstash-del").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("logstash-del").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("logstash-del-ok").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("logstash-del-ok").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); String date = new SimpleDateFormat("YYYY.MM.dd").format(new Date()); tc.index( - new IndexRequest("logstash-" + date).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("logstash-" + date).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -664,7 +664,7 @@ public void testCCSIndexResolve() throws Exception { final RestHelper rh = nonSslRestHelper(); try (Client tc = getClient()) { - tc.index(new IndexRequest(".abc-6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest(".abc-6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); } @@ -685,11 +685,11 @@ public void testCCSIndexResolve2() throws Exception { final RestHelper rh = nonSslRestHelper(); try (Client tc = getClient()) { - tc.index(new IndexRequest(".abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest(".abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("xyz").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest("xyz").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("noperm").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", XContentType.JSON)) + tc.index(new IndexRequest("noperm").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":3}", MediaType.JSON)) .actionGet(); } @@ -756,9 +756,9 @@ public void testIndexResolveIgnoreUnavailable() throws Exception { try (Client tc = getClient()) { // create indices and mapping upfront - tc.index(new IndexRequest("test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", XContentType.JSON)) + tc.index(new IndexRequest("test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("lorem").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", XContentType.JSON)) + tc.index(new IndexRequest("lorem").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", MediaType.JSON)) .actionGet(); } @@ -781,7 +781,7 @@ public void testIndexResolveIndicesAlias() throws Exception { try (Client tc = getClient()) { // create indices and mapping upfront tc.index( - new IndexRequest("foo-index").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", XContentType.JSON) + new IndexRequest("foo-index").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", MediaType.JSON) ).actionGet(); tc.admin() .indices() @@ -813,7 +813,7 @@ public void testIndexResolveMinus() throws Exception { try (Client tc = getClient()) { // create indices and mapping upfront tc.index( - new IndexRequest("foo-abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", XContentType.JSON) + new IndexRequest("foo-abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"field2\":\"init\"}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/IntegrationTests.java b/src/test/java/org/opensearch/security/IntegrationTests.java index 399d226bd9..424d24f452 100644 --- a/src/test/java/org/opensearch/security/IntegrationTests.java +++ b/src/test/java/org/opensearch/security/IntegrationTests.java @@ -44,7 +44,7 @@ import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; import org.opensearch.common.util.concurrent.ThreadContext; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.action.configupdate.ConfigUpdateAction; import org.opensearch.security.action.configupdate.ConfigUpdateRequest; import org.opensearch.security.action.configupdate.ConfigUpdateResponse; @@ -72,7 +72,7 @@ public void testSearchScroll() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -221,10 +221,10 @@ public void testMultiget() throws Exception { try (Client tc = getClient()) { tc.index( - new IndexRequest("mindex1").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("mindex1").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("mindex2").id("2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON) + new IndexRequest("mindex2").id("2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON) ).actionGet(); } @@ -307,7 +307,7 @@ public void testSingle() throws Exception { tc.index( new IndexRequest("shakespeare").id("1") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); ConfigUpdateResponse cur = tc.execute( @@ -366,17 +366,17 @@ public void testRegexExcludes() throws Exception { setup(Settings.EMPTY, new DynamicSecurityConfig(), Settings.EMPTY); try (Client tc = getClient()) { - tc.index(new IndexRequest("indexa").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"indexa\":1}", XContentType.JSON)) + tc.index(new IndexRequest("indexa").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"indexa\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("indexb").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"indexb\":1}", XContentType.JSON)) + tc.index(new IndexRequest("indexb").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"indexb\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("isallowed").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"isallowed\":1}", XContentType.JSON)) + tc.index(new IndexRequest("isallowed").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"isallowed\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("special").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"special\":1}", XContentType.JSON)) + tc.index(new IndexRequest("special").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"special\":1}", MediaType.JSON)) .actionGet(); tc.index( new IndexRequest("alsonotallowed").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"alsonotallowed\":1}", XContentType.JSON) + .source("{\"alsonotallowed\":1}", MediaType.JSON) ).actionGet(); } @@ -410,9 +410,9 @@ public void testMultiRoleSpan() throws Exception { final RestHelper rh = nonSslRestHelper(); try (Client tc = getClient()) { - tc.index(new IndexRequest("mindex_1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("mindex_1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("mindex_2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest("mindex_2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); } @@ -449,13 +449,13 @@ public void testMultiRoleSpan2() throws Exception { final RestHelper rh = nonSslRestHelper(); try (Client tc = getClient()) { - tc.index(new IndexRequest("mindex_1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("mindex_1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("mindex_2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest("mindex_2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("mindex_3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest("mindex_3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("mindex_4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", XContentType.JSON)) + tc.index(new IndexRequest("mindex_4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":2}", MediaType.JSON)) .actionGet(); } @@ -499,7 +499,7 @@ public void testDeleteByQueryDnfof() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) { tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } } @@ -526,7 +526,7 @@ public void testUpdate() throws Exception { try (Client tc = getClient()) { tc.index( - new IndexRequest("indexc").id("0").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("indexc").id("0").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -553,36 +553,36 @@ public void testDnfof() throws Exception { tc.index( new IndexRequest("indexa").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":\"indexa\"}", XContentType.JSON) + .source("{\"content\":\"indexa\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("indexb").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":\"indexb\"}", XContentType.JSON) + .source("{\"content\":\"indexb\"}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -809,36 +809,36 @@ public void testNoDnfof() throws Exception { tc.index( new IndexRequest("indexa").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":\"indexa\"}", XContentType.JSON) + .source("{\"content\":\"indexa\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("indexb").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":\"indexb\"}", XContentType.JSON) + .source("{\"content\":\"indexb\"}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() diff --git a/src/test/java/org/opensearch/security/PitIntegrationTests.java b/src/test/java/org/opensearch/security/PitIntegrationTests.java index 035cc2ce3e..1b6ddad48f 100644 --- a/src/test/java/org/opensearch/security/PitIntegrationTests.java +++ b/src/test/java/org/opensearch/security/PitIntegrationTests.java @@ -22,7 +22,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.SingleClusterTest; import org.opensearch.security.test.helper.rest.RestHelper; @@ -42,7 +42,7 @@ public void testPitExplicitAPIAccess() throws Exception { tc.index( new IndexRequest("pit_2").id("2") .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":2}", XContentType.JSON) + .source("{\"content\":2}", MediaType.JSON) ).actionGet(); } @@ -122,12 +122,12 @@ public void testPitAllAPIAccess() throws Exception { tc.index( new IndexRequest("pit_1").id("1") .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("pit_2").id("2") .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":2}", XContentType.JSON) + .source("{\"content\":2}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/PrivilegesEvaluationTest.java b/src/test/java/org/opensearch/security/PrivilegesEvaluationTest.java index b7af395daa..6c4496517f 100644 --- a/src/test/java/org/opensearch/security/PrivilegesEvaluationTest.java +++ b/src/test/java/org/opensearch/security/PrivilegesEvaluationTest.java @@ -19,7 +19,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.SingleClusterTest; import org.opensearch.security.test.helper.rest.RestHelper; @@ -33,7 +33,7 @@ public void resolveTestHidden() throws Exception { client.index( new IndexRequest("hidden_test_not_hidden").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source(XContentType.JSON, "index", "hidden_test_not_hidden", "b", "y", "date", "1985/01/01") + .source(MediaType.JSON, "index", "hidden_test_not_hidden", "b", "y", "date", "1985/01/01") ).actionGet(); client.admin() diff --git a/src/test/java/org/opensearch/security/ResolveAPITests.java b/src/test/java/org/opensearch/security/ResolveAPITests.java index 088702acd9..1cc0a4015f 100644 --- a/src/test/java/org/opensearch/security/ResolveAPITests.java +++ b/src/test/java/org/opensearch/security/ResolveAPITests.java @@ -27,7 +27,7 @@ import org.opensearch.action.support.WriteRequest; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.DynamicSecurityConfig; import org.opensearch.security.test.SingleClusterTest; import org.opensearch.security.test.helper.rest.RestHelper; @@ -175,43 +175,43 @@ private void setupIndices() { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); tc.index( new IndexRequest("vulcangov").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("starfleet").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("starfleet_academy").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("starfleet_library").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("klingonempire").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("public").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("spock").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("kirk").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("kirk").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("role01_role02").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source("{\"content\":1}", XContentType.JSON) + .source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("xyz").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("xyz").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() diff --git a/src/test/java/org/opensearch/security/SnapshotRestoreTests.java b/src/test/java/org/opensearch/security/SnapshotRestoreTests.java index 1c884a8e5d..dc3a55b3d8 100644 --- a/src/test/java/org/opensearch/security/SnapshotRestoreTests.java +++ b/src/test/java/org/opensearch/security/SnapshotRestoreTests.java @@ -41,7 +41,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.action.configupdate.ConfigUpdateAction; import org.opensearch.security.action.configupdate.ConfigUpdateRequest; import org.opensearch.security.action.configupdate.ConfigUpdateResponse; @@ -69,7 +69,7 @@ public void testSnapshotEnableSecurityIndexRestore() throws Exception { setup(settings, currentClusterConfig); try (Client tc = getClient()) { - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() @@ -269,7 +269,7 @@ public void testSnapshot() throws Exception { setup(settings, currentClusterConfig); try (Client tc = getClient()) { - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() @@ -443,7 +443,7 @@ public void testSnapshotCheckWritePrivileges() throws Exception { setup(settings, currentClusterConfig); try (Client tc = getClient()) { - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() @@ -679,17 +679,17 @@ public void testSnapshotRestore() throws Exception { ); try (Client tc = getClient()) { - tc.index(new IndexRequest("testsnap1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() @@ -790,7 +790,7 @@ public void testSnapshotRestoreSpecialIndicesPatterns() throws Exception { tc.index( new IndexRequest(index).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .id("document1") - .source("{ \"foo\": \"bar\" }", XContentType.JSON) + .source("{ \"foo\": \"bar\" }", MediaType.JSON) ).actionGet(); } } @@ -864,17 +864,17 @@ public void testNoSnapshotRestore() throws Exception { ); try (Client tc = getClient()) { - tc.index(new IndexRequest("testsnap1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap3").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap4").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap5").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("testsnap6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("testsnap6").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.admin() diff --git a/src/test/java/org/opensearch/security/TracingTests.java b/src/test/java/org/opensearch/security/TracingTests.java index 2fefd33155..721f72cdb1 100644 --- a/src/test/java/org/opensearch/security/TracingTests.java +++ b/src/test/java/org/opensearch/security/TracingTests.java @@ -39,7 +39,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.support.ConfigConstants; import org.opensearch.security.test.DynamicSecurityConfig; import org.opensearch.security.test.SingleClusterTest; @@ -58,19 +58,19 @@ public void testAdvancedMapping() throws Exception { try (Client tc = getClient()) { tc.admin() .indices() - .create(new CreateIndexRequest("myindex1").mapping(FileHelper.loadFile("mapping1.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex1").mapping(FileHelper.loadFile("mapping1.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex2").mapping(FileHelper.loadFile("mapping2.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex2").mapping(FileHelper.loadFile("mapping2.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex3").mapping(FileHelper.loadFile("mapping3.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex3").mapping(FileHelper.loadFile("mapping3.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex4").mapping(FileHelper.loadFile("mapping4.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex4").mapping(FileHelper.loadFile("mapping4.json"), MediaType.JSON)) .actionGet(); } @@ -198,12 +198,12 @@ public void testHTTPTraceNoSource() throws Exception { tc.index( new IndexRequest("a").id(i + "") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":" + i + "}", XContentType.JSON) + .source("{\"content\":" + i + "}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("c").id(i + "") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":" + i + "}", XContentType.JSON) + .source("{\"content\":" + i + "}", MediaType.JSON) ).actionGet(); } } @@ -339,28 +339,28 @@ public void testHTTPSingle() throws Exception { try (Client tc = getClient()) { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -432,7 +432,7 @@ public void testSearchScroll() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -472,12 +472,12 @@ public void testHTTPTrace() throws Exception { tc.index( new IndexRequest("a").id(i + "") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":" + i + "}", XContentType.JSON) + .source("{\"content\":" + i + "}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("c").id(i + "") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":" + i + "}", XContentType.JSON) + .source("{\"content\":" + i + "}", MediaType.JSON) ).actionGet(); } } diff --git a/src/test/java/org/opensearch/security/auditlog/impl/AuditMessageTest.java b/src/test/java/org/opensearch/security/auditlog/impl/AuditMessageTest.java index f53872bb3a..34722440a6 100644 --- a/src/test/java/org/opensearch/security/auditlog/impl/AuditMessageTest.java +++ b/src/test/java/org/opensearch/security/auditlog/impl/AuditMessageTest.java @@ -26,7 +26,7 @@ import org.opensearch.cluster.service.ClusterService; import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.collect.Tuple; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.auditlog.AuditLog; import org.opensearch.security.securityconf.impl.CType; @@ -138,7 +138,7 @@ public void testBCryptHashIsRedacted() { // test tuple redaction final ByteBuffer[] byteBuffers = new ByteBuffer[] { ByteBuffer.wrap(("Hash in tuple is " + hash1).getBytes()) }; BytesReference ref = BytesReference.fromByteBuffers(byteBuffers); - message.addSecurityConfigTupleToRequestBody(new Tuple<>(XContentType.JSON, ref), internalUsersDocId); + message.addSecurityConfigTupleToRequestBody(new Tuple<>(MediaType.JSON, ref), internalUsersDocId); assertEquals("Hash in tuple is __HASH__", message.getAsMap().get(AuditMessage.REQUEST_BODY)); } } diff --git a/src/test/java/org/opensearch/security/auditlog/impl/TracingTests.java b/src/test/java/org/opensearch/security/auditlog/impl/TracingTests.java index db45d6c130..83328ff51c 100644 --- a/src/test/java/org/opensearch/security/auditlog/impl/TracingTests.java +++ b/src/test/java/org/opensearch/security/auditlog/impl/TracingTests.java @@ -22,7 +22,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.auditlog.AuditTestUtils; import org.opensearch.security.support.ConfigConstants; import org.opensearch.security.test.DynamicSecurityConfig; @@ -63,12 +63,12 @@ public void testHTTPTrace() throws Exception { tc.index( new IndexRequest("a").id(i + "") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":" + i + "}", XContentType.JSON) + .source("{\"content\":" + i + "}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("c").id(i + "") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":" + i + "}", XContentType.JSON) + .source("{\"content\":" + i + "}", MediaType.JSON) ).actionGet(); } } @@ -234,28 +234,28 @@ public void testHTTPSingle() throws Exception { try (Client tc = getClient()) { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -327,7 +327,7 @@ public void testSearchScroll() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -375,19 +375,19 @@ public void testAdvancedMapping() throws Exception { try (Client tc = getClient()) { tc.admin() .indices() - .create(new CreateIndexRequest("myindex1").mapping(FileHelper.loadFile("mapping1.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex1").mapping(FileHelper.loadFile("mapping1.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex2").mapping(FileHelper.loadFile("mapping2.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex2").mapping(FileHelper.loadFile("mapping2.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex3").mapping(FileHelper.loadFile("mapping3.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex3").mapping(FileHelper.loadFile("mapping3.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex4").mapping(FileHelper.loadFile("mapping4.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex4").mapping(FileHelper.loadFile("mapping4.json"), MediaType.JSON)) .actionGet(); } @@ -446,11 +446,11 @@ public void testImmutableIndex() throws Exception { try (Client tc = getClient()) { tc.admin() .indices() - .create(new CreateIndexRequest("myindex1").mapping(FileHelper.loadFile("mapping1.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex1").mapping(FileHelper.loadFile("mapping1.json"), MediaType.JSON)) .actionGet(); tc.admin() .indices() - .create(new CreateIndexRequest("myindex2").mapping(FileHelper.loadFile("mapping1.json"), XContentType.JSON)) + .create(new CreateIndexRequest("myindex2").mapping(FileHelper.loadFile("mapping1.json"), MediaType.JSON)) .actionGet(); } diff --git a/src/test/java/org/opensearch/security/auditlog/integration/BasicAuditlogTest.java b/src/test/java/org/opensearch/security/auditlog/integration/BasicAuditlogTest.java index 2532d7bb17..ecb99c8c86 100644 --- a/src/test/java/org/opensearch/security/auditlog/integration/BasicAuditlogTest.java +++ b/src/test/java/org/opensearch/security/auditlog/integration/BasicAuditlogTest.java @@ -28,7 +28,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.auditlog.AbstractAuditlogiUnitTest; import org.opensearch.security.auditlog.AuditLog.Origin; import org.opensearch.security.auditlog.AuditTestUtils; @@ -564,28 +564,28 @@ public void testAliases() throws Exception { try (Client tc = getClient()) { tc.admin().indices().create(new CreateIndexRequest("copysf")).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -637,7 +637,7 @@ public void testScroll() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } @@ -700,7 +700,7 @@ public void testAliasResolution() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() .indices() @@ -797,7 +797,7 @@ public void testDeleteByQuery() throws Exception { try (Client tc = getClient()) { for (int i = 0; i < 3; i++) tc.index( - new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/ccstest/CrossClusterSearchTests.java b/src/test/java/org/opensearch/security/ccstest/CrossClusterSearchTests.java index fad6c77a1a..23151ef413 100644 --- a/src/test/java/org/opensearch/security/ccstest/CrossClusterSearchTests.java +++ b/src/test/java/org/opensearch/security/ccstest/CrossClusterSearchTests.java @@ -43,7 +43,7 @@ import org.opensearch.cluster.health.ClusterHealthStatus; import org.opensearch.common.collect.Tuple; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.node.Node; import org.opensearch.node.PluginAwareNode; import org.opensearch.security.OpenSearchSecurityPlugin; @@ -169,12 +169,12 @@ public void testCcs() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twutter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -188,12 +188,12 @@ public void testCcs() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twutter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -258,12 +258,12 @@ public void testCcsNonadmin() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twutter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.admin() .indices() @@ -282,12 +282,12 @@ public void testCcsNonadmin() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twutter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.admin() .indices() @@ -540,12 +540,12 @@ public void testCcsNonadminDnfof() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twutter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.admin() .indices() @@ -564,12 +564,12 @@ public void testCcsNonadminDnfof() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twutter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.admin() .indices() @@ -839,7 +839,7 @@ public void testCcsEmptyCoord() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -879,12 +879,12 @@ public void testCcsDashboardsAggregations() throws Exception { tc.index( new IndexRequest("coordinating").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -892,7 +892,7 @@ public void testCcsDashboardsAggregations() throws Exception { tc.index( new IndexRequest("remote").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1005,17 +1005,17 @@ public void testCcsDashboardsAggregationsNonAdminDnfof() throws Exception { tc.index( new IndexRequest("coordinating").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1023,13 +1023,13 @@ public void testCcsDashboardsAggregationsNonAdminDnfof() throws Exception { tc.index( new IndexRequest("remote").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("analytics").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1147,12 +1147,12 @@ public void testCcsAggregations() throws Exception { tc.index( new IndexRequest("coordinating").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1160,7 +1160,7 @@ public void testCcsAggregations() throws Exception { tc.index( new IndexRequest("remote").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1262,17 +1262,17 @@ public void testCcsAggregationsDnfof() throws Exception { tc.index( new IndexRequest("coordinating").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("abc").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1280,13 +1280,13 @@ public void testCcsAggregationsDnfof() throws Exception { tc.index( new IndexRequest("remote").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("analytics").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1393,7 +1393,7 @@ private void populateBaseData(ClusterTransportClientSettings cluster1, ClusterTr tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } @@ -1401,7 +1401,7 @@ private void populateBaseData(ClusterTransportClientSettings cluster1, ClusterTr tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } } @@ -1502,7 +1502,7 @@ public void testCcsWithRoleInjection() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl2Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/ccstest/RemoteReindexTests.java b/src/test/java/org/opensearch/security/ccstest/RemoteReindexTests.java index 3c49548cf3..4e39a42012 100644 --- a/src/test/java/org/opensearch/security/ccstest/RemoteReindexTests.java +++ b/src/test/java/org/opensearch/security/ccstest/RemoteReindexTests.java @@ -36,7 +36,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.AbstractSecurityUnitTest; import org.opensearch.security.test.helper.cluster.ClusterConfiguration; import org.opensearch.security.test.helper.cluster.ClusterHelper; @@ -104,7 +104,7 @@ public void testNonSSLReindex() throws Exception { tc.index( new IndexRequest("twitter").setRefreshPolicy(RefreshPolicy.IMMEDIATE) .id("0") - .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", XContentType.JSON) + .source("{\"cluster\": \"" + cl1Info.clustername + "\"}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/AbstractDlsFlsTest.java b/src/test/java/org/opensearch/security/dlic/dlsfls/AbstractDlsFlsTest.java index dfe96bb55d..d9a76996f5 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/AbstractDlsFlsTest.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/AbstractDlsFlsTest.java @@ -24,7 +24,7 @@ import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.security.support.ConfigConstants; @@ -68,14 +68,14 @@ protected final void setup(Settings override, DynamicSecurityConfig dynamicSecur protected SearchResponse executeSearch(String indexName, String user, String password) throws Exception { HttpResponse response = rh.executeGetRequest("/" + indexName + "/_search?from=0&size=50&pretty", encodeBasicHeader(user, password)); Assert.assertEquals(200, response.getStatusCode()); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); return SearchResponse.fromXContent(xcp); } protected GetResponse executeGet(String indexName, String id, String user, String password) throws Exception { HttpResponse response = rh.executeGetRequest("/" + indexName + "/_doc/" + id, encodeBasicHeader(user, password)); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); return GetResponse.fromXContent(xcp); } @@ -90,7 +90,7 @@ protected MultiSearchResponse executeMSearchMatchAll(String user, String passwor HttpResponse response = rh.executePostRequest("/_msearch?pretty", body.toString(), encodeBasicHeader(user, password)); Assert.assertEquals(200, response.getStatusCode()); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); return MultiSearchResponse.fromXContext(xcp); } @@ -105,7 +105,7 @@ protected MultiGetResponse executeMGet(String user, String password, Map", "cust" + i).replace("", "" + i).replace("", "1970-01-02"); - tc.index(new IndexRequest("deals").id("0" + i).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(moddoc, XContentType.JSON)) + tc.index(new IndexRequest("deals").id("0" + i).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(moddoc, MediaType.JSON)) .actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFieldsWcTest.java b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFieldsWcTest.java index f6cfd036fd..1efe6d65ee 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFieldsWcTest.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFieldsWcTest.java @@ -21,7 +21,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.helper.file.FileHelper; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -39,7 +39,7 @@ protected void populateData(Client tc) { for (int i = 0; i < 10; i++) { final String moddoc = doc.replace("", "cust" + i).replace("", "" + i).replace("", "1970-01-02"); - tc.index(new IndexRequest("deals").id("0" + i).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(moddoc, XContentType.JSON)) + tc.index(new IndexRequest("deals").id("0" + i).setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(moddoc, MediaType.JSON)) .actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFlatTests.java b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFlatTests.java index e4b3063138..0e8755ce9f 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFlatTests.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsFlatTests.java @@ -19,7 +19,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.Strings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.security.test.DynamicSecurityConfig; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -69,7 +69,7 @@ protected void populateData(final Client tc) { final Consumer createIndexWithMapping = (indexName) -> { final CreateIndexRequest createIndex = new CreateIndexRequest(indexName); - createIndex.settings(mappings, XContentType.JSON); + createIndex.settings(mappings, MediaType.JSON); tc.admin().indices().create(createIndex); }; @@ -85,7 +85,7 @@ protected void populateData(final Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"phone-all\": {\"areaCode\": 1001, \"localNumber\": 1091 },\"phone-some\":{\"areaCode\": 1002, \"localNumber\": 1092 },\"phone-one\":{\"areaCode\": 1003, \"localNumber\": 1093 }}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); createIndexWithMapping.accept("green-page"); @@ -94,7 +94,7 @@ protected void populateData(final Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"phone-all\": {\"areaCode\": 2001, \"localNumber\": 2091 },\"phone-some\":{\"areaCode\": 2002, \"localNumber\": 2092 },\"phone-one\":{\"areaCode\": 2003, \"localNumber\": 2093 }}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); createIndexWithMapping.accept("blue-book"); @@ -103,12 +103,12 @@ protected void populateData(final Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"phone-all\": {\"areaCode\": 3001, \"localNumber\": 3091 },\"phone-some\":{\"areaCode\": 3002, \"localNumber\": 3092 },\"phone-one\":{\"areaCode\": 3003, \"localNumber\": 3093 }}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); // Seperate index used to test aliasing - tc.index(new IndexRequest(".hidden").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{}", XContentType.JSON)).actionGet(); + tc.index(new IndexRequest(".hidden").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{}", MediaType.JSON)).actionGet(); } private Header asPhoneOneUser = encodeBasicHeader("user_aaa", "password"); diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsIndexingTests.java b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsIndexingTests.java index 2d7ed0efcf..fed0b47ee1 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsIndexingTests.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsIndexingTests.java @@ -18,7 +18,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.DynamicSecurityConfig; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -35,21 +35,21 @@ protected void populateData(final Client tc) { tc.index( new IndexRequest("yellow-pages").id("1") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"phone-all\":1001,\"phone-some\":1002,\"phone-one\":1003}", XContentType.JSON) + .source("{\"phone-all\":1001,\"phone-some\":1002,\"phone-one\":1003}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("green-pages").id("2") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"phone-all\":2001,\"phone-some\":2002,\"phone-one\":2003}", XContentType.JSON) + .source("{\"phone-all\":2001,\"phone-some\":2002,\"phone-one\":2003}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("blue-book").id("3") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"phone-all\":3001,\"phone-some\":3002,\"phone-one\":3003}", XContentType.JSON) + .source("{\"phone-all\":3001,\"phone-some\":3002,\"phone-one\":3003}", MediaType.JSON) ).actionGet(); // Seperate index used to test aliasing - tc.index(new IndexRequest(".hidden").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{}", XContentType.JSON)).actionGet(); + tc.index(new IndexRequest(".hidden").id("1").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{}", MediaType.JSON)).actionGet(); } private Header asPhoneOneUser = encodeBasicHeader("user_aaa", "password"); diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsKeywordTests.java b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsKeywordTests.java index 1c51ec99b7..68af5b8329 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsKeywordTests.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsKeywordTests.java @@ -20,7 +20,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.DynamicSecurityConfig; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -37,7 +37,7 @@ protected void populateData(Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"year\": 2013, \"title\": \"Rush\", \"actors\": [\"Daniel Br\u00FChl\", \"Chris Hemsworth\", \"Olivia Wilde\"]}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsTest.java b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsTest.java index 180256efd9..c159c06f3e 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/FlsTest.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/FlsTest.java @@ -18,7 +18,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; public class FlsTest extends AbstractDlsFlsTest { @@ -30,13 +30,13 @@ protected void populateData(Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"customer\": {\"name\":\"cust1\"}, \"zip\": \"12345\",\"secret\": \"tellnoone\",\"amount\": 10}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); tc.index( new IndexRequest("deals").id("1") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"customer\": {\"name\":\"cust2\", \"ctype\":\"industry\"}, \"amount\": 1500}", XContentType.JSON) + .source("{\"customer\": {\"name\":\"cust2\", \"ctype\":\"industry\"}, \"amount\": 1500}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/IndexPatternTest.java b/src/test/java/org/opensearch/security/dlic/dlsfls/IndexPatternTest.java index 9b075e0600..6851d2d40d 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/IndexPatternTest.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/IndexPatternTest.java @@ -18,7 +18,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; public class IndexPatternTest extends AbstractDlsFlsTest { @@ -27,19 +27,19 @@ protected void populateData(Client tc) { tc.index( new IndexRequest("logstash-2016").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"message\":\"mymsg1a\", \"ipaddr\": \"10.0.0.0\",\"msgid\": \"12\"}", XContentType.JSON) + .source("{\"message\":\"mymsg1a\", \"ipaddr\": \"10.0.0.0\",\"msgid\": \"12\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("logstash-2016").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"message\":\"mymsg1b\", \"ipaddr\": \"10.0.0.1\",\"msgid\": \"14\"}", XContentType.JSON) + .source("{\"message\":\"mymsg1b\", \"ipaddr\": \"10.0.0.1\",\"msgid\": \"14\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("logstash-2018").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"message\":\"mymsg1c\", \"ipaddr\": \"10.0.0.2\",\"msgid\": \"12\"}", XContentType.JSON) + .source("{\"message\":\"mymsg1c\", \"ipaddr\": \"10.0.0.2\",\"msgid\": \"12\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("logstash-2018").setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"message\":\"mymsg1d\", \"ipaddr\": \"10.0.0.3\",\"msgid\": \"14\"}", XContentType.JSON) + .source("{\"message\":\"mymsg1d\", \"ipaddr\": \"10.0.0.3\",\"msgid\": \"14\"}", MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/dlsfls/MFlsTest.java b/src/test/java/org/opensearch/security/dlic/dlsfls/MFlsTest.java index 81a2c50fc6..63e621034e 100644 --- a/src/test/java/org/opensearch/security/dlic/dlsfls/MFlsTest.java +++ b/src/test/java/org/opensearch/security/dlic/dlsfls/MFlsTest.java @@ -18,7 +18,7 @@ import org.opensearch.action.index.IndexRequest; import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; public class MFlsTest extends AbstractDlsFlsTest { @@ -30,7 +30,7 @@ protected void populateData(Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"customer\": {\"name\":\"cust1\"}, \"zip\": \"12345\",\"secret\": \"tellnoone\",\"amount\": 10}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); tc.index( @@ -38,7 +38,7 @@ protected void populateData(Client tc) { .setRefreshPolicy(RefreshPolicy.IMMEDIATE) .source( "{\"finfield2\":\"fff\",\"xcustomer\": {\"name\":\"cust2\", \"ctype\":\"industry\"}, \"famount\": 1500}", - XContentType.JSON + MediaType.JSON ) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/AccountApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/AccountApiTest.java index c07b0f1333..1cbf00b06d 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/AccountApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/AccountApiTest.java @@ -17,7 +17,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.securityconf.impl.CType; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -63,7 +63,7 @@ public void testGetAccount() throws Exception { // test - valid request response = rh.executeGetRequest(ENDPOINT, encodeBasicHeader(testUser, testPass)); - Settings body = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings body = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals(testUser, body.get("user_name")); assertFalse(body.getAsBoolean("is_reserved", true)); @@ -154,7 +154,7 @@ public void testPutAccount() throws Exception { // test - reserved user - sarek response = rh.executeGetRequest(ENDPOINT, encodeBasicHeader("sarek", "sarek")); - Settings body = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings body = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); // check reserved user exists assertTrue(body.getAsBoolean("is_reserved", false)); payload = "{\"password\":\"" + testPass + "\", \"current_password\":\"" + "sarek" + "\"}"; @@ -163,7 +163,7 @@ public void testPutAccount() throws Exception { // test - hidden user - hide response = rh.executeGetRequest(ENDPOINT, encodeBasicHeader("hide", "hide")); - body = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + body = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); // check hidden user exists assertTrue(body.getAsBoolean("is_hidden", false)); payload = "{\"password\":\"" + testPass + "\", \"current_password\":\"" + "hide" + "\"}"; @@ -174,7 +174,7 @@ public void testPutAccount() throws Exception { rh.keystore = "restapi/kirk-keystore.jks"; rh.sendAdminCertificate = true; response = rh.executeGetRequest(ENDPOINT, encodeBasicHeader("admin", "admin")); - body = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + body = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); assertEquals("CN=kirk,OU=client,O=client,L=Test,C=DE", body.get("user_name")); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); // check admin user exists System.out.println(response.getBody()); @@ -218,7 +218,7 @@ public void testPutAccountRetainsAccountInformation() throws Exception { response = rh.executeGetRequest(internalUserEndpoint); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); Settings responseBody = Settings.builder() - .loadFromSource(response.getBody(), XContentType.JSON) + .loadFromSource(response.getBody(), MediaType.JSON) .build() .getAsSettings(testUsername); assertTrue(responseBody.getAsList("backend_roles").contains("test-backend-role-1")); diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/ActionGroupsApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/ActionGroupsApiTest.java index c87698155f..0ac01f1ffc 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/ActionGroupsApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/ActionGroupsApiTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator; import org.opensearch.security.test.helper.file.FileHelper; @@ -72,7 +72,7 @@ void verifyGetForSuperAdmin(final Header[] header) throws Exception { // GET_UT, actiongroup exists HttpResponse response = rh.executeGetRequest(ENDPOINT + "/CRUD_UT", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); List permissions = settings.getAsList("CRUD_UT.allowed_actions"); Assert.assertNotNull(permissions); Assert.assertEquals(2, permissions.size()); @@ -146,12 +146,12 @@ void verifyPutForSuperAdmin(final Header[] header, final boolean userAdminCert) rh.sendAdminCertificate = userAdminCert; HttpResponse response = rh.executePutRequest(ENDPOINT + "/SOMEGROUP", "", header); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.PAYLOAD_MANDATORY.getMessage(), settings.get("reason")); // put new configuration with invalid payload, must fail response = rh.executePutRequest(ENDPOINT + "/SOMEGROUP", FileHelper.loadFile("restapi/actiongroup_not_parseable.json"), header); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.BODY_NOT_PARSEABLE.getMessage(), settings.get("reason")); @@ -302,7 +302,7 @@ void verifyPatchForSuperAdmin(final Header[] header, final boolean userAdminCert Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); response = rh.executeGetRequest(ENDPOINT + "/CRUD_UT", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); List permissions = settings.getAsList("CRUD_UT.allowed_actions"); Assert.assertNotNull(permissions); Assert.assertEquals(3, permissions.size()); @@ -373,7 +373,7 @@ void verifyPatchForSuperAdmin(final Header[] header, final boolean userAdminCert Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); response = rh.executeGetRequest(ENDPOINT + "/BULKNEW1", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); permissions = settings.getAsList("BULKNEW1.allowed_actions"); Assert.assertNotNull(permissions); Assert.assertEquals(2, permissions.size()); @@ -382,7 +382,7 @@ void verifyPatchForSuperAdmin(final Header[] header, final boolean userAdminCert response = rh.executeGetRequest(ENDPOINT + "/BULKNEW2", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); permissions = settings.getAsList("BULKNEW2.allowed_actions"); Assert.assertNotNull(permissions); Assert.assertEquals(1, permissions.size()); @@ -397,7 +397,7 @@ void verifyPatchForSuperAdmin(final Header[] header, final boolean userAdminCert // assert other resource is still there response = rh.executeGetRequest(ENDPOINT + "/BULKNEW2", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); permissions = settings.getAsList("BULKNEW2.allowed_actions"); Assert.assertNotNull(permissions); Assert.assertEquals(1, permissions.size()); @@ -551,7 +551,7 @@ public void checkNullElementsInArray() throws Exception { String body = FileHelper.loadFile("restapi/actiongroup_null_array_element.json"); HttpResponse response = rh.executePutRequest(ENDPOINT + "/CRUD_UT", body, new Header[0]); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/FlushCacheApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/FlushCacheApiTest.java index 120596f046..aafc609172 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/FlushCacheApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/FlushCacheApiTest.java @@ -17,7 +17,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; import static org.opensearch.security.OpenSearchSecurityPlugin.PLUGINS_PREFIX; @@ -45,25 +45,25 @@ public void testFlushCache() throws Exception { // GET HttpResponse response = rh.executeGetRequest(ENDPOINT); Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("message"), "Method GET not supported for this action."); // PUT response = rh.executePutRequest(ENDPOINT, "{}", new Header[0]); Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("message"), "Method PUT not supported for this action."); // POST response = rh.executePostRequest(ENDPOINT, "{}", new Header[0]); Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("message"), "Method POST not supported for this action."); // DELETE response = rh.executeDeleteRequest(ENDPOINT, new Header[0]); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("message"), "Cache flushed successfully."); } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/GetConfigurationApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/GetConfigurationApiTest.java index 09c4a762b5..c42352289c 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/GetConfigurationApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/GetConfigurationApiTest.java @@ -17,7 +17,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.test.helper.rest.RestHelper.HttpResponse; @@ -48,14 +48,14 @@ public void testGetConfiguration() throws Exception { // config response = rh.executeGetRequest(ENDPOINT + "/securityconfig"); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.getAsBoolean("config.dynamic.authc.authentication_domain_basic_internal.http_enabled", false), true); Assert.assertNull(settings.get("_opendistro_security_meta.type")); // internalusers response = rh.executeGetRequest(ENDPOINT + "/internalusers"); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.get("admin.hash")); Assert.assertEquals("", settings.get("other.hash")); Assert.assertNull(settings.get("_opendistro_security_meta.type")); @@ -70,14 +70,14 @@ public void testGetConfiguration() throws Exception { // roles response = rh.executeGetRequest(ENDPOINT + "/rolesmapping"); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.getAsList("opendistro_security_role_starfleet.backend_roles").get(0), "starfleet"); Assert.assertNull(settings.get("_opendistro_security_meta.type")); // action groups response = rh.executeGetRequest(ENDPOINT + "/actiongroups"); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.getAsList("ALL.allowed_actions").get(0), "indices:*"); Assert.assertTrue(settings.hasValue("INTERNAL.allowed_actions")); Assert.assertNull(settings.get("_opendistro_security_meta.type")); diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/NodesDnApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/NodesDnApiTest.java index a549ad4dd9..59c70e8e63 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/NodesDnApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/NodesDnApiTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.auditlog.impl.AuditCategory; import org.opensearch.security.auditlog.impl.AuditMessage; import org.opensearch.security.auditlog.integration.TestAuditlogImpl; @@ -122,7 +122,7 @@ private void checkNullElementsInArray(final Header headers) throws Exception { String body = FileHelper.loadFile("restapi/nodesdn_null_array_element.json"); HttpResponse response = rh.executePutRequest(ENDPOINT + "/nodesdn/cluster1", body, headers); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/RoleBasedAccessTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/RoleBasedAccessTest.java index 9d8badba6f..db6529e745 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/RoleBasedAccessTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/RoleBasedAccessTest.java @@ -16,7 +16,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.support.SecurityJsonNode; import org.opensearch.security.test.helper.file.FileHelper; @@ -55,20 +55,20 @@ public void testActionGroupsApi() throws Exception { // legacy user API, accessible for worf, single user HttpResponse response = rh.executeGetRequest(ENDPOINT + "/internalusers/admin", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertTrue(settings.get("admin.hash") != null); Assert.assertEquals("", settings.get("admin.hash")); // new user API, accessible for worf, single user response = rh.executeGetRequest(ENDPOINT + "/internalusers/admin", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertTrue(settings.get("admin.hash") != null); // legacy user API, accessible for worf, get complete config response = rh.executeGetRequest(ENDPOINT + "/internalusers/", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.get("admin.hash")); Assert.assertEquals("", settings.get("sarek.hash")); Assert.assertEquals("", settings.get("worf.hash")); @@ -76,7 +76,7 @@ public void testActionGroupsApi() throws Exception { // new user API, accessible for worf response = rh.executeGetRequest(ENDPOINT + "/internalusers/", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.get("admin.hash")); Assert.assertEquals("", settings.get("sarek.hash")); Assert.assertEquals("", settings.get("worf.hash")); @@ -84,7 +84,7 @@ public void testActionGroupsApi() throws Exception { // legacy user API, accessible for worf, get complete config, no trailing slash response = rh.executeGetRequest(ENDPOINT + "/internalusers", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.get("admin.hash")); Assert.assertEquals("", settings.get("sarek.hash")); Assert.assertEquals("", settings.get("worf.hash")); @@ -92,7 +92,7 @@ public void testActionGroupsApi() throws Exception { // new user API, accessible for worf, get complete config, no trailing slash response = rh.executeGetRequest(ENDPOINT + "/internalusers", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.get("admin.hash")); Assert.assertEquals("", settings.get("sarek.hash")); Assert.assertEquals("", settings.get("worf.hash")); @@ -100,14 +100,14 @@ public void testActionGroupsApi() throws Exception { // roles API, GET accessible for worf response = rh.executeGetRequest(ENDPOINT + "/rolesmapping", encodeBasicHeader("worf", "worf")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.getAsList("opendistro_security_all_access.users").get(0), "nagilum"); Assert.assertEquals("", settings.getAsList("opendistro_security_role_starfleet_library.backend_roles").get(0), "starfleet*"); Assert.assertEquals("", settings.getAsList("opendistro_security_zdummy_all.users").get(0), "bug108"); // Deprecated get configuration API, acessible for sarek // response = rh.executeGetRequest("_opendistro/_security/api/configuration/internalusers", encodeBasicHeader("sarek", "sarek")); - // settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + // settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); // Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); // Assert.assertEquals("", settings.get("admin.hash")); // Assert.assertEquals("", settings.get("sarek.hash")); @@ -115,7 +115,7 @@ public void testActionGroupsApi() throws Exception { // Deprecated get configuration API, acessible for sarek // response = rh.executeGetRequest("_opendistro/_security/api/configuration/actiongroups", encodeBasicHeader("sarek", "sarek")); - // settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + // settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); // Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); // Assert.assertEquals("", settings.getAsList("ALL").get(0), "indices:*"); // Assert.assertEquals("", settings.getAsList("OPENDISTRO_SECURITY_CLUSTER_MONITOR").get(0), "cluster:monitor/*"); @@ -220,7 +220,7 @@ public void testActionGroupsApi() throws Exception { encodeBasicHeader("worf", "worf") ); Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); // starfleet role present again response = rh.executeGetRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet_captains", encodeBasicHeader("worf", "worf")); @@ -238,7 +238,7 @@ public void testActionGroupsApi() throws Exception { // admin response = rh.executeGetRequest(ENDPOINT + "/internalusers/admin", encodeBasicHeader("la", "lu")); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertTrue(settings.get("admin.hash") != null); Assert.assertEquals("", settings.get("admin.hash")); diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java index bf703fea35..96415e1251 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/RolesApiTest.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator; import org.opensearch.security.support.SecurityJsonNode; @@ -885,37 +885,37 @@ public void checkNullElementsInArray() throws Exception { String body = FileHelper.loadFile("restapi/roles_null_array_element_cluster_permissions.json"); HttpResponse response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/roles_null_array_element_index_permissions.json"); response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/roles_null_array_element_tenant_permissions.json"); response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/roles_null_array_element_index_patterns.json"); response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/roles_null_array_element_masked_fields.json"); response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/roles_null_array_element_allowed_actions.json"); response = rh.executePutRequest(ENDPOINT + "/roles/opendistro_security_role_starfleet", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java index 42fb111281..4e742771e4 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/RolesMappingApiTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator; import org.opensearch.security.test.helper.file.FileHelper; @@ -172,7 +172,7 @@ void verifyGetForSuperAdmin(final Header[] header) throws Exception { response = rh.executeGetRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); Assert.assertTrue(response.getContentType(), response.isJsonContentType()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("starfleet", settings.getAsList("opendistro_security_role_starfleet.backend_roles").get(0)); Assert.assertEquals("captains", settings.getAsList("opendistro_security_role_starfleet.backend_roles").get(1)); Assert.assertEquals("*.starfleetintranet.com", settings.getAsList("opendistro_security_role_starfleet.hosts").get(0)); @@ -238,7 +238,7 @@ void verifyPutForSuperAdmin(final Header[] header) throws Exception { // put with empty mapping, must fail HttpResponse response = rh.executePutRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet_captains", "", header); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.PAYLOAD_MANDATORY.getMessage(), settings.get("reason")); // put new configuration with invalid payload, must fail @@ -247,7 +247,7 @@ void verifyPutForSuperAdmin(final Header[] header) throws Exception { FileHelper.loadFile("restapi/rolesmapping_not_parseable.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.BODY_NOT_PARSEABLE.getMessage(), settings.get("reason")); @@ -257,7 +257,7 @@ void verifyPutForSuperAdmin(final Header[] header) throws Exception { FileHelper.loadFile("restapi/rolesmapping_invalid_keys.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.INVALID_CONFIGURATION.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get(AbstractConfigurationValidator.INVALID_KEYS_KEY + ".keys").contains("theusers")); @@ -270,7 +270,7 @@ void verifyPutForSuperAdmin(final Header[] header) throws Exception { FileHelper.loadFile("restapi/rolesmapping_backendroles_captains_single_wrong_datatype.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("backend_roles").equals("Array expected")); @@ -282,7 +282,7 @@ void verifyPutForSuperAdmin(final Header[] header) throws Exception { FileHelper.loadFile("restapi/rolesmapping_hosts_single_wrong_datatype.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("hosts").equals("Array expected")); @@ -294,7 +294,7 @@ void verifyPutForSuperAdmin(final Header[] header) throws Exception { FileHelper.loadFile("restapi/rolesmapping_users_picard_single_wrong_datatype.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("hosts").equals("Array expected")); @@ -370,7 +370,7 @@ void verifyPatchForSuperAdmin(final Header[] header) throws Exception { Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); response = rh.executeGetRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_vulcans", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); List permissions = settings.getAsList("opendistro_security_role_vulcans.backend_roles"); Assert.assertNotNull(permissions); Assert.assertTrue(permissions.contains("spring")); @@ -422,7 +422,7 @@ void verifyPatchForSuperAdmin(final Header[] header) throws Exception { Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); response = rh.executeGetRequest(ENDPOINT + "/rolesmapping/bulknew1", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); permissions = settings.getAsList("bulknew1.backend_roles"); Assert.assertNotNull(permissions); Assert.assertTrue(permissions.contains("vulcanadmin")); @@ -650,19 +650,19 @@ public void checkNullElementsInArray() throws Exception { body, new Header[0] ); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/rolesmapping_null_array_element_backend_roles.json"); response = rh.executePutRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet_captains", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); body = FileHelper.loadFile("restapi/rolesmapping_null_array_element_hosts.json"); response = rh.executePutRequest(ENDPOINT + "/rolesmapping/opendistro_security_role_starfleet_captains", body, new Header[0]); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); } diff --git a/src/test/java/org/opensearch/security/dlic/rest/api/UserApiTest.java b/src/test/java/org/opensearch/security/dlic/rest/api/UserApiTest.java index 895f65bc81..496fe9e1b8 100644 --- a/src/test/java/org/opensearch/security/dlic/rest/api/UserApiTest.java +++ b/src/test/java/org/opensearch/security/dlic/rest/api/UserApiTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator; import org.opensearch.security.dlic.rest.validation.PasswordValidator; import org.opensearch.security.securityconf.impl.CType; @@ -87,7 +87,7 @@ public void testSecurityRoles() throws Exception { // initial configuration, 6 users HttpResponse response = rh.executeGetRequest(ENDPOINT + "/" + CType.INTERNALUSERS.toLCString()); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(133, settings.size()); response = rh.executePatchRequest( ENDPOINT + "/internalusers", @@ -148,7 +148,7 @@ public void testUserApi() throws Exception { // initial configuration HttpResponse response = rh.executeGetRequest(ENDPOINT + "/" + CType.INTERNALUSERS.toLCString()); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(USER_SETTING_SIZE, settings.size()); verifyGet(); verifyPut(); @@ -163,7 +163,7 @@ private void verifyGet(final Header... header) throws Exception { // GET, user admin, exists HttpResponse response = rh.executeGetRequest(ENDPOINT + "/internalusers/admin", header); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(7, settings.size()); // hash must be filtered Assert.assertEquals("", settings.get("admin.hash")); @@ -191,13 +191,13 @@ private void verifyPut(final Header... header) throws Exception { // Faulty JSON payload response = rh.executePutRequest(ENDPOINT + "/internalusers/nagilum", "{some: \"thing\" asd other: \"thing\"}", header); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("reason"), AbstractConfigurationValidator.ErrorType.BODY_NOT_PARSEABLE.getMessage()); // Missing quotes in JSON - parseable in 6.x, but wrong config keys response = rh.executePutRequest(ENDPOINT + "/internalusers/nagilum", "{some: \"thing\", other: \"thing\"}", header); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); // JK: this should be "Could not parse content of request." because JSON is truly invalid // Assert.assertEquals(settings.get("reason"), AbstractConfigurationValidator.ErrorType.INVALID_CONFIGURATION.getMessage()); // Assert.assertTrue(settings.get(AbstractConfigurationValidator.INVALID_KEYS_KEY + ".keys").contains("some")); @@ -231,13 +231,13 @@ private void verifyPut(final Header... header) throws Exception { header ); Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("message"), "Role 'non_existent' is not available for role-mapping."); // Wrong config keys response = rh.executePutRequest(ENDPOINT + "/internalusers/nagilum", "{\"some\": \"thing\", \"other\": \"thing\"}", header); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("reason"), AbstractConfigurationValidator.ErrorType.INVALID_CONFIGURATION.getMessage()); Assert.assertTrue(settings.get(AbstractConfigurationValidator.INVALID_KEYS_KEY + ".keys").contains("some")); Assert.assertTrue(settings.get(AbstractConfigurationValidator.INVALID_KEYS_KEY + ".keys").contains("other")); @@ -294,7 +294,7 @@ private void verifyPatch(final boolean sendAdminCert, Header... restAdminHeader) Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); response = rh.executeGetRequest(ENDPOINT + "/internalusers/test", restAdminHeader); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertFalse(settings.hasValue("test.password")); Assert.assertTrue(settings.hasValue("test.hash")); @@ -354,7 +354,7 @@ private void verifyPatch(final boolean sendAdminCert, Header... restAdminHeader) Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); response = rh.executeGetRequest(ENDPOINT + "/internalusers/bulknew1", restAdminHeader); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertFalse(settings.hasValue("bulknew1.password")); Assert.assertTrue(settings.hasValue("bulknew1.hash")); List roles = settings.getAsList("bulknew1.backend_roles"); @@ -450,7 +450,7 @@ private void verifyPatch(final boolean sendAdminCert, Header... restAdminHeader) // get user, check hash, must be untouched response = rh.executeGetRequest(ENDPOINT + "/internalusers/nagilum", restAdminHeader); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertTrue(settings.get("nagilum.hash").equals("")); } @@ -516,7 +516,7 @@ private void verifyRoles(final boolean sendAdminCert, Header... header) throws E FileHelper.loadFile("restapi/users_wrong_datatypes.json"), header ); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("backend_roles").equals("Array expected")); @@ -528,7 +528,7 @@ private void verifyRoles(final boolean sendAdminCert, Header... header) throws E FileHelper.loadFile("restapi/users_wrong_datatypes.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("backend_roles").equals("Array expected")); @@ -540,7 +540,7 @@ private void verifyRoles(final boolean sendAdminCert, Header... header) throws E FileHelper.loadFile("restapi/users_wrong_datatypes2.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("password").equals("String expected")); @@ -553,7 +553,7 @@ private void verifyRoles(final boolean sendAdminCert, Header... header) throws E FileHelper.loadFile("restapi/users_wrong_datatypes3.json"), header ); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.WRONG_DATATYPE.getMessage(), settings.get("reason")); Assert.assertTrue(settings.get("backend_roles").equals("Array expected")); @@ -584,7 +584,7 @@ private void verifyRoles(final boolean sendAdminCert, Header... header) throws E rh.sendAdminCertificate = sendAdminCert; response = rh.executeGetRequest(ENDPOINT + "/internalusers/picard", header); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals("", settings.get("picard.hash")); List roles = settings.getAsList("picard.backend_roles"); Assert.assertNotNull(roles); @@ -608,7 +608,7 @@ public void testUserApiWithRestAdminPermissions() throws Exception { // initial configuration HttpResponse response = rh.executeGetRequest(ENDPOINT + "/" + CType.INTERNALUSERS.toLCString(), restApiAdminHeader); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(USER_SETTING_SIZE, settings.size()); verifyGet(restApiAdminHeader); verifyPut(restApiAdminHeader); @@ -626,7 +626,7 @@ public void testUserApiWithRestInternalUsersAdminPermissions() throws Exception // initial configuration HttpResponse response = rh.executeGetRequest(ENDPOINT + "/" + CType.INTERNALUSERS.toLCString(), restApiInternalUsersAdminHeader); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(USER_SETTING_SIZE, settings.size()); verifyGet(restApiInternalUsersAdminHeader); verifyPut(restApiInternalUsersAdminHeader); @@ -653,7 +653,7 @@ public void testRegExpPasswordRules() throws Exception { // initial configuration, 6 users HttpResponse response = rh.executeGetRequest("_plugins/_security/api/" + CType.INTERNALUSERS.toLCString()); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(USER_SETTING_SIZE, settings.size()); verifyCouldNotCreatePasswords(HttpStatus.SC_BAD_REQUEST); @@ -785,7 +785,7 @@ public void testScoreBasedPasswordRules() throws Exception { // initial configuration, 6 users HttpResponse response = rh.executeGetRequest("_plugins/_security/api/" + CType.INTERNALUSERS.toLCString()); Assert.assertEquals(response.getBody(), HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(133, settings.size()); addUserWithPassword( @@ -819,7 +819,7 @@ public void testUserApiWithDots() throws Exception { // initial configuration, 6 users HttpResponse response = rh.executeGetRequest(ENDPOINT + "/" + CType.INTERNALUSERS.toLCString()); Assert.assertEquals(HttpStatus.SC_OK, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(USER_SETTING_SIZE, settings.size()); addUserWithPassword(".my.dotuser0", "$2a$12$n5nubfWATfQjSYHiWtUyeOxMIxFInUHOAx8VMmGmxFNPGpaBmeB.m", HttpStatus.SC_CREATED); @@ -953,7 +953,7 @@ public void testUserApiForNonSuperAdmin() throws Exception { new Header[0] ); Assert.assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(settings.get("message"), "Resource 'opendistro_security_reserved' is read-only."); // Patch single hidden user @@ -999,7 +999,7 @@ public void checkNullElementsInArray() throws Exception { String body = FileHelper.loadFile("restapi/users_null_array_element.json"); HttpResponse response = rh.executePutRequest(ENDPOINT + "/internalusers/picard", body, new Header[0]); - Settings settings = Settings.builder().loadFromSource(response.getBody(), XContentType.JSON).build(); + Settings settings = Settings.builder().loadFromSource(response.getBody(), MediaType.JSON).build(); Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(AbstractConfigurationValidator.ErrorType.NULL_ARRAY_ELEMENT.getMessage(), settings.get("reason")); } diff --git a/src/test/java/org/opensearch/security/multitenancy/test/MultitenancyTests.java b/src/test/java/org/opensearch/security/multitenancy/test/MultitenancyTests.java index 648f5df4a0..28b6eb3117 100644 --- a/src/test/java/org/opensearch/security/multitenancy/test/MultitenancyTests.java +++ b/src/test/java/org/opensearch/security/multitenancy/test/MultitenancyTests.java @@ -28,7 +28,7 @@ import org.opensearch.action.support.WriteRequest.RefreshPolicy; import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.security.DefaultObjectMapper; import org.opensearch.security.support.ConfigConstants; import org.opensearch.security.support.WildcardMatcher; @@ -61,36 +61,36 @@ public void testNoDnfof() throws Exception { tc.index( new IndexRequest("indexa").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":\"indexa\"}", XContentType.JSON) + .source("{\"content\":\"indexa\"}", MediaType.JSON) ).actionGet(); tc.index( new IndexRequest("indexb").id("0") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source("{\"content\":\"indexb\"}", XContentType.JSON) + .source("{\"content\":\"indexb\"}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("vulcangov").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("starfleet").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_academy").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("starfleet_library").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.index( - new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("klingonempire").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); - tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("public").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("spock").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); - tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON)) + tc.index(new IndexRequest("kirk").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON)) .actionGet(); tc.index( - new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", XContentType.JSON) + new IndexRequest("role01_role02").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"content\":1}", MediaType.JSON) ).actionGet(); tc.admin() @@ -363,7 +363,7 @@ public void testMtMulti() throws Exception { tc.index( new IndexRequest(dashboardsIndex).id("index-pattern:9fbbd1a0-c3c5-11e8-a13f-71b8ea5a4f7b") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source(body, XContentType.JSON) + .source(body, MediaType.JSON) ).actionGet(); } @@ -509,7 +509,7 @@ public void testDashboardsAlias() throws Exception { .create(new CreateIndexRequest(".kibana-6").alias(new Alias(".kibana")).settings(indexSettings)) .actionGet(); - tc.index(new IndexRequest(".kibana-6").id("6.2.2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(body, XContentType.JSON)) + tc.index(new IndexRequest(".kibana-6").id("6.2.2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(body, MediaType.JSON)) .actionGet(); } @@ -544,12 +544,12 @@ public void testDashboardsAlias65() throws Exception { .create(new CreateIndexRequest(".kibana_1").alias(new Alias(".kibana")).settings(indexSettings)) .actionGet(); - tc.index(new IndexRequest(".kibana_1").id("6.2.2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(body, XContentType.JSON)) + tc.index(new IndexRequest(".kibana_1").id("6.2.2").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source(body, MediaType.JSON)) .actionGet(); tc.index( new IndexRequest(".kibana_-900636979_kibanaro").id("6.2.2") .setRefreshPolicy(RefreshPolicy.IMMEDIATE) - .source(body, XContentType.JSON) + .source(body, MediaType.JSON) ).actionGet(); } diff --git a/src/test/java/org/opensearch/security/protected_indices/ProtectedIndicesTests.java b/src/test/java/org/opensearch/security/protected_indices/ProtectedIndicesTests.java index 3d37c132c9..35ea07b7bc 100644 --- a/src/test/java/org/opensearch/security/protected_indices/ProtectedIndicesTests.java +++ b/src/test/java/org/opensearch/security/protected_indices/ProtectedIndicesTests.java @@ -45,7 +45,7 @@ import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.core.rest.RestStatus; @@ -173,7 +173,7 @@ public void createTestIndicesAndDocs() { tc.index( new IndexRequest(index).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .id("document1") - .source("{ \"foo\": \"bar\" }", XContentType.JSON) + .source("{ \"foo\": \"bar\" }", MediaType.JSON) ).actionGet(); } } @@ -215,7 +215,7 @@ public void testNoSearchResults() throws Exception { // Test direct index query. for (String index : listOfIndexesToTest) { RestHelper.HttpResponse response = rh.executePostRequest(index + "/_search", matchAllQuery, indexAccessNoRoleUserHeader); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -231,7 +231,7 @@ public void testNoSearchResults() throws Exception { // Test index pattern for (String indexPattern : listOfIndexPatternsToTest) { RestHelper.HttpResponse response = rh.executePostRequest(indexPattern + "/_search", matchAllQuery, indexAccessNoRoleUserHeader); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -256,7 +256,7 @@ public void testSearchWithSettingDisabled() throws Exception { // Test direct index query. for (String index : listOfIndexesToTest) { RestHelper.HttpResponse response = rh.executePostRequest(index + "/_search", matchAllQuery, protectedIndexUserHeader); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -272,7 +272,7 @@ public void testSearchWithSettingDisabled() throws Exception { // Test index pattern for (String indexPattern : listOfIndexPatternsToTest) { RestHelper.HttpResponse response = rh.executePostRequest(indexPattern + "/_search", matchAllQuery, protectedIndexUserHeader); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -313,7 +313,7 @@ public void testNoResultsAlias() throws Exception { matchAllQuery, indexAccessNoRoleUserHeader ); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -612,7 +612,7 @@ public void testSearchResults() throws Exception { // Test direct index query. for (String index : listOfIndexesToTest) { RestHelper.HttpResponse response = rh.executePostRequest(index + "/_search", matchAllQuery, protectedIndexUserHeader); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -628,7 +628,7 @@ public void testSearchResults() throws Exception { // Test index pattern for (String indexPattern : listOfIndexPatternsToTest) { RestHelper.HttpResponse response = rh.executePostRequest(indexPattern + "/_search", matchAllQuery, protectedIndexUserHeader); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. @@ -670,7 +670,7 @@ public void testResultsAlias() throws Exception { protectedIndexUserHeader ); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); // confirm good response. diff --git a/src/test/java/org/opensearch/security/ssl/SSLTest.java b/src/test/java/org/opensearch/security/ssl/SSLTest.java index 72ad6d5d16..06e04dd150 100644 --- a/src/test/java/org/opensearch/security/ssl/SSLTest.java +++ b/src/test/java/org/opensearch/security/ssl/SSLTest.java @@ -50,7 +50,7 @@ import org.opensearch.common.settings.MockSecureSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.node.Node; import org.opensearch.node.PluginAwareNode; import org.opensearch.security.OpenSearchSecurityPlugin; @@ -877,7 +877,7 @@ public void testCustomPrincipalExtractor() throws Exception { TestPrincipalExtractor.reset(); Assert.assertEquals( "test", - tc.index(new IndexRequest("test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"a\":5}", XContentType.JSON)) + tc.index(new IndexRequest("test").setRefreshPolicy(RefreshPolicy.IMMEDIATE).source("{\"a\":5}", MediaType.JSON)) .actionGet() .getIndex() ); diff --git a/src/test/java/org/opensearch/security/system_indices/SystemIndicesTests.java b/src/test/java/org/opensearch/security/system_indices/SystemIndicesTests.java index b6f3254a85..5a8ebde16d 100644 --- a/src/test/java/org/opensearch/security/system_indices/SystemIndicesTests.java +++ b/src/test/java/org/opensearch/security/system_indices/SystemIndicesTests.java @@ -29,7 +29,7 @@ import org.opensearch.client.Client; import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.LoggingDeprecationHandler; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentParser; import org.opensearch.core.rest.RestStatus; @@ -112,7 +112,7 @@ private void createTestIndicesAndDocs() { tc.index( new IndexRequest(index).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) .id("document1") - .source("{ \"foo\": \"bar\" }", XContentType.JSON) + .source("{ \"foo\": \"bar\" }", MediaType.JSON) ).actionGet(); } } @@ -160,7 +160,7 @@ private RestHelper sslRestHelper() { private void validateSearchResponse(RestHelper.HttpResponse response, int expectecdHits) throws IOException { assertEquals(RestStatus.OK.getStatus(), response.getStatusCode()); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); assertEquals(RestStatus.OK, searchResponse.status()); @@ -230,7 +230,7 @@ public void testSearchWithSystemIndicesAsAdmin() throws Exception { // search all indices RestHelper.HttpResponse response = restHelper.executePostRequest("/_search", matchAllQuery, allAccessUserHeader); assertEquals(RestStatus.OK.getStatus(), response.getStatusCode()); - XContentParser xcp = XContentType.JSON.xContent() + XContentParser xcp = MediaType.JSON.xContent() .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, response.getBody()); SearchResponse searchResponse = SearchResponse.fromXContent(xcp); assertEquals(RestStatus.OK, searchResponse.status()); diff --git a/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java b/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java index b038949782..e210158e22 100644 --- a/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java +++ b/src/test/java/org/opensearch/security/test/helper/cluster/ClusterHelper.java @@ -61,7 +61,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.common.transport.TransportAddress; import org.opensearch.common.unit.TimeValue; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.http.HttpInfo; import org.opensearch.node.Node; import org.opensearch.node.PluginAwareNode; @@ -297,7 +297,7 @@ public void run() { final AcknowledgedResponse templateAck = nodeClient().admin() .indices() - .putTemplate(new PutIndexTemplateRequest("default").source(defaultTemplate, XContentType.JSON)) + .putTemplate(new PutIndexTemplateRequest("default").source(defaultTemplate, MediaType.JSON)) .actionGet(); if (!templateAck.isAcknowledged()) { diff --git a/src/test/java/org/opensearch/security/test/helper/file/FileHelper.java b/src/test/java/org/opensearch/security/test/helper/file/FileHelper.java index 90adca6a91..0fd5aa036d 100644 --- a/src/test/java/org/opensearch/security/test/helper/file/FileHelper.java +++ b/src/test/java/org/opensearch/security/test/helper/file/FileHelper.java @@ -50,7 +50,7 @@ import org.opensearch.core.common.bytes.BytesReference; import org.opensearch.common.io.Streams; import org.opensearch.common.xcontent.XContentFactory; -import org.opensearch.common.xcontent.XContentType; +import org.opensearch.core.xcontent.MediaType; import org.opensearch.core.xcontent.NamedXContentRegistry; import org.opensearch.core.xcontent.XContentBuilder; import org.opensearch.core.xcontent.XContentParser; @@ -110,7 +110,7 @@ public static BytesReference readYamlContent(final String file) { XContentParser parser = null; try { - parser = XContentFactory.xContent(XContentType.YAML) + parser = XContentFactory.xContent(MediaType.YAML) .createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, new StringReader(loadFile(file))); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder(); @@ -133,7 +133,7 @@ public static BytesReference readYamlContentFromString(final String yaml) { XContentParser parser = null; try { - parser = XContentFactory.xContent(XContentType.YAML) + parser = XContentFactory.xContent(MediaType.YAML) .createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, new StringReader(yaml)); parser.nextToken(); final XContentBuilder builder = XContentFactory.jsonBuilder();