我们有一个小型 LAN,每个用户都通过 Active Directory 服务器登录 Windows。我希望能够以同样的方式从 Java 代码验证用户。我是通过以下方式执行此操作的:
Hashtable <String, String> env = new Hashtable <>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.0.1:389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "user1");
env.put(Context.SECURITY_CREDENTIALS, "pass1"));
env.put(Context.REFERRAL, "ignore");
try {
new InitialDirContext(env).close();
return true;
} catch (AuthenticationException ex) {
return false;
}
用户凭证的位置user1
和位置。pass1
在本地管理员通过为每个用户明确设置允许的工作站列表来限制访问之前,这一直很好。现在用户仍然可以登录 Windows,但我的代码(在允许的工作站上执行)产生
javax.naming.AuthenticationException: [LDAP: error code 49 - ...:
LdapErr: ...,
comment: AcceptSecurityContext error,
data 531,
...]
所以问题是:当设置了用户允许的工作站时,我应该如何在 LDAP 服务器上对用户进行身份验证?我应该以某种方式将当前工作站传递给 LDAP 服务器还是什么?