簡體   English   中英

javax.naming.AuthenticationException:[LDAP:錯誤代碼49 - 證書無效]

[英]javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]

我是ldap的新手,我正在嘗試一下我認為是一個簡單的例子來測試一個有人已經設置用於測試的ldap實例的spring ldap模塊。

有關我正在使用的ldap實例的詳細信息,請訪問: http//blog.stuartlewis.com/2008/07/07/test-ldap-service/comment-page-3/

我使用了ldap瀏覽器/管理工具(Softerra LDAP Admin),我可以毫無問題地訪問該目錄。

當我使用java和spring-ldap(2.0.1)嘗試它時,我得到上面提到的身份驗證異常。 在設置我自己的ldap實例以嘗試進一步排除故障之前,我想檢查一下,以防有經驗的人可以指出我錯過的一些明顯的東西。

以下是我使用的代碼:

import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;

import java.util.List;

public class LdapTest {


public List<String> getListing() {

    LdapTemplate template = getTemplate();

    List<String> children = template.list("dc=testathon,dc=net");

   return children;
}


private LdapTemplate getTemplate(){

    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setUrl("ldap://ldap.testathon.net:389");
    contextSource.setUserDn("cn=john");
    contextSource.setPassword("john");

    try {
        contextSource.afterPropertiesSet();
    } catch (Exception ex) {
        ex.printStackTrace();
    }


    LdapTemplate template = new LdapTemplate();

    template.setContextSource(contextSource);

    return template;

}


public static void main(String[] args){


    LdapTest sClient = new LdapTest();
    List<String> children = sClient.getListing();

    for  (String child :children) {
        System.out.println(child);
    }

}

}

堆棧跟蹤:

Exception in thread "main" org.springframework.ldap.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - Invalid Credentials]
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:191)
at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:356)
at org.springframework.ldap.core.support.AbstractContextSource.doGetContext(AbstractContextSource.java:140)

事實證明,我只需要在可分辨名稱(包括組織單位)中包含所有內容。 運用

contextSource.setBase(...);

由於某種原因沒有奏效。 做出那次糾正之后一切都很好。

contextSource.setUserDn("cn=john,ou=Users,dc=testathon,dc=net");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM