// Now start to make changes ...
Editor editor = config.edit();
// Find the array of sequencer documents ...
EditableDocument security = editor.getOrCreateDocument(FieldName.SECURITY);
EditableArray providers = security.getOrCreateArray(FieldName.PROVIDERS);
// The container should be an array ...
for (String configuredAuthenticatorName : providers.keySet()) {
// Look for the entry with a name that matches our authenticator name ...
if (authenticatorName.equals(configuredAuthenticatorName)) {
// Find the document in the array with the name field value that matches ...
boolean found = false;
for (Object nested : providers) {
if (nested instanceof EditableDocument) {
EditableDocument doc = (EditableDocument)nested;
if (doc.getString(FieldName.NAME).equals(configuredAuthenticatorName)) {
// Change the field ...
String fieldName = defn.getFieldName();
// Get the raw value from the model node ...
Object rawValue = defn.getTypedValue(newValue);
// And update the field ...
doc.set(fieldName, rawValue);
found = true;
break;
}
}
}
if (!found) {
// Add the nested document ...
EditableDocument doc = Schematic.newDocument();
doc.set(FieldName.NAME, configuredAuthenticatorName);
// Set the field ...
String fieldName = defn.getFieldName();
// Get the raw value from the model node ...
Object rawValue = defn.getTypedValue(newValue);
// And update the field ...
doc.set(fieldName, rawValue);
providers.add(doc);
}
break;
}
}