0

my problem is that I had to deploy an application onto a linux server. The authentication is based on a remote active directory. Everything was working fine, but since i have deployed onto the linux server, my authentication no longer works.

This is my authentication code:

public boolean connectUser(String login, String password) {



    Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, HOST);

    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, login+"@nazoos.com");
    env.put(Context.SECURITY_CREDENTIALS, password);

    // Create the initial context
    try {
        DirContext ctx = new InitialDirContext(env);
        Log.getLogger().debug("UserService : Connexion ==> OK ");
        return true;

    } catch (NamingException e) {

        Log.getLogger().debug("UserService : Erreur Connexion :"+e.getMessage());
        return false;

    }


}

This is the error that i have

Caused by: java.net.UnknownHostException: nazoos.com
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at java.net.Socket.<init>(Socket.java:425)
    at java.net.Socket.<init>(Socket.java:208)
    at com.sun.jndi.ldap.Connection.createSocket(Connection.java:368)
    at com.sun.jndi.ldap.Connection.<init>(Connection.java:203)
    ... 54 more

I have searched a lot, but I couldn't find anything.

3
  • Do you get an error message? Commented Mar 10, 2015 at 15:58
  • @JanTheGun ,i edited my post to add the error message with printStackTrace. Commented Mar 10, 2015 at 16:48
  • This is just a DNS failure. Your Linux machine is probably using it's own DNS which has it's ideas about what the proper names for machines are. There is probably a proper hostname for the specific domain controller you want to authenticate against. But using LDAP for authentication in general is not recommended. Jespa is currently the best way to authenticate web clients against AD in a Java application. And it has it's own DNS implementation so it will be very good at finding domain controllers and properly failing over to a different server and so on. Commented Apr 8, 2015 at 14:11

1 Answer 1

1
  1. HOST variable should have format ldap://<IP_or_hostname>:389
  2. If you use hostname then you should check that it can be resolved to IP address from your linux server. Maybe you will need to add this hostname into the server hosts file.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.