DomainFilter { public static List<IdentityProvider> getIdpsForEmailDomain(List<IdentityProvider> activeProviders, String email) { if (!StringUtils.hasText(email) || !email.contains("@")) { return EMPTY_LIST; } final String domain = email.substring(email.indexOf('@') + 1); return activeProviders.stream().filter(provider -> doesEmailDomainMatchProvider(provider, domain, true)).collect(Collectors.toList()); }  static List<IdentityProvider> filter(List<IdentityProvider> activeProviders, ClientDetails client, String email); static List<IdentityProvider> filter(List<IdentityProvider> activeProviders, ClientDetails client, String email, boolean useUaaFallback); static List<IdentityProvider> getIdpsForEmailDomain(List<IdentityProvider> activeProviders, String email);  }
@Test public void test_ipds_for_email_domain() { samlProvider1.getConfig().setEmailDomain(Collections.singletonList("test.org")); samlProvider2.getConfig().setEmailDomain(Collections.singletonList("test.org")); List<IdentityProvider> idpsForEmailDomain = filter.getIdpsForEmailDomain(activeProviders, "abc@test.org"); assertEquals(2, idpsForEmailDomain.size()); assertThat(idpsForEmailDomain, Matchers.containsInAnyOrder(samlProvider1, samlProvider2)); }
@Test public void test_idp_with_wildcard_for_email_domain() { samlProvider1.getConfig().setEmailDomain(Collections.singletonList("t*.org")); List<IdentityProvider> idpsForEmailDomain = filter.getIdpsForEmailDomain(activeProviders, "abc@test.org"); assertEquals(1, idpsForEmailDomain.size()); assertThat(idpsForEmailDomain, Matchers.containsInAnyOrder(samlProvider1)); }
@Test public void test_idp_with_no_matching_email_domain() { samlDef1.setEmailDomain(Collections.singletonList("example.org")); List<IdentityProvider> idpsForEmailDomain = filter.getIdpsForEmailDomain(activeProviders, "abc@test.org"); assertEquals(0, idpsForEmailDomain.size()); }