How do I set it up so that the below login method accepts input from 2 JTextfield boxes?

The problem is that this is a JAAS login application. The below method uses Java's Callback class and it's kinda bugging me out. Because it is wired in with the Callback class (among other things) the standard JTextfield username = Class.getText(); isn't working. Your thoughts are welcome: public boolean login() throws LoginException { // prompt for a user name and password if (callbackHandler == null) throw new LoginException("Error: no CallbackHandler available " + "to garner authentication information from the user"); Callback[] callbacks = new Callback[2]; callbacks[0] = new NameCallback("user name: "); callbacks[1] = new PasswordCallback("password: ", false); try { callbackHandler.handle(callbacks); username = ((NameCallback)callbacks[0]).getName(); char[] tmpPassword = ((PasswordCallback)callbacks[1]).getPassword(); if (tmpPassword == null) { // treat a NULL password as an empty password tmpPassword = new char[0]; } password = new char[tmpPassword.length]; System.arraycopy(tmpPassword, 0, password, 0, tmpPassword.length); ((PasswordCallback)callbacks[1]).clearPassword(); } catch ( ioe) { throw new LoginException(ioe.toString()); } catch (UnsupportedCallbackException uce) { throw new LoginException("Error: " + uce.getCallback().toString() + " not available to garner authentication information " + "from the user"); } . . .
Wouldn't the CallbackHandler contain the code that gets the input from the user, in this case, call the Swing code and then return only after the user is done entering the data? Perhaps this is the code you should be showing and not the LoginModule code. What problems are you having? What are you trying to do with this line? JTextfield username = Class.getText(); as it doesn't make sense to me.

以上就是How do I set it up so that the below login method accepts input from 2 JTextfield boxes?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准