/** * Returns the cached password. If the password is not in the cache, the default password (if no * password is set) or <code>null</code> (if a password is set) is returned. * @return The cached password or <code>null</code> if the password is not in the cache */ public synchronized byte[] getPassword() { resetExpiration(); if ((password==null || password.length<=0) && !configuration.getPasswordFile().exists()) return FileEncryptionConstants.DEFAULT_PASSWORD; else return password; }
/** * Tests if a password is correct and stores it in the cache if it is. * If the password is not correct, a <code>PasswordException</code> is thrown. * @param password * @throws IOException * @throws GeneralSecurityException * @throws PasswordException */ @Override public void tryPassword(byte[] password) throws IOException, GeneralSecurityException, PasswordException { File passwordFile = configuration.getPasswordFile(); boolean correct = FileEncryptionUtil.isPasswordCorrect(password, passwordFile); if (correct) { // Don't cache tried password if none is set. This check is needed // because IMAP doesn't support a blank password, so the user // inputs a random string. if (passwordFile.exists()) passwordCache.setPassword(password); } else throw new PasswordException(); }
if (password == null) throw new PasswordException(); File passwordFile = configuration.getPasswordFile(); boolean correct = FileEncryptionUtil.isPasswordCorrect(password, passwordFile); if (!correct)
File passwordFile = configuration.getPasswordFile();
atLeast(1).of(configuration).getPasswordFile(); will(returnValue(passwordFile)); }});