key words: HttpClient LDAP LDAP驗證
LDAP目前應(yīng)用得非常廣泛,在企業(yè)環(huán)境里可以供各種應(yīng)用統(tǒng)一用戶驗證數(shù)據(jù)。
以下是一個客戶端在正常訪問的時候插入驗證代碼,將用戶提交的用戶名和密碼提交給ldap驗證
HttpClient?hc?=?new?HttpClient();
????????????GetMethod?method?=?new?GetMethod("http://www.yoursite.com/auth/your_auth.html");
????????????String?inputUserName?=?JOptionPane.showInputDialog("Input?your?User?Name:");
????????????String?inputPassWord?=?JOptionPane.showInputDialog("Input?your?password:");
????????????UsernamePasswordCredentials?upc?=?new?UsernamePasswordCredentials(inputUserName,?inputPassWord);
????????????hc.getState().setCredentials(null,?null,?upc);
????????????int?status?=?hc.executeMethod(method);
????????????method.releaseConnection();
????????????if(status?==?200)
????????????{
????????????????System.out.println("login?successful!");
??????????????? //do your business things
????????????}?else
????????????{
????????????????System.out.println("Login?failed!??Please?check?your?userName?and?Password!");
????????????}
http://www.yoursite.com/auth/your_auth.html如果直接訪問會彈出對話框讓你輸入用戶名密碼