@Test(expected = WebApplicationException.class) public void when_multiple_templates_and_none_is_valid_then_throw_401() throws LdapException{ client = client("cn=${login},ou=notexisting", "cn=${login},ou=nothing, dc=example, dc=com"); String username = client.authenticate(new Auth(USER_NAME, USER_PASSWORD.toCharArray())); assertThat(username).isEqualTo(USER_NAME); }
@Override public String authenticate(final Auth auth){ for(String template : templates){ String userNameTemplate = convertTemplate(template, auth.getUserName()); LdapConfig config = new LdapConfig(url, userNameTemplate, auth.getPassword()); if(tryAuthenticate(config)){ return auth.getUserName(); } } throw new NotAuthorizedException(); }
SimpleLdapClient implements LdapClient { @Override public String authenticate(final Auth auth){ for(String template : templates){ String userNameTemplate = convertTemplate(template, auth.getUserName()); LdapConfig config = new LdapConfig(url, userNameTemplate, auth.getPassword()); if(tryAuthenticate(config)){ return auth.getUserName(); } } throw new NotAuthorizedException(); } }
SimpleLdapClient implements LdapClient { @Override public String authenticate(final Auth auth){ for(String template : templates){ String userNameTemplate = convertTemplate(template, auth.getUserName()); LdapConfig config = new LdapConfig(url, userNameTemplate, auth.getPassword()); if(tryAuthenticate(config)){ return auth.getUserName(); } } throw new NotAuthorizedException(); } SimpleLdapClient(final List<String> templates, final String url); }
SimpleLdapClient implements LdapClient { @Override public String authenticate(final Auth auth){ for(String template : templates){ String userNameTemplate = convertTemplate(template, auth.getUserName()); LdapConfig config = new LdapConfig(url, userNameTemplate, auth.getPassword()); if(tryAuthenticate(config)){ return auth.getUserName(); } } throw new NotAuthorizedException(); } SimpleLdapClient(final List<String> templates, final String url); @Override String authenticate(final Auth auth); }
SimpleLdapClient implements LdapClient { @Override public String authenticate(final Auth auth){ for(String template : templates){ String userNameTemplate = convertTemplate(template, auth.getUserName()); LdapConfig config = new LdapConfig(url, userNameTemplate, auth.getPassword()); if(tryAuthenticate(config)){ return auth.getUserName(); } } throw new NotAuthorizedException(); } SimpleLdapClient(final List<String> templates, final String url); @Override String authenticate(final Auth auth);  }