title: Unable to authenticate using LDAP authentication in IBM Worklight
body: <p>I am developing a mobile application with IBM Worklight and I have some issues with the authentication. I am using a custom authenticator and a custom login module for validating the user credentials against a Tivoli directory server.</p>
  
  <p>This is the code I am using, it works when I run it like a java application (class with a main method) in Worklight Studio, but when I run it like a Worklight application (in the login function of my custom login module) it returns a naming exception and prints jndi.20</p>
  
  <pre><code>public boolean login(Map&lt;String, Object&gt; authenticationData) {
      logger.info("SmaciLoginModule :: login");
  
      try{
          USERNAME = (String) authenticationData.get("username");
          PASSWORD = (String) authenticationData.get("password");
          String solicuser="uid="+USERNAME+",cn=users,dc=smaci,dc=ibm";
          Hashtable&lt;String, String&gt; env = new Hashtable&lt;String, String&gt;();
          env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, "ldap://127.0.0.1:1389/");
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          env.put(Context.SECURITY_PRINCIPAL, solicuser);
          env.put(Context.SECURITY_CREDENTIALS, PASSWORD);
          DirContext ctx = new InitialDirContext(env);
          boolean result = ctx != null;
  
                  if(ctx != null)
                      ctx.close();
  
              return result;
  
          }catch (Exception e) {
              throw new RuntimeException("Invalid credentials"+e.getMessage());
          }
  }
  </code></pre>
  
  <p>I hope that you can help me with my problem. I don't have experience working with LDAP, I appreciate any suggestion.
  Thank you!</p>