Skip to content

Commit

Permalink
Merge branch '2.x' into backport/backport-2274-to-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
cwperks authored Feb 21, 2023
2 parents 9290db3 + d86dc3f commit 11732c2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.ToXContent;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentType;

public class WhoAmIResponse extends ActionResponse implements ToXContent {

Expand Down Expand Up @@ -105,6 +106,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

@Override
public String toString() {
return Strings.toString(this, true, true);
return Strings.toString(XContentType.JSON,this, true, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +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.env.Environment;
import org.opensearch.security.auditlog.AuditLog;
import org.opensearch.security.auditlog.config.AuditConfig;
Expand Down Expand Up @@ -379,7 +380,7 @@ public Map<CType, SecurityDynamicConfiguration<?>> getConfigurationsFromIndex(Co
if (logComplianceEvent && auditLog.getComplianceConfig().isEnabled()) {
CType configurationType = configTypes.iterator().next();
Map<String, String> fields = new HashMap<String, String>();
fields.put(configurationType.toLCString(), Strings.toString(retVal.get(configurationType)));
fields.put(configurationType.toLCString(), Strings.toString(XContentType.JSON, retVal.get(configurationType)));
auditLog.logDocumentRead(this.securityIndex, configurationType.toLCString(), null, fields);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.common.util.concurrent.ThreadContext;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.index.query.ParsedQuery;
import org.opensearch.rest.RestStatus;
import org.opensearch.search.DocValueFormat;
Expand Down Expand Up @@ -209,10 +210,10 @@ public boolean invoke(String action, ActionRequest request, final ActionListener
StringBuilder sb = new StringBuilder();

if (searchRequest.source() != null) {
sb.append(Strings.toString(searchRequest.source()) + System.lineSeparator());
sb.append(Strings.toString(XContentType.JSON, searchRequest.source()) + System.lineSeparator());
}

sb.append(Strings.toString(af) + System.lineSeparator());
sb.append(Strings.toString(XContentType.JSON, af) + System.lineSeparator());

LogManager.getLogger("debuglogger").error(sb.toString());

Expand All @@ -222,7 +223,7 @@ public boolean invoke(String action, ActionRequest request, final ActionListener
searchRequest.requestCache(Boolean.FALSE);
} else {
LogManager.getLogger("debuglogger").error("Shard requestcache enabled for "
+ (searchRequest.source() == null ? "<NULL>" : Strings.toString(searchRequest.source())));
+ (searchRequest.source() == null ? "<NULL>" : Strings.toString(XContentType.JSON, searchRequest.source())));
}

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,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(nir, true, true));
sb.append(Strings.toString(XContentType.JSON, nir, true, true));
} catch (Exception e1) {
sb.append(ExceptionsHelper.stackTrace(e1));
}
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/org/opensearch/security/ConfigTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.opensearch.common.Strings;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.security.securityconf.Migration;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
Expand Down Expand Up @@ -59,18 +60,18 @@ public void testMigrate() throws Exception {
Tuple<SecurityDynamicConfiguration<RoleV7>, SecurityDynamicConfiguration<TenantV7>> rolesResult = Migration.migrateRoles((SecurityDynamicConfiguration<RoleV6>)load("./legacy/securityconfig_v6/roles.yml", CType.ROLES),
(SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));

System.out.println(Strings.toString(rolesResult.v2(), true, false));
System.out.println(Strings.toString(rolesResult.v1(), true, false));
System.out.println(Strings.toString(XContentType.JSON, rolesResult.v2(), true, false));
System.out.println(Strings.toString(XContentType.JSON, rolesResult.v1(), true, false));


SecurityDynamicConfiguration<ActionGroupsV7> actionGroupsResult = Migration.migrateActionGroups((SecurityDynamicConfiguration<ActionGroupsV6>)load("./legacy/securityconfig_v6/action_groups.yml", CType.ACTIONGROUPS));
System.out.println(Strings.toString(actionGroupsResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, actionGroupsResult, true, false));
SecurityDynamicConfiguration<ConfigV7> configResult =Migration.migrateConfig((SecurityDynamicConfiguration<ConfigV6>)load("./legacy/securityconfig_v6/config.yml", CType.CONFIG));
System.out.println(Strings.toString(configResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, configResult, true, false));
SecurityDynamicConfiguration<InternalUserV7> internalUsersResult = Migration.migrateInternalUsers((SecurityDynamicConfiguration<InternalUserV6>)load("./legacy/securityconfig_v6/internal_users.yml", CType.INTERNALUSERS));
System.out.println(Strings.toString(internalUsersResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, internalUsersResult, true, false));
SecurityDynamicConfiguration<RoleMappingsV7> rolemappingsResult = Migration.migrateRoleMappings((SecurityDynamicConfiguration<RoleMappingsV6>)load("./legacy/securityconfig_v6/roles_mapping.yml", CType.ROLESMAPPING));
System.out.println(Strings.toString(rolemappingsResult, true, false));
System.out.println(Strings.toString(XContentType.JSON, rolemappingsResult, true, false));
}

@Test
Expand Down Expand Up @@ -113,7 +114,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(conf), cType, configVersion, 0, 0);
SecurityDynamicConfiguration.fromJson(Strings.toString(XContentType.JSON, conf), cType, configVersion, 0, 0);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected void populateData(Client tc) {
e.printStackTrace();
}
System.out.println("q");
System.out.println(Strings.toString(tc.search(new SearchRequest().indices(".opendistro_security")).actionGet()));
System.out.println(Strings.toString(XContentType.JSON, tc.search(new SearchRequest().indices(".opendistro_security")).actionGet()));
tc.search(new SearchRequest().indices("deals")).actionGet();
}

Expand Down

0 comments on commit 11732c2

Please sign in to comment.