FileDocCategorySizeDatePackage
PasswordCallback.javaAPI DocAndroid 1.5 API4092Wed May 06 22:41:02 BST 2009javax.security.auth.callback

PasswordCallback

public class PasswordCallback extends Object implements Serializable, Callback
Is used in conjunction with a {@link CallbackHandler} to retrieve a password when needed.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private String
prompt
boolean
echoOn
private char[]
inputPassword
Constructors Summary
public PasswordCallback(String prompt, boolean echoOn)
Creates a new {@code PasswordCallback} instance.

param
prompt the message that should be displayed to the user
param
echoOn determines whether the user input should be echoed

        super();
        setPrompt(prompt);
        this.echoOn = echoOn;
    
Methods Summary
public voidclearPassword()
Clears the password stored in this {@code PasswordCallback}.

        if (inputPassword != null) {
            Arrays.fill(inputPassword, '\u0000");
        }
    
public char[]getPassword()
Returns the password. The security service that needs the password usually calls this method once the {@link CallbackHandler} has finished its work.

return
the password. A copy of the internal password is created and returned, so subsequent changes to the internal password do not affect the result.

        if (inputPassword != null) {
            char[] tmp = new char[inputPassword.length];
            System.arraycopy(inputPassword, 0, tmp, 0, tmp.length);
            return tmp;
        }
        return null;
    
public java.lang.StringgetPrompt()
Returns the prompt that was specified when creating this {@code PasswordCallback}

return
the prompt

        return prompt;
    
public booleanisEchoOn()
Queries whether this {@code PasswordCallback} expects user input to be echoed, which is specified during the creation of the object.

return
{@code true} if (and only if) user input should be echoed

        return echoOn;
    
public voidsetPassword(char[] password)
Sets the password. The {@link CallbackHandler} that performs the actual provisioning or input of the password needs to call this method to hand back the password to the security service that requested it.

param
password the password. A copy of this is stored, so subsequent changes to the input array do not affect the {@code PasswordCallback}.

        if (password == null) {
            this.inputPassword = password;
        } else {
            inputPassword = new char[password.length];
            System.arraycopy(password, 0, inputPassword, 0, inputPassword.length);
        }
    
private voidsetPrompt(java.lang.String prompt)


          
        if (prompt == null || prompt.length() == 0) {
            throw new IllegalArgumentException(Messages.getString("auth.14")); //$NON-NLS-1$
        }
        this.prompt = prompt;