1 29 30 package hero.client.importLdap; 31 32 53 54 import javax.security.auth.callback.Callback ; 55 import javax.security.auth.callback.CallbackHandler ; 56 import javax.security.auth.callback.NameCallback ; 57 import javax.security.auth.callback.PasswordCallback ; 58 import javax.security.auth.callback.UnsupportedCallbackException ; 59 60 61 public class SimpleCallbackHandler implements CallbackHandler { 62 private String username; 63 private char[] password; 64 65 public SimpleCallbackHandler(String username, char[] password) 66 { 67 this.username = username; 68 this.password = password; 69 } 70 71 public void handle(Callback [] callbacks) throws 72 java.io.IOException , UnsupportedCallbackException 73 { 74 for (int i = 0; i < callbacks.length; i++) 75 { 76 if (callbacks[i] instanceof NameCallback ) 77 { 78 NameCallback nc = (NameCallback )callbacks[i]; 79 nc.setName(username); 80 } 81 else if (callbacks[i] instanceof PasswordCallback ) 82 { 83 PasswordCallback pc = (PasswordCallback )callbacks[i]; 84 pc.setPassword(password); 85 } 86 90 } 91 } 92 } 93 | Popular Tags |