What's the best way to ping an LDAP server?
What's the best way to ping an LDAP server?
What exactly do you mean by "ping". Do you plan to perform a (command line) tool for this task?
Or do you want to check availability of the LDAP server programmatically? And if so, which with library (I assume Spring LDAP).
In any case, it depends how your LDAP server is configured. If it is allowed to perform anonymous search requests (quite often the case), you can simply do this. If you provide some information (e.g. type of you LDAP server), I'll add some sample code.
Greetings from Hamburg,
Stefan
---8<---
Stefan Zoerner (szoerner(at)apache.org)
Committer :: PMC Member
Apache Directory Project
http://directory.apache.org
Stefan Zoerner
Apache Directory Project
Committer :: PMC Member
Hello, Stefan;
Within Spring LDAP, I'd like to (programmatically) be able to ensure that the active directory domain server is "live" before I commit my application to attempt further utilization. This would also allow me to obtain a new IP address (from the administrators) if the higher ups decide to change it (they sometimes change the DNS name and IP address).
I do not have a DNS server available and have to hard-code the IP address.
If the IP address suddenly goes dead, I have to make manual changes.
The "ping" would alert me to make the changes rather than have users contacting the HELP DESK because my application appears non-responsive.
Given an IP and USERDN, I'd like to "ping" the server...
Thanks!
-Larry
Hi Larry,
In fact there are many options. I would recommend to perform a simple search. If your connection is configured as a bean like this
you may perform something like this:Code:... <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource"> <property name="url" value="ldap://localhost:389" /> <property name="base" value="dc=example,dc=com" /> <property name="userDn" value="cn=Manager" /> <property name="password" value="secret" /> </bean> ...
It will raise a connection refused exception, if the LDAP server is not listening.Code:import javax.naming.directory.Attributes; import javax.naming.directory.DirContext; import org.springframework.ldap.core.ContextSource; ... ApplicationContext spring = new ClassPathXmlApplicationContext("beans.xml"); ContextSource contextSource = (ContextSource) spring.getBean("contextSource"); DirContext ctx = contextSource.getReadOnlyContext(); Attributes attrs = ctx.getAttributes(""); ...
Other Options would include a bind with user DN and password in the Java source instead of the XML configuration, I recommend to use an anonymous bind if possible, although most Active Directory implementations does not allow that.
Please let me know if it does not work, or if you have further questions.
Greetings from Hamburg,
Stefan
Stefan Zoerner
Apache Directory Project
Committer :: PMC Member
Stefan,
...I just noticed that I never thanked you for your replies.
THANKS!!!
-Larry![]()