Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Test LDAP connection using standalone Java application - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Test LDAP connection using standalone Java application
KB0855232

Test LDAP connection using standalone Java application


5740 Views Last updated : Jan 3, 2025 public Copy Permalink
KB Summary by Now Assist

Summary

One of the types cases that is frequently assigned to CS-Integrations deal with LDAP connectivity issues.  This type of issue occurs when the ServiceNow instance is not able to connect to the customer’s LDAP server.

One of the best things a TSE should determine is if this is an issue on the ServiceNow side or the customer’s LDAP server side.  The best method to answer this question is to attempt to connect to the customer’s LDAP server using a 3rd party tool from a network outside of ServiceNow.  If the test is successful, then the issue is most likely on the ServiceNow side.  However, if the test fails, then the issue is most likely on the customer’s side.

A popular 3rd party tool that is already installed in all of the ServiceNow servers is ‘ldapsearch’.  I am not going to explain how to use the ‘ldapsearch’ tool here, for information on this tool see Knowledge Base article KB0549836 titled ‘Using ldapsearch to test an LDAP server’.  If ‘ldapsearch’ is not a valid option, then the customer can also compile and run the following Java application to test their LDAP connection.

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;

public class TestLdapConnection {
     public static void main(String[] args) {
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL,"ldap://10.11.110.110:636");
          try {
               //bind to the domain controller
               LdapContext ctx = new InitialLdapContext(env,null);
               ctx = new InitialLdapContext(env, null);
               System.out.println("LDAP Connection Successful");
               System.exit(0);
          } catch (NamingException e) {
               System.err.println("LDAP Notifications failure. " + e);
               System.exit(1);
          }

      }
}

Instructions

Use these instructions to compile and run the application.  Note, that I am assuming that the customer already has a JVM installed.

  1. copy and paste the code into a file named TestLdapConnection.java
  2. update the following line to have it point to their ldap server: env.put(Context.PROVIDER_URL,"ldap://192.168.2.129:636");
  3. compile with: javac TestLdapConnection.java
  4. run with: java TestLdapConnection

You may also run the application using the -Djavax.net.debug=all to get network debug information.


The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.