952 * @param getPasswdFromSharedState boolean that tells this method whether
953 * to retrieve the password from the sharedState.
954 * @exception LoginException if the username/password cannot be acquired.
955 */
956 private void getUsernamePassword(boolean getPasswdFromSharedState)
957 throws LoginException {
958
959 if (getPasswdFromSharedState) {
960 // use the password saved by the first module in the stack
961 username = (String)sharedState.get(USERNAME_KEY);
962 password = (char[])sharedState.get(PASSWORD_KEY);
963 return;
964 }
965
966 // prompt for a username and password
967 if (callbackHandler == null)
968 throw new LoginException("No CallbackHandler available " +
969 "to acquire authentication information from the user");
970
971 Callback[] callbacks = new Callback[2];
972 callbacks[0] = new NameCallback(rb.getString("username: "));
973 callbacks[1] = new PasswordCallback(rb.getString("password: "), false);
974
975 try {
976 callbackHandler.handle(callbacks);
977 username = ((NameCallback)callbacks[0]).getName();
978 char[] tmpPassword = ((PasswordCallback)callbacks[1]).getPassword();
979 password = new char[tmpPassword.length];
980 System.arraycopy(tmpPassword, 0,
981 password, 0, tmpPassword.length);
982 ((PasswordCallback)callbacks[1]).clearPassword();
983
984 } catch (java.io.IOException ioe) {
985 throw new LoginException(ioe.toString());
986
987 } catch (UnsupportedCallbackException uce) {
988 throw new LoginException("Error: " + uce.getCallback().toString() +
989 " not available to acquire authentication information" +
990 " from the user");
991 }
992 }
993
|
952 * @param getPasswdFromSharedState boolean that tells this method whether
953 * to retrieve the password from the sharedState.
954 * @exception LoginException if the username/password cannot be acquired.
955 */
956 private void getUsernamePassword(boolean getPasswdFromSharedState)
957 throws LoginException {
958
959 if (getPasswdFromSharedState) {
960 // use the password saved by the first module in the stack
961 username = (String)sharedState.get(USERNAME_KEY);
962 password = (char[])sharedState.get(PASSWORD_KEY);
963 return;
964 }
965
966 // prompt for a username and password
967 if (callbackHandler == null)
968 throw new LoginException("No CallbackHandler available " +
969 "to acquire authentication information from the user");
970
971 Callback[] callbacks = new Callback[2];
972 callbacks[0] = new NameCallback(rb.getString("username."));
973 callbacks[1] = new PasswordCallback(rb.getString("password."), false);
974
975 try {
976 callbackHandler.handle(callbacks);
977 username = ((NameCallback)callbacks[0]).getName();
978 char[] tmpPassword = ((PasswordCallback)callbacks[1]).getPassword();
979 password = new char[tmpPassword.length];
980 System.arraycopy(tmpPassword, 0,
981 password, 0, tmpPassword.length);
982 ((PasswordCallback)callbacks[1]).clearPassword();
983
984 } catch (java.io.IOException ioe) {
985 throw new LoginException(ioe.toString());
986
987 } catch (UnsupportedCallbackException uce) {
988 throw new LoginException("Error: " + uce.getCallback().toString() +
989 " not available to acquire authentication information" +
990 " from the user");
991 }
992 }
993
|