Skip to content

Commit

Permalink
Add logging for LdapServer actions
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Jan 9, 2024
1 parent 649a2fc commit 7f343ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/test/java/com/amazon/dlic/auth/ldap/srv/LdapServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

import com.google.common.io.CharStreams;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -153,9 +156,8 @@ private synchronized int configureAndStartServer(String... ldifFiles) throws Exc
config.setEnforceAttributeSyntaxCompliance(false);
config.setEnforceSingleStructuralObjectClass(false);

// config.setLDAPDebugLogHandler(DEBUG_HANDLER);
// config.setAccessLogHandler(DEBUG_HANDLER);
// config.addAdditionalBindCredentials(configuration.getBindDn(), configuration.getPassword());
config.setLDAPDebugLogHandler(new DebugHandler());
config.setAccessLogHandler(new DebugHandler());

server = new InMemoryDirectoryServer(config);

Expand Down Expand Up @@ -214,25 +216,33 @@ private int loadLdifFiles(String... ldifFiles) throws Exception {
return ldifLoadCount;
}

/* private static class DebugHandler extends Handler {
private final static Logger LOG = LogManager.getLogger(DebugHandler.class);
private static class DebugHandler extends Handler {
final Logger logger = LogManager.getLogger(DebugHandler.class);

@Override
public void publish(LogRecord logRecord) {
//LOG.debug(ToStringBuilder.reflectionToString(logRecord, ToStringStyle.MULTI_LINE_STYLE));
public void publish(final LogRecord logRecord) {
logger.log(toLog4jLevel(logRecord.getLevel()), logRecord.getMessage(), logRecord.getThrown());
}

@Override
public void flush() {
}
public void flush() {}

@Override
public void close() throws SecurityException {
public void close() throws SecurityException {}

private Level toLog4jLevel(java.util.logging.Level javaLevel) {
switch (javaLevel.getName()) {
case "SEVERE":
return Level.ERROR;
case "WARNING":
return Level.WARN;
case "INFO":
return Level.INFO;
case "CONFIG":
return Level.DEBUG;
default:
return Level.TRACE;
}
}
}
private static final DebugHandler DEBUG_HANDLER = new DebugHandler();
*/
}
3 changes: 3 additions & 0 deletions src/test/resources/log4j2-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ rootLogger.level = warn
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.file.ref = LOGFILE

logger.resolver.name = com.amazon.dlic.auth.ldap.srv.LdapServer
logger.resolver.level = info

#logger.resolver.name = org.opensearch.security.resolver
#logger.resolver.level = trace

Expand Down

0 comments on commit 7f343ff

Please sign in to comment.