Hello,
I have some problem with my first LDAP prototype.
An (external) LDAP server works well und connecting / browsing via Jxplorer is no problem.
I try a simple search/query in a java application.
First of all I set up a new context:
(It should be a very simple application.. up to now, I do not need a xml configuration file..)Code:LdapContextSource ctx = new LdapContextSource(); ctx.setUrl(url); ctx.setUserDn(userDn); ctx.setPassword(password); ctx.setBase(base); ctx.setPooled(pooled);
For a comfortable search, I want to use LdapTemplate.
For a simple test, I copied a code from http://static.springsource.org/sprin...roduction.htmlCode:ldapTemplate = new LdapTemplate(ctx);
If I try to execute the code, I get a Exception:Code:public static List getAllPersonNames() { return ldapTemplate.search( base, "(objectclass=person)", new AttributesMapper() { public Object mapFromAttributes(Attributes attrs) throws NamingException { return attrs.get("cn").get(); } }); }
I need help.. what else I have to configurate for a simple query?Exception in thread "main" java.lang.NullPointerException
at org.springframework.ldap.core.support.AbstractCont extSource.getReadOnlyContext(AbstractContextSource .java:125)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:287)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:259)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:571)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:556)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:411)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:431)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:451)
...
Edit:
Some additional information:
This is AbstractContextSource.getReadOnlyContext(AbstractC ontextSource.java:125).Code:public DirContext getReadOnlyContext() { if (!anonymousReadOnly) { return getContext(authenticationSource.getPrincipal(), authenticationSource.getCredentials()); } else { return createContext(getAnonymousEnv()); } }
The exception occurs, because the authenticationSource is null. I do not understand why: all needed information are present in the LdapContextSource, aren't they?
If I make a new authenticationSource I just get another exception.:
New exceptionCode:ctx.setAuthenticationSource(new AuthenticationSource() { @Override public String getPrincipal() { // TODO Auto-generated method stub return userDn; } @Override public String getCredentials() { // TODO Auto-generated method stub return password; } });
atException in thread "main" java.lang.NullPointerException
at java.util.Hashtable.<init>(Unknown Source)
at org.springframework.ldap.core.support.AbstractCont extSource.getAuthenticatedEnv(AbstractContextSourc e.java:480)
at org.springframework.ldap.core.support.AbstractCont extSource.getContext(AbstractContextSource.java:10 6)
at org.springframework.ldap.core.support.AbstractCont extSource.getReadOnlyContext(AbstractContextSource .java:125)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:287)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:259)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:571)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:556)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:411)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:431)
at org.springframework.ldap.core.LdapTemplate.search( LdapTemplate.java:451)
..
Code:Hashtable env = new Hashtable(getAnonymousEnv());
I just want to connect to the ldap server and run simple queries. It seems I missed something. Could someone give me some hints?


Reply With Quote
