2014-04-25 3 views
2

AD에서 모든 사용자를 나열하도록 LDAP 연결을 설정하려고합니다. 나는 성공적 정보와 함께이는 XML스프링 LDAP, 자바에서 연결 세부 설정

<ldap:context-source 
url="ldap://<url>" 
base="dc=example,dc=local" 
username="<user>@example.local" 
password="<pass>" /> 

에 저장 수행하지만 내가 어떻게이 정보 자바에서가 아니라 XML에 설정할 수 있습니다? 내가 NullPointerExeption을 얻을

LdapContextSource ctxSrc = new LdapContextSource(); 
    ctxSrc.setUrl("ldap://<url>"); 
    ctxSrc.setBase("dc=example,dc=local"); 
    ctxSrc.setUserDn("<user>@example.local"); 
    ctxSrc.setPassword("<pass>"); 
LdapTemplate tmpl = new LdapTemplate(ctxSrc); 
setLdapTemplate(tmpl); 

그러나

List users = (List<User>) ldapTemplate.search(LdapUtils.emptyLdapName(), "(&(objectCategory=person)(objectClass=user))", new UserAttributesMapper());

을들이받은 : 함께했습니다. 자바에서 속성을 설정하지 않고 (즉, XML에서 읽기) 있음을들이받은 모든

+0

당신이 예외 스택 추적을 추가 할 수 보시기 바랍니다 잘 작동? – bhdrk

+0

스택 트랜스로 포스트 업데이트 – Alchnemesis

답변

6

LdapContextSource ctxSrc = new LdapContextSource(); 
    ctxSrc.setUrl("ldap://<url>"); 
    ctxSrc.setBase("dc=example,dc=local"); 
    ctxSrc.setUserDn("<user>@example.local"); 
    ctxSrc.setPassword("<pass>"); 

ctxSrc.afterPropertiesSet(); // this method should be called. 

LdapTemplate tmpl = new LdapTemplate(ctxSrc); 
setLdapTemplate(tmpl); 
+1

thats it! ctxSrc.afterPropertiesSet(); LdapContextSource에서 호출해야했기 때문에 템플릿에서 호출했습니다 :) 감사합니다! – Alchnemesis