我已经设置了AD 2016安装。现在打算将其用于web应用程序(Java)的身份验证。我有一段用于测试身份验证的代码,并有一些观察结果。
public static void main(String[] args)
{
String userid="userhere",password="passwordhere";
LdapContextCreation ldapContxCrtn = new LdapContextCreation();
LdapContext ctx = ldapContxCrtn.getLdapContext(userid,password);
if(ctx==null)
{System.out.println("Authentication Failed.");}
else
{System.out.println("Authentication Successful.");}
}
public LdapContext getLdapContext(String base, String password)
{
LdapContext ctx = null;
try
{
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
env.put(Context.SECURITY_PRINCIPAL, base);
env.put(Context.SECURITY_CREDENTIALS, password);
env.put(Context.PROVIDER_URL, "ldaps://mydomaincontroller:636");
ctx = new InitialLdapContext(env, null);
}
catch(NamingException nex)
{
//nex.printStackTrace();
}现在,我在以下场景中测试了用户/密码组合:
//第一个组合,AD中存在user1且密码正确(测试鉴权绑定)String userid="user1@domain.com",password="user1password";期望:鉴权成功。Actual:鉴权成功。这对我来说是很清楚的。对于不正确的密码,它会响应正确的消息-身份验证失败。
//第二个组合,AD中存在user2,但我们尝试发送的密码为空(测试未验证的绑定)字符串userid="user2@domain.com",password="";预期:验证失败。Actual:鉴权成功。如何处理这种情况-我可以在AD中控制这一点,还是必须在代码中处理?
//第三种组合,AD中不存在user3 (测试不存在用户) String userid="user3@domain.com",password=“somepassword”,预期:鉴权失败。Actual:鉴权成功。如何处理这种情况?用户并不存在--甚至不存在。这是AD配置错误吗?
//第四种组合,用户名和密码为空(匿名绑定测试)字符串userid="",password="";预期:鉴权失败。Actual:鉴权成功。如何处理这种情况-我可以在AD中控制这一点,还是必须在代码中处理?
发布于 2019-01-06 09:25:25
您看到的是一个“未经身份验证的绑定”,在LDAP RFC 4513 section 5.1.2中进行了详细介绍,并对section 6.3.1中的后续安全注意事项进行了说明。
最好在代码中处理此问题(即,在与目录服务器通信之前,验证用户名和密码都不为空)。在Windows2019中添加了一个禁止未经验证的绑定操作的设置--在你的配置分区中,打开CN=Directory Service, CN=Windows NT, CN=Services, CN=Configuration的属性--找到msDS-其他-设置属性,然后添加一个新的条目DenyUnauthenticatedBind=1,但是除非你正在编写一个只会与你拥有的活动目录一起使用的一次性应用程序,否则不能安全地假设其他活动目录已经以这种方式进行了配置。
https://stackoverflow.com/questions/54021767
复制相似问题