通过java.namming包实现LDAP用户登录认证,怎么区分账号被冻结、停用、不存在等异常的业务情况呢?
参考的是:网上普遍流传的LDAP连接的代码
public boolean auth(String username, String password) {
//设置相关常量
String initialContextFactory ="com.sun.jndi.ldap.LdapCtxFactory";
String ad4ProviderURL ="ldap://ip:port";
String securityAuthentication ="simple";
String domain ="ad4";
if (!username.startsWith(domain)) {
username = domain+"\"+ username;
}
/*
* 组织参数集合
*/
Hashtable env = new Hashtable();
//set the initializing information of the context
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, initialContextFactory);
//set the URL of ldap server
env.put(javax.naming.Context.PROVIDER_URL, ad4ProviderURL);
//set the authentication mode
<