java - 使用来自 AD 服务器的身份验证时出错

标签 java

package mypack;

import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;

public class ADCheck {
    public static void main(String[] args) {
        try {
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.PROVIDER_URL,"LDAP://myad.com:385"); 
            env.put(Context.SECURITY_AUTHENTICATION,"DIGEST-MD5"); 
            env.put(Context.SECURITY_PRINCIPAL,"MY_USER_NAME"); 
            env.put(Context.SECURITY_CREDENTIALS, "MY_PASSWORS");  
            DirContext ctx = new InitialDirContext(env);
            ctx.close();
        } catch(NamingException ne) {
            System.out.println("Error authenticating user:");
            System.out.println(ne.getMessage());
            return;
        }
        System.out.println("OK, successfully authenticating user");
    }
}

获取错误:

javax.naming.AuthenticationException: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C09043E, comment: AcceptSecurityContext error, data 0, vece.

请帮忙

最佳答案

https://www.fuzeqna.com/sonicwallkb/consumer/kbdetail.asp?kbid=5266

When testing authentication to an Active Directory server, you may see this error:

Authentication Error: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C09043E, comment: AcceptSecurityContext error, data 0, vece].

Resolution or Workaround:

This can occur if the Host Type in the Remote Domain configuration is incorrect. Change the Host Type to Active Directory (or vice versa):

同时检查 http://www.websina.com/bugzero/faq/ldap-error-code-49.html

A: This error is caused by the wrong setting of
java.naming.security.principal.

A full DN must be used here, something like:

CN=FName LName,OU=OrgUnit_the_user_stored_in,DC=Domain_name,DC=Domain_suffix

关于java - 使用来自 AD 服务器的身份验证时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16518570/

相关文章:

java - 有没有办法强制 Checkstyle 忽略源代码中的特定警告?

java - double 是计算小数百分比的正确数据类型吗?

java - 当我从 android 刷新时出现 Android TCP 错误 :onClick

java - 从键值对开始迭代 Java 中的 Map(特别是 TreeMap)

java - 如何在 Java 中将 8 位灰度位图转换为 4 位灰度位图?

java - 正则表达式 - 查找十六进制数的匹配项,不包括下一个十六进制数的 0

Java Stream优雅解决方案,避免多次循环

java - Spring 启动 : redirect from HTTP to HTTPS results in 405 error for PUT method

java - 如何创建带有类型参数的 java.lang.Class?

java - Rock Paper Scissors Game Best 2 out of 3 with Loops