I was able to achieve this by creating my own InMemoryOperationInterceptor
:
static class PasswordRemovingOperationInterceptor
extends InMemoryOperationInterceptor {
@Override
public void processSearchEntry(InMemoryInterceptedSearchEntry entry) {
if (!entry.getRequest().getAttributeList().contains("userPassword")) {
if (entry.getSearchEntry().getAttribute("userPassword") != null) {
Entry old = entry.getSearchEntry();
Collection<Attribute> attributes = old.getAttributes().stream()
.filter(attribute ->
!"userPassword".equals(attribute.getName()))
.collect(Collectors.toList());
Entry withoutPassword = new Entry(old.getDN(), attributes);
entry.setSearchEntry(withoutPassword);
}
}
}
}
And then adding this to the startup configuration:
InMemoryDirectoryServerConfig config = ...;
config.addInMemoryOperationInterceptor(new PasswordRemovingOperationInterceptor());
Is there a more elegant way, though?