### Question:
LdapLinkResource extends ResourceValue { public boolean simpleBind (String dn, String password) { Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, _uri); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put("java.naming.ldap.version", Integer.toString(LdapModule.LDAP_OPT_PROTOCOL_VERSION)); if (LdapModule.LDAP_OPT_REFERRALS == 1) { env.put(Context.REFERRAL, "follow"); } else { env.put(Context.REFERRAL, "ignore"); } if (dn.length() > 0) { if (password.length() == 0) { return false; } env.put(Context.SECURITY_PRINCIPAL, dn); env.put(Context.SECURITY_CREDENTIALS, password); } try { _ctx = new InitialDirContext(env); } catch (NamingException e) { return false; } return true; } LdapLinkResource(String uri); LdapResultResource search(String baseDN, String filter, List<String> attributes,
                                      int attrsOnly, long sizeLimit, int timeLimit, int deref,
                                      int scope); boolean simpleBind(String dn, String password); boolean unbind();  }### Answer:
@Test public void anonymousBind () { assertTrue("Trying anonymous bind", _connection.simpleBind("", "")); }
@Test public void passwordlessBind () { assertFalse("Binding with DN specified but empty password should fail", _connection.simpleBind("cn=john,dc=example,dc=com", "")); }
@Test public void authenticatedBind () { assertTrue("Binding with manager DN and password", _connection.simpleBind("cn=Manager,dc=example,dc=com", "secret")); }
@Test public void badPasswordBind () { assertFalse("Binding with manager DN and wrong password", _connection.simpleBind("cn=Manager,dc=example,dc=com", "s3kr1t")); }