1 /*
2  * @(#) $Id: DFCallbackHandler.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10import java.io.BufferedReader;
11import java.io.InputStreamReader;
12import java.io.IOException;
13import javax.security.auth.callback.Callback;
14import javax.security.auth.callback.CallbackHandler;
15import javax.security.auth.callback.NameCallback;
16import javax.security.auth.callback.PasswordCallback;
17
18public class DFCallbackHandler implements CallbackHandler {
19    public void handle(Callback[] cb) {
20        try {
21            for (int i = 0; i < cb.length; i++){
22                if (cb[i] instanceof NameCallback){
23                    NameCallback nc = (NameCallback)cb[i];
24                    System.out.print(nc.getPrompt() + " ");
25                    System.out.flush();
26                    String name = new BufferedReader(new InputStreamReader(System.in)).readLine();
27                    nc.setName(name);
28                } else if (cb[i] instanceof PasswordCallback){
29                    PasswordCallback pc = (PasswordCallback)cb[i];
30                    System.out.print(pc.getPrompt() + " ");
31                    System.out.flush();
32                    String pw = new BufferedReader(new InputStreamReader(System.in)).readLine();
33                    pc.setPassword(pw.toCharArray());
34                    pw = null;
35                }
36            }
37        } catch (IOException ioe){
38            System.out.println("ioe = " + ioe);
39        }
40    }
41}