[英]Spring 2.5.6 JMX NotificationPublisher invocation throwing NPE
[英]Spring LDAP throwing a NPE
我正在使用以下代碼來使用Spring LDAP進行身份驗證。
public static void main(String[] args) {
String username = "kgam";
String password = "password";
LdapContextSource ctxSrc = new LdapContextSource();
ctxSrc.setUrl(URL);
ctxSrc.setBase(BASE);
ctxSrc.setUserDn(USERDN);
ctxSrc.setPassword(PASSWORD);
LdapTemplate ldapTemplate = new LdapTemplate(ctxSrc);
AndFilter filter = new AndFilter();
ldapTemplate.setIgnorePartialResultException(true);
filter.and(new EqualsFilter("objectClass", "person")).and(new EqualsFilter("sAMAccountName", username));
System.out.println(ldapTemplate.authenticate(BASE, filter.toString(), password));
}
它使用以下堆棧跟蹤引發NPE。
Exception in thread "main" java.lang.NullPointerException
at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:138)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:286)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:236)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:623)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:534)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:461)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:482)
at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:502)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1481)
at org.springframework.ldap.core.LdapTemplate.authenticate(LdapTemplate.java:1398)
at com.capitalone.dashboard.service.AuthenticationServiceImpl.main(AuthenticationServiceImpl.java:123)
關於我在哪里錯的任何想法嗎?
如果像您的示例一樣完全在沒有Spring幫助的情況下完全配置Spring LDAP,則在完成配置后,需要在ContextSource
上調用afterPropertiesSet
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.