2013-04-08 39 views
1

做这样的连接,似乎工作,如果一切都确定了用户LDAP连接错误,让细节子错误代码

Properties props = new Properties(); 
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
props.setProperty(Context.PROVIDER_URL, someUrl); 
props.setProperty(Context.SECURITY_PRINCIPAL, commonName); 
props.setProperty(Context.SECURITY_CREDENTIALS, password); 

InitialLdapContext ctx = null; 
try { 
    ctx = new InitialLdapContext(props, null); 
    return true; 
} catch (javax.naming.AuthenticationException ex) { 
    ex.printStackTrace(); 
} catch (NamingException ex) { 
    logger.warn("LDAP NamingException looking for user - " + 
      username + ": " + ex.getMessage(), ex); 
} 
return false; 

但是,如果用户是无效的,我们只是得到这样一个错误: 的javax .naming.AuthenticationException:LDAP:错误代码49 它不会告诉无效通过与过期帐户之间的差异等

我读过,你可以尝试做一个重新连接,然后做getResponseControls()获得访问实际发生的详细错误,如:

Properties props = new Properties(); 
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); 
props.setProperty(Context.PROVIDER_URL, someUrl); 

InitialLdapContext ctx = null; 
try { 
    ctx = new InitialLdapContext(props, null); 
    // set the user/pass they entered 
    ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, commonName); 
    ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password); 
    Hashtable env = new Hashtable(); 
    ctx.reconnect(null); 
    return true; 
} catch (javax.naming.AuthenticationException ex) { 
    ex.printStackTrace(); 
    try { 
     Control[] controls = ctx.getResponseControls(); 
     if (controls == null) { 
      logger.debug("response controls = null", ex); 
     } else { 
      logger.debug("response controls = " + controls.toString(), ex); 
     } 
    } catch (NamingException ex1) { 
     logger.error("error decoding respponsecontrols", ex); 
    } 
    return false; 
} catch (NamingException ex) { 
    logger.warn("LDAP NamingException looking for user - " + 
      username + ": " + ex.getMessage(), ex); 
} 

但是当我这样做,控件是空的。

有人曾经成功做过这件事吗?

+0

的地方我看了有关使用重新连接()来获取访问CTX对象是:http://bb10.com/apache-directory-user/2011-11/msg00057.html但正如我所说,这确实似乎没有工作,因为ctx.getResponseControls()为空。期待任何人有任何想法。 – 2013-04-08 23:02:06

+0

你有没有找到解决这个问题的办法? – kukudas 2014-03-06 17:37:10

回答

0

许多目录服务器使用“无效凭证”(49)来表明该帐户存在问题,该帐户不存在或与身份验证有关。一般来说,最好不要指明一个账户不存在或被锁定(这也表明它的存在),因为攻击者会知道该账户存在。

+0

我同意我不会与最终用户输入用户/密码共享此信息。但我们需要它在我们的服务器上进行内部调试。 – 2013-04-08 20:52:29

+0

这些是我们正在寻找的代码:https://forums.oracle.com/forums/thread.jspa?threadID=1155616 – 2013-04-08 23:03:50