javax.naming.AuthenticationException

srikotesh
srikotesh used Ask the Experts™
on
Hi Expets,

I am trying to connect ldap active directory path

Exception:
==========

Exception in thread "main" javax.naming.AuthenticationException:
 [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903CF,
 comment: AcceptSecurityContext error, data 52e, v2580

PLEASE FINE THE BELOW CODE AND SUGGEST WHAT IS WRONG IN MY CODE


public class AdSearchExample {
    
    /**
     * @param args
     * @return
     * @throws NamingException
     */
    public static InitialDirContext getDirContext() throws NamingException {
        Hashtable<String, String> env = new Hashtable<String, String>();        
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");      
        env.put(Context.PROVIDER_URL,"ldap://host:portno/");
        env.put(Context.REFERRAL, "follow");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        env.put(Context.SECURITY_PRINCIPAL, "CN=SRI RAO,OU=PRAC,OU=Users,OU=MindTree Bangalore,OU=Asia Pacific,DC=mindtree,DC=com");
        env.put(Context.SECURITY_CREDENTIALS, "welocome@123");
        System.out.println("env" +env);
        return new InitialDirContext(env);       
    }
    
    public static void main(String args[]) throws NamingException{

        DirContext context = getDirContext();

}

}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
        env.put(Context.SECURITY_CREDENTIALS, "welocome@123");

Open in new window


are you sure that's not meant to be this?

        env.put(Context.SECURITY_CREDENTIALS, "welcome@123");

Open in new window

I HAVE TRIED BELOW LINK ITS WORKING FINE
http://www.codeproject.com/Articles/653337/Java-Retrieving-User-Informatio

THIS LINE WILL BE THE ISSUE I GUESS
env.put(Context.SECURITY_PRINCIPAL, user);

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial