Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging for test LdapServer actions #3933

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ServerLogger());
config.setAccessLogHandler(new ServerLogger());

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 ServerLogger extends Handler {
final Logger logger = LogManager.getLogger(ServerLogger.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();
*/
}
6 changes: 6 additions & 0 deletions src/test/resources/log4j2-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ rootLogger.level = warn
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.file.ref = LOGFILE

# For troubleshooting com.amazon.dlic.auth.ldap.* test cases
logger.ldapServerLogger.name = com.amazon.dlic.auth.ldap.srv.LdapServer.ServerLogger
logger.ldapServerLogger.level = info
logger.ldapAuthBackend.name = com.amazon.dlic.auth.ldap.backend.LDAPAuthorizationBackend
logger.ldapAuthBackend.level = debug

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

Expand Down
Loading