klyall / ad-authenticator

Java library to authenticate against Active Directory and retrieve the user's details.
GNU Lesser General Public License v3.0
2 stars 3 forks source link

Aduser null #3

Closed ancgate closed 6 years ago

ancgate commented 8 years ago

When I add the method addSearchObject to the authenticator, adUser is null even if I make the affection.

ADAuthenticator authenticator = ADAuthenticatorFactory.newInstance("MERQURY.COM"); String searchObject="OU=BOARD,DC=MERQURY,DC=COM"; authenticator.addSearchObject(searchObject); boolean authenticated = authenticator.authenticate("pmurphy", "password"); ADUser adUser = authenticator.retrieveLoggedInUser();

    if (authenticated) {

        System.out.println("Authentification");
        System.out.print(adUser.getFirstName()+ "\n");
        System.out.print(adUser.getLastName()+ "\n");
        System.out.print(adUser.getEmail()+ "\n");
        System.out.print(adUser.getDisplayName() + "\n");
        System.out.print(adUser.getSamAccountName()+ "\n");
        System.out.print(adUser.getUserPrincipleName()+ "\n");
        System.out.print(adUser.getGroups()+ "\n");

    } else {

        System.out.println("Authentification Invalide : Username ou Mot de passe incorrect");
    }

}
klyall commented 8 years ago

Hi.

Have you tried allowing it to discover the domain itself using ADAuthenticatorFactory.newInstance()?

If you have the library in DEBUG mode you should see what it discovers.

I would also try and get a connection without calling addSearchObject() first to see if that will work. The addSearchObject method is ideally used to just improve performance.

ancgate commented 8 years ago

Hi, thank you for the reply.

Yes, I tried allowing it to discover the domain itself using ADAuthenticatorFactory.newInstance() and it works perfectly. I got all the information of adUser. It works also when I put the domain name. I also got all the information of adUser. And I did all the this without calling addSearchObject(). The only problem I have is that it takes more than 30s to return the results. That is why I used the addsearchObject to improve performance. The authentication is faster however the method authenticator.retrieveLoggedInUser() return null. This is my problem. I wanted to know what did I missed knowing I want to improve the performance.