LdapBasicAuthenticator implements Authenticator<BasicCredentials, User> { String sanitizeUsername(String username) { return username.replaceAll("[^a-zA-Z0-9_.]", ""); } LdapBasicAuthenticator(LdapConfig settings); Optional<User> authenticate(BasicCredentials credentials);  }
@Test public void testSanitizeUsername() { String correctUsername = "userNAME_123.45Z"; String sanitized = AUTHENTICATOR_FOR_UTIL_METHODS_WITHOUT_SSL.sanitizeUsername(correctUsername); Assert.assertEquals(correctUsername, sanitized); String incorrectUsername = "userNAME-~!@#$%^&777*()_+-=`[]\\{}|;':\",./<>?你"; sanitized = AUTHENTICATOR_FOR_UTIL_METHODS_WITHOUT_SSL.sanitizeUsername(incorrectUsername); System.out.println(sanitized); Assert.assertEquals("userNAME777_.", sanitized); }