1 package hero.client.test; 2 3 24 25 import javax.security.auth.callback.Callback ; 26 import javax.security.auth.callback.CallbackHandler ; 27 import javax.security.auth.callback.NameCallback ; 28 import javax.security.auth.callback.PasswordCallback ; 29 import javax.security.auth.callback.UnsupportedCallbackException ; 30 31 32 public class SimpleCallbackHandler implements CallbackHandler { 33 private String username; 34 private char[] password; 35 36 public SimpleCallbackHandler(String username, char[] password) 37 { 38 this.username = username; 39 this.password = password; 40 } 41 42 public void handle(Callback [] callbacks) throws 43 java.io.IOException , UnsupportedCallbackException 44 { 45 for (int i = 0; i < callbacks.length; i++) 46 { 47 if (callbacks[i] instanceof NameCallback ) 48 { 49 NameCallback nc = (NameCallback )callbacks[i]; 50 nc.setName(username); 51 } 52 else if (callbacks[i] instanceof PasswordCallback ) 53 { 54 PasswordCallback pc = (PasswordCallback )callbacks[i]; 55 pc.setPassword(password); 56 } 57 61 } 62 } 63 } 64 | Popular Tags |