FileDocCategorySizeDatePackage
SampleUsernamePasswordCallbackHandler.javaAPI DocExample4129Tue May 29 16:57:54 BST 2007common

SampleUsernamePasswordCallbackHandler

public class SampleUsernamePasswordCallbackHandler extends Object implements CallbackHandler
author
Jiandong Guo

Fields Summary
Constructors Summary
Methods Summary
public voidhandle(javax.security.auth.callback.Callback[] callbacks)

        
        for (int i=0; i < callbacks.length; i++) {
            Callback callback = callbacks[i];
            if (callback instanceof NameCallback) {
                handleUsernameCallback((NameCallback)callback);
            } else if (callback instanceof PasswordCallback) {
                handlePasswordCallback((PasswordCallback)callback);
            }else{
                throw new UnsupportedCallbackException(callback, "Unknow callback for username or password");
            }
        }
    
private voidhandlePasswordCallback(javax.security.auth.callback.PasswordCallback cb)

        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.err.println("***Please Enter Your Password: ");
        System.err.flush();
        cb.setPassword((new BufferedReader(new InputStreamReader(System.in))).readLine().toCharArray());
    
private voidhandleUsernameCallback(javax.security.auth.callback.NameCallback cb)

        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.err.println("***Please Enter Your User Name: ");
        System.err.flush();
        cb.setName((new BufferedReader(new InputStreamReader(System.in))).readLine());