使用ApacheDS,我可以执行DefaultDirectoryService#setPasswordHidden
以确保进行LDAP查询时,返回的记录从结果集中删除userPassword
属性。
如何使用UnboundId(例如,InMemoryDirectoryServer
)实现相同的目标?
答案 0 :(得分:0)
我能够通过创建自己的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());
但是,还有一种更优雅的方式吗?