简体   繁体   中英

Java - Access to remote active directory with linux

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.

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM