Polish LdapTemplate Logging

Issue gh-345
This commit is contained in:
Josh Cummings
2024-02-01 17:12:07 -07:00
parent 8adf061a74
commit 95da09ca79

View File

@@ -252,12 +252,15 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
@Override
public void search(final Name base, final String filter, final SearchControls controls,
NameClassPairCallbackHandler handler) {
SearchExecutor se = (ctx) -> {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
return ctx.search(base, filter, controls);
};
// Create a SearchExecutor to perform the search.
if (handler instanceof ContextMapperCallbackHandler) {
assureReturnObjFlagSet(controls);
}
search(searchExecutorWithLogging(base, filter, controls), handler);
search(se, handler);
}
/**
@@ -266,12 +269,15 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
@Override
public void search(final String base, final String filter, final SearchControls controls,
NameClassPairCallbackHandler handler) {
SearchExecutor se = (ctx) -> {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
return ctx.search(base, filter, controls);
};
// Create a SearchExecutor to perform the search.
if (handler instanceof ContextMapperCallbackHandler) {
assureReturnObjFlagSet(controls);
}
search(searchExecutorWithLogging(base, filter, controls), handler);
search(se, handler);
}
/**
@@ -280,12 +286,15 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
@Override
public void search(final Name base, final String filter, final SearchControls controls,
NameClassPairCallbackHandler handler, DirContextProcessor processor) {
SearchExecutor se = (ctx) -> {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
return ctx.search(base, filter, controls);
};
// Create a SearchExecutor to perform the search.
if (handler instanceof ContextMapperCallbackHandler) {
assureReturnObjFlagSet(controls);
}
search(searchExecutorWithLogging(base, filter, controls), handler, processor);
search(se, handler, processor);
}
/**
@@ -294,12 +303,15 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
@Override
public void search(final String base, final String filter, final SearchControls controls,
NameClassPairCallbackHandler handler, DirContextProcessor processor) {
SearchExecutor se = (ctx) -> {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
return ctx.search(base, filter, controls);
};
// Create a SearchExecutor to perform the search.
if (handler instanceof ContextMapperCallbackHandler) {
assureReturnObjFlagSet(controls);
}
search(searchExecutorWithLogging(base, filter, controls), handler, processor);
search(se, handler, processor);
}
/**
@@ -1552,7 +1564,10 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
assureReturnObjFlagSet(searchControls);
NamingEnumeration<SearchResult> results = unchecked(searchSupplier(ctx, base, encodedFilter, searchControls));
NamingEnumeration<SearchResult> results = unchecked(() -> {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
return ctx.search(base, encodedFilter, searchControls);
});
if (results == null) {
return Stream.empty();
}
@@ -1781,38 +1796,6 @@ public class LdapTemplate implements LdapOperations, InitializingBean {
return searchForStream(builder.filter(includeClass), contextMapper);
}
private SearchExecutor searchExecutorWithLogging(final Name base, final String filter,
final SearchControls controls) {
return ctx -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
}
return ctx.search(base, filter, controls);
};
}
private SearchExecutor searchExecutorWithLogging(final String base, final String filter,
final SearchControls controls) {
return ctx -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
}
return ctx.search(base, filter, controls);
};
}
private CheckedSupplier<NamingEnumeration<SearchResult>> searchSupplier(final DirContext ctx,
final Name base,
final String filter,
final SearchControls controls) {
return () -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing search with base [{}] and filter [{}]", base, filter);
}
return ctx.search(base, filter, controls);
};
}
private <T> T unchecked(CheckedSupplier<T> supplier) {
try {
return supplier.get();