@Test(expected = WebApplicationException.class) public void when_query_returns_result_but_password_is_wrong_then_throw_WAE() throws LdapException{ addUser(USER_NAME, USER_PASSWORD, ""); client = client(QUERY, "ou=system"); client.authenticate(new Auth(USER_NAME, "wrongPassword".toCharArray())); }
@Override public String authenticate(final Auth auth) { try{ final LdapConfig config = new LdapConfig(url, adminDn, adminPassword); final DirContext context = new InitialDirContext(config); List<String> usersDns = findAllUsersThatMatchQuery(context, auth); for(String userDn : usersDns) if(tryAuthenticate(context, userDn, auth.getPassword())) return auth.getUserName(); }catch(NamingException e){ throw new RuntimeException(e); } throw new NotAuthorizedException(); }
QueryLdapClient implements LdapClient { @Override public String authenticate(final Auth auth) { try{ final LdapConfig config = new LdapConfig(url, adminDn, adminPassword); final DirContext context = new InitialDirContext(config); List<String> usersDns = findAllUsersThatMatchQuery(context, auth); for(String userDn : usersDns) if(tryAuthenticate(context, userDn, auth.getPassword())) return auth.getUserName(); }catch(NamingException e){ throw new RuntimeException(e); } throw new NotAuthorizedException(); } }
QueryLdapClient implements LdapClient { @Override public String authenticate(final Auth auth) { try{ final LdapConfig config = new LdapConfig(url, adminDn, adminPassword); final DirContext context = new InitialDirContext(config); List<String> usersDns = findAllUsersThatMatchQuery(context, auth); for(String userDn : usersDns) if(tryAuthenticate(context, userDn, auth.getPassword())) return auth.getUserName(); }catch(NamingException e){ throw new RuntimeException(e); } throw new NotAuthorizedException(); } QueryLdapClient(String query, String queryDn, String url, String bindDn, char[] password); }
QueryLdapClient implements LdapClient { @Override public String authenticate(final Auth auth) { try{ final LdapConfig config = new LdapConfig(url, adminDn, adminPassword); final DirContext context = new InitialDirContext(config); List<String> usersDns = findAllUsersThatMatchQuery(context, auth); for(String userDn : usersDns) if(tryAuthenticate(context, userDn, auth.getPassword())) return auth.getUserName(); }catch(NamingException e){ throw new RuntimeException(e); } throw new NotAuthorizedException(); } QueryLdapClient(String query, String queryDn, String url, String bindDn, char[] password); @Override String authenticate(final Auth auth); }
QueryLdapClient implements LdapClient { @Override public String authenticate(final Auth auth) { try{ final LdapConfig config = new LdapConfig(url, adminDn, adminPassword); final DirContext context = new InitialDirContext(config); List<String> usersDns = findAllUsersThatMatchQuery(context, auth); for(String userDn : usersDns) if(tryAuthenticate(context, userDn, auth.getPassword())) return auth.getUserName(); }catch(NamingException e){ throw new RuntimeException(e); } throw new NotAuthorizedException(); } QueryLdapClient(String query, String queryDn, String url, String bindDn, char[] password); @Override String authenticate(final Auth auth);  }