String[] fields = JSONObject.getNames(jPrincipals);
for (String field : fields) {
String serviceId = jPrincipals.optString(field);
if (serviceId != null && serviceId.length() > 0) {
if (field.equalsIgnoreCase("AWS")) {
statement.getPrincipals().add(new Principal(serviceId));
} else if (field.equalsIgnoreCase("Service")) {
statement.getPrincipals().add(
new Principal(Services.fromString(serviceId)));
} else if (field.equalsIgnoreCase("Federated")) {
if (WebIdentityProviders.fromString(serviceId) != null) {
statement.getPrincipals().add(
new Principal(WebIdentityProviders.fromString(serviceId)));
} else {
statement.getPrincipals().add(
new Principal("Federated", serviceId));
}
}
} else {
JSONArray jPrincipal = jPrincipals.getJSONArray(field);
convertPrincipalRecord(field, statement, jPrincipal);