/**
   * OK button event handler.
   *
   * @param e action event
   */
  public void actionPerformed(ActionEvent e) {
    boolean close = false;
    CredentialsStorageService credentialsStorageService =
        SecurityConfigActivator.getCredentialsStorageService();
    String oldMasterPassword = null;

    if (credentialsStorageService.isUsingMasterPassword()) {
      oldMasterPassword = getCurrentPassword();
      if (oldMasterPassword.length() == 0) {
        displayPopupError(
            resources.getI18NString("plugin.securityconfig.masterpassword.MP_CURRENT_EMPTY"));
        return;
      }
      boolean verified = credentialsStorageService.verifyMasterPassword(oldMasterPassword);
      if (!verified) {
        displayPopupError(
            resources.getI18NString(
                "plugin.securityconfig.masterpassword.MP_VERIFICATION_FAILURE_MSG"));
        return;
      }
    }
    // if the callback executes OK, we close the dialog
    if (callback != null) {
      close = callback.execute(oldMasterPassword, getNewPassword());
    }

    if (close) {
      dialog = null;
      dispose();
    }
  }
  /**
   * Returns the password last saved for the specified account.
   *
   * <p>TODO Delegate the implementation to {@link AccountManager} because it knows the format in
   * which the password (among the other account properties) was saved.
   *
   * @param bundleContext a currently valid bundle context.
   * @param accountID the AccountID for the account whose password we're looking for..
   * @return a String containing the password for the specified accountID.
   */
  protected String loadPassword(BundleContext bundleContext, AccountID accountID) {
    String accountPrefix = findAccountPrefix(bundleContext, accountID, getFactoryImplPackageName());

    if (accountPrefix == null) return null;

    CredentialsStorageService credentialsStorage =
        ServiceUtils.getService(bundleContext, CredentialsStorageService.class);

    return credentialsStorage.loadPassword(accountPrefix);
  }
  /**
   * Saves the password for the specified account after scrambling it a bit so that it is not
   * visible from first sight (Method remains highly insecure).
   *
   * <p>TODO Delegate the implementation to {@link AccountManager} because it knows the format in
   * which the password (among the other account properties) is to be saved.
   *
   * @param bundleContext a currently valid bundle context.
   * @param accountID the <tt>AccountID</tt> of the account whose password is to be stored
   * @param password the password to be stored
   * @throws IllegalArgumentException if no account corresponding to <tt>accountID</tt> has been
   *     previously stored.
   * @throws OperationFailedException if anything goes wrong while storing the specified
   *     <tt>password</tt>
   */
  protected void storePassword(BundleContext bundleContext, AccountID accountID, String password)
      throws IllegalArgumentException, OperationFailedException {
    String accountPrefix = findAccountPrefix(bundleContext, accountID, getFactoryImplPackageName());

    if (accountPrefix == null) {
      throw new IllegalArgumentException(
          "No previous records found for account ID: "
              + accountID.getAccountUniqueID()
              + " in package"
              + getFactoryImplPackageName());
    }

    CredentialsStorageService credentialsStorage =
        ServiceUtils.getService(bundleContext, CredentialsStorageService.class);

    if (!credentialsStorage.storePassword(accountPrefix, password)) {
      throw new OperationFailedException(
          "CredentialsStorageService failed to storePassword",
          OperationFailedException.GENERAL_ERROR);
    }
  }