code: public Principal authenticate(String username, char password[]) 
      throws NamingException
  	{
  		DirContext ctx = null;
  		try
  		{
  			String userDN = toDN(username);
  			ctx = initContext(userDN, password);
  
  			return new X500Principal(userDN);
  		}
  		finally
  		{
  			if(ctx != null)
  				try{ ctx.close(); } catch(Exception e){e.printStackTrace();}
  		}
  	}
docs: -----------------------------------------------