FileDocCategorySizeDatePackage
MyCallbackHandler.javaAPI DocExample1255Mon Jan 15 13:11:52 GMT 2001javasec.samples.ch15

MyCallbackHandler

public class MyCallbackHandler extends Object implements CallbackHandler

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

        for (int i = 0; i < cb.length; i++) {
            if (cb[i] instanceof NameCallback) {
                NameCallback nc = (NameCallback) cb[i];
                System.out.print(nc.getPrompt()+ " ");
                System.out.flush();
                String name = new BufferedReader
                       (new InputStreamReader(System.in)).readLine();
                nc.setName(name);
            }
            else if (cb[i] instanceof PasswordCallback) {
                PasswordCallback pc = (PasswordCallback) cb[i];
                System.out.print(pc.getPrompt()+ " ");
                System.out.flush();
                String pw = new BufferedReader
                        (new InputStreamReader(System.in)).readLine();
                pc.setPassword(pw.toCharArray());
                pw = null;   // Let pw be collected as soon as possible
            } else throw new
                   UnsupportedCallbackException(cb[i], "MyCallbackHandler");
        }