我正在将LDAP身份验证添加到spring-boot应用程序。所有设置都相应,即使提供了正确的凭据,我也收到“ LDAP错误代码49 AcceptSecurityContext错误数据52e v2580”错误。
我正在使用import javax.naming.Context;
,并提到了以下代码。
String url = ldap_url;
String domain = ldap_domain;
String uname = request.getUsername();
String pwd = request.getPassword();
boolean authentication = false;
boolean error = true;
String msg;
String ldapSearchBase = "OU=TEST_OU, DC=DC2, DC=DC1";
// create env for initial context
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, url);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "CN=" + uname + "@" + domain + "," + ldapSearchBase);
env.put(Context.SECURITY_CREDENTIALS, pwd);
NamingEnumeration results = null;
try {
LdapContext ctx = new InitialLdapContext(env, null);
authentication = true;
error = false;
} catch (NamingException e) {
logger.error("LDAP error for :{NamingException}" + e);
return ResponseEntity.ok(new ApiResponse(true, e.getMessage()));
} finally {
if (!error) {
msg = "Login success!!!";
} else {
msg = "Authentication failed!";
}
}
logger.info("exitinig...");
if (authentication) {
return ResponseEntity.ok(new ApiResponse(false, msg));
} else {
return ResponseEntity.ok(new ApiResponse(true, msg));
}
错误捕获为NamingException
。
答案 0 :(得分:0)
带有LDAP错误code 49 ... data 52e的错误响应“当用户名有效时返回但密码/凭据无效。”。
可能存在基础设施问题,例如when the domain controller computer account may not be synchronized with the Key Distribution Center (KDC)。但是,当这种情况存在时,您可能还会遇到很多其他问题。
答案 1 :(得分:0)