CachingPasswordEncoder implements PasswordEncoder { @Override public boolean matches(CharSequence rawPassword, String encodedPassword) throws AuthenticationException { String cacheKey = cacheEncode(rawPassword); return internalMatches(cacheKey, rawPassword, encodedPassword); } CachingPasswordEncoder(final PasswordEncoder passwordEncoder); @Override String encode(CharSequence rawPassword); @Override boolean matches(CharSequence rawPassword, String encodedPassword);  }
@Test void matches() { cachingPasswordEncoder.encode(password); String encoded = cachingPasswordEncoder.encode(password); int iterations = 5; for (int i = 0; i < iterations; i++) { assertTrue(passwordEncoder.matches(password, encoded)); assertTrue(cachingPasswordEncoder.matches(password, encoded)); } }