/** * Clears the password after a certain time if {@link #getPassword()} hasn't been called. * @see Configuration#getPasswordCacheDuration() */ @Override public void run() { while (!Thread.interrupted()) { try { TimeUnit.MINUTES.sleep(1); } catch (InterruptedException e) { break; } try { long durationMilliseconds = TimeUnit.MILLISECONDS.convert(configuration.getPasswordCacheDuration(), TimeUnit.MINUTES); boolean isEmpty = password==null || password.length==0; if (System.currentTimeMillis()>lastReset+durationMilliseconds && !isEmpty) // cache empty passwords forever clear(); } catch (RuntimeException e) { // catch unexpected exceptions to keep the thread running log.error("Exception caught in PasswordCache loop", e); } } log.debug("PasswordCache thread exiting."); } }
allowing(configuration).getPasswordCacheDuration(); will(returnValue(1)); }});