繁体   English   中英

LDAP验证问题

[英]LDAP Authentication Issue

我必须连接到LDAP,但是我无法使用Java代码进行连接,并且使用LDAPAdmin工具也可以连接。

String url = "ldap://host name:389";
ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");   
ldapEnv.put(Context.PROVIDER_URL,  url);   
ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
ldapEnv.put(Context.SECURITY_PRINCIPAL, "CN=username");
ldapEnv.put(Context.SECURITY_CREDENTIALS, "#1223");

错误

  Search error: javax.naming.AuthenticationException: [LDAP: error code 49 -
  80090308: LdapErr: DSID-0C0903CF, comment: AcceptSecurityContext error, data 52e, v2580

一旦看这个..这对我来说很好,这可能会帮助您。 谢谢..

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
public class LdapContextCreation {
    public static void main(String[] args) {
        LdapContextCreation ldapContxCrtn = new LdapContextCreation();
        LdapContext ctx = ldapContxCrtn.getLdapContext();
    }
        public LdapContext getLdapContext(){
            LdapContext ctx = null;
            Hashtable env = new Hashtable();
            env.put(Context.INITIAL_CONTEXT_FACTORY,  "com.sun.jndi.ldap.LdapCtxFactory");
            env.put(Context.SECURITY_AUTHENTICATION, "Simple");  
            env.put(Context.SECURITY_PRINCIPAL, "cn=company,dc=example,dc=com");         
            env.put(Context.SECURITY_CREDENTIALS, "pasword");          
            env.put(Context.PROVIDER_URL, "ldap://localhost:389"); 
            try{
            ctx = new InitialLdapContext(env, null);           
            System.out.println("Connection Successful.");  
            }catch(NamingException nex){       
                System.out.println("LDAP Connection: FAILED");      
                nex.printStackTrace();
                }      
            return ctx;
                }

        }

在这里查看错误代码-http: //www-01.ibm.com/support/docview.wss?uid=swg21290631

数据52e-根据链接,52e表示无效的凭据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM