key words: HttpClient LDAP LDAP验证
LDAP目前应用得非常广泛,在企业环境里可以供各种应用统一用户验证数据。
以下是一个客户端在正常访问的时候插入验证代码,将用户提交的用户名和密码提交给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如果直接访问会弹出对话框让你输入用户名密码