RedisRealm extends CachingRealm { @Override public Account authenticate(StandardCredentials requestCredentials) { final String username = requestCredentials.getUsername(); final String password = requestCredentials.getPassword(); if (hasAccount(username)) { return super.authenticate(requestCredentials); } return authenticate(username, password); } RedisRealm(); @Override void setup(Config config); @Override void start(); @Override void stop(); @Override Account authenticate(StandardCredentials requestCredentials); @Override Account authenticate(final String username, final String password);  }
@Test public void basicTest() { RedisRealm realm = getRealm(); Account account = null; account = realm.authenticate("phineas", "fail"); assertNull(account); account = realm.authenticate("phineas", "iKnowWhatWereGonnaDoToday"); assertNotNull(account); assertEquals("phineas", account.getUsername()); assertEquals("Phineas Flynn", account.getName()); assertTrue(account.getEmailAddresses().contains("phineas.flynn@disney.com")); assertTrue(account.hasRole("inventor")); assertTrue(account.isPermitted("secure:view")); account = realm.authenticate("ferb", "fail"); assertNull(account); account = realm.authenticate("ferb", "ferb"); assertNotNull(account); assertEquals("ferb", account.getUsername()); assertEquals("Ferb Fletcher", account.getName()); assertTrue(account.getEmailAddresses().contains("ferb.fletcher@disney.com")); assertTrue(account.hasRole("inventor")); assertTrue(account.isPermitted("secure:view")); account = realm.authenticate("candace", "fail"); assertNull(account); account = realm.authenticate("candace", "ilovejeremy"); assertNotNull(account); assertEquals("candace", account.getUsername()); assertEquals("Candace Flynn", account.getName()); assertTrue(account.getEmailAddresses().contains("candace.flynn@disney.com")); assertFalse(account.hasRole("inventor")); assertTrue(account.isPermitted("secure:view")); account = realm.authenticate("linda", "fail"); assertNull(account); account = realm.authenticate("linda", "imLindanaAndIWannaHaveFun"); assertNotNull(account); assertEquals("linda", account.getUsername()); assertEquals("Linda Flynn-Fletcher", account.getName()); assertTrue(account.getEmailAddresses().contains("linda.fletcher@disney.com")); assertFalse(account.hasRole("inventor")); assertFalse(account.isPermitted("secure:view")); account = realm.authenticate("heinz", "CurseYouPerryThePlatypus"); assertNull(account); }