/** Here, we attempt to get the password from the private alias/passwords map. */ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { try { String id = (String) callback.getClass().getMethod("getIdentifier").invoke(callback); String pass = passwords.get(id); if (pass != null) { callback.getClass().getMethod("setPassword", String.class).invoke(callback, pass); return; } } catch (Exception ex) { UnsupportedCallbackException e = new UnsupportedCallbackException(callback); e.initCause(ex); throw e; } } }