code: public static boolean isAuthenticed(String host, int port, String userName, String password) throws NamingException {
  		log.info("isAuthenticed");
  		// Set up the environment for creating the initial context
  		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 + ":" + port);
  		env.put(Context.SECURITY_AUTHENTICATION, "simple");
  		env.put(Context.SECURITY_PRINCIPAL, userName + "@" + host);
  		log.info(env.toString());
  		env.put(Context.SECURITY_CREDENTIALS, password);
  		// Create the initial context
  		DirContext ctx = new InitialDirContext(env);
  		log.info("DirContext Init Succ");
  		boolean result = ctx != null;
  		if (ctx != null) {
  			log.info("Closing DirContext");
  			ctx.close();
  		}
  		return result;
  	}
docs: Checks if is authenticed.
  
  @param host     the host
  @param port     the port
  @param userName the user name
  @param password the password
  @return true, if is authenticed
  @throws NamingException the naming exception