Ejemplo n.º 1
0
    public void handle(Callback[] callbacks) throws UnsupportedCallbackException {

      for (int i = 0; i < callbacks.length; i++) {
        if (callbacks[i] instanceof NameCallback) {
          // prompt the user for a username
          NameCallback nc = (NameCallback) callbacks[i];
          nc.setName(userid);
        } else if (callbacks[i] instanceof PasswordCallback) {
          PasswordCallback pc = (PasswordCallback) callbacks[i];
          pc.setPassword(password.toCharArray());
        }
      }
    }
Ejemplo n.º 2
0
  /**
   * Loads the keystore using the given <code>KeyStore.LoadStoreParameter</code>.
   *
   * <p>Note that if this KeyStore has already been loaded, it is reinitialized and loaded again
   * from the given parameter.
   *
   * @param param the <code>KeyStore.LoadStoreParameter</code> that specifies how to load the
   *     keystore, which may be <code>null</code>
   * @exception IllegalArgumentException if the given <code>KeyStore.LoadStoreParameter</code> input
   *     is not recognized
   * @exception IOException if there is an I/O or format problem with the keystore data. If the
   *     error is due to an incorrect <code>ProtectionParameter</code> (e.g. wrong password) the
   *     {@link Throwable#getCause cause} of the <code>IOException</code> should be an <code>
   *     UnrecoverableKeyException</code>
   * @exception NoSuchAlgorithmException if the algorithm used to check the integrity of the
   *     keystore cannot be found
   * @exception CertificateException if any of the certificates in the keystore could not be loaded
   * @since 1.5
   */
  public void engineLoad(KeyStore.LoadStoreParameter param)
      throws IOException, NoSuchAlgorithmException, CertificateException {

    if (param == null) {
      engineLoad((InputStream) null, (char[]) null);
      return;
    }

    if (param instanceof KeyStore.SimpleLoadStoreParameter) {
      ProtectionParameter protection = param.getProtectionParameter();
      char[] password;
      if (protection instanceof PasswordProtection) {
        password = ((PasswordProtection) protection).getPassword();
      } else if (protection instanceof CallbackHandlerProtection) {
        CallbackHandler handler = ((CallbackHandlerProtection) protection).getCallbackHandler();
        PasswordCallback callback = new PasswordCallback("Password: "******"Could not obtain password", e);
        }
        password = callback.getPassword();
        callback.clearPassword();
        if (password == null) {
          throw new NoSuchAlgorithmException("No password provided");
        }
      } else {
        throw new NoSuchAlgorithmException(
            "ProtectionParameter must" + " be PasswordProtection or CallbackHandlerProtection");
      }
      engineLoad(null, password);
      return;
    }

    throw new UnsupportedOperationException();
  }