HtpasswdRealm extends MemoryRealm { @Override public Account authenticate(AuthenticationToken authenticationToken) { readCredentialsFile(); return super.authenticate(authenticationToken); } HtpasswdRealm(); @Override boolean canAuthenticate(AuthenticationToken authenticationToken); @Override void setup(Config config); @Override void start(); @Override void stop(); boolean isAllowClearTextPasswords(); void setAllowClearTextPasswords(boolean value); synchronized void setFile(File realmFile); @Override boolean hasAccount(String username); @Override Account getAccount(String username); @Override Account authenticate(AuthenticationToken authenticationToken);  }
@Test public void testAuthenticate() { htpasswd.setAllowClearTextPasswords(true); Account account = htpasswd.authenticate("user1", "pass1"); assertNotNull(account); assertEquals("user1", account.getUsername()); account = htpasswd.authenticate("user2", "pass2"); assertNotNull(account); assertEquals("user2", account.getUsername()); account = htpasswd.authenticate("plain", "passWord"); assertNotNull(account); assertEquals("plain", account.getUsername()); htpasswd.setAllowClearTextPasswords(false); account = htpasswd.authenticate("crypt", "password"); assertNotNull(account); assertEquals("crypt", account.getUsername()); account = htpasswd.authenticate("md5", "password"); assertNotNull(account); assertEquals("md5", account.getUsername()); account = htpasswd.authenticate("sha", "password"); assertNotNull(account); assertEquals("sha", account.getUsername()); account = htpasswd.authenticate("trailing", "whitespace"); assertNotNull(account); assertEquals("trailing", account.getUsername()); account = htpasswd.authenticate("tabbed", "frontAndBack"); assertNotNull(account); assertEquals("tabbed", account.getUsername()); account = htpasswd.authenticate("leading", "whitespace"); assertNotNull(account); assertEquals("leading", account.getUsername()); }