private Authentication authenticateUserPassword(UsernamePasswordAuthenticationToken token) throws NamingException {
Object login = login(token);
LOGGER.debug("Starting authentication login='{}'", login);
Object password = token.getCredentials();
LdapContext ctx = createLdapCtx(login, password);
SearchControls ctrls = createSearchControls();
String filter = String.format(this.filter, login);
NamingEnumeration<SearchResult> ne = ctx.search(dn, filter, ctrls);
....
我有以下方法登录用户。这取决于LDAP。有时它挂在最后一行。我不知道为什么。它有时在性能测试中重现。在Ldap搜索设置方法超时
是否有办法等待一段时间,如果方法没有响应 - 返回一些预定义的值?
P.S.
private LdapContext createLdapCtx(Object login, Object password) throws NamingException {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(Context.INITIAL_CONTEXT_FACTORY, factory);
props.put(Context.PROVIDER_URL, url);
props.put(Context.SECURITY_AUTHENTICATION, "simple");
props.put(Context.SECURITY_PRINCIPAL, String.format(domain, login));
props.put(Context.SECURITY_CREDENTIALS, password.toString());
return new InitialLdapContext(props, null);
}
@RealSkeptic和Tunaki请澄清差异 – gstackoverflow
@gstackoverflow这可能不完全正确(我不确定所有的贪婪细节),但'setTimeLimit'不用于搜索操作(我不确定为什么) – Tunaki
NamingException是常见的ldap异常。我没有检查,但我认为TimeLimitExceededException将被抛出 – gstackoverflow