删除用户';来自未绑定LDAP搜索结果的密码

删除用户';来自未绑定LDAP搜索结果的密码,ldap,unboundid-ldap-sdk,Ldap,Unboundid Ldap Sdk,使用,我可以执行DefaultDirectoryService#setPasswordHidden以确保在进行LDAP查询时,返回的记录从结果集中删除userPassword属性 我如何使用InMemoryDirectoryServer实现同样的功能,比如说使用InMemoryDirectoryServer?我通过创建自己的InMemoryOperationInterceptor实现了这一点: static class PasswordRemovingOperationInterceptor

使用,我可以执行
DefaultDirectoryService#setPasswordHidden
以确保在进行LDAP查询时,返回的记录从结果集中删除
userPassword
属性


我如何使用InMemoryDirectoryServer实现同样的功能,比如说使用InMemoryDirectoryServer?

我通过创建自己的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);
            }
        }
    }
}
有没有更优雅的方式呢

InMemoryDirectoryServerConfig config = ...;
config.addInMemoryOperationInterceptor(new PasswordRemovingOperationInterceptor());