DomainFilter { public static List<IdentityProvider> filter(List<IdentityProvider> activeProviders, ClientDetails client, String email) { return filter(activeProviders, client, email, true); }  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_null_arguments() { assertThat(filter.filter(null,null,null), Matchers.containsInAnyOrder()); assertThat(filter.filter(null,null,email), Matchers.containsInAnyOrder()); assertThat(filter.filter(null,client,null), Matchers.containsInAnyOrder()); assertThat(filter.filter(null,client,email), Matchers.containsInAnyOrder()); assertThat(filter.filter(activeProviders,null,null), Matchers.containsInAnyOrder()); assertThat(filter.filter(activeProviders,client,null), Matchers.containsInAnyOrder()); assertThat(filter.filter(activeProviders,client,email), Matchers.containsInAnyOrder(uaaProvider)); }
@Test public void test_default_idp_and_client_setup() { assertThat(filter.filter(activeProviders,null,email), Matchers.containsInAnyOrder(uaaProvider)); assertThat(filter.filter(activeProviders,client,email), Matchers.containsInAnyOrder(uaaProvider)); assertThat(filter.filter(Collections.singletonList(ldapProvider),null,email), Matchers.containsInAnyOrder()); assertThat(filter.filter(Collections.singletonList(ldapProvider),client,email), Matchers.containsInAnyOrder()); assertThat(filter.filter(Arrays.asList(uaaProvider, samlProvider2),null,email), Matchers.containsInAnyOrder(uaaProvider)); assertThat(filter.filter(Arrays.asList(uaaProvider, samlProvider2),client,email), Matchers.containsInAnyOrder(uaaProvider)); assertThat(filter.filter(Collections.singletonList(uaaProvider), null, email), Matchers.containsInAnyOrder(uaaProvider)); assertThat(filter.filter(Collections.singletonList(uaaProvider),client,email), Matchers.containsInAnyOrder(uaaProvider)); }
@Test public void test_no_allowed_client_providers() { client.addAdditionalInformation(ALLOWED_PROVIDERS, EMPTY_LIST); assertThat(filter.filter(activeProviders,client,email), Matchers.containsInAnyOrder()); }
@Test public void test_single_positive_email_domain_match() { uaaDef.setEmailDomain(null); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(EMPTY_LIST); ldapDef.setEmailDomain(Collections.singletonList("test.org")); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(ldapProvider)); assertThat(filter.filter(activeProviders, client, "some@other.domain"), Matchers.containsInAnyOrder(uaaProvider)); }
@Test public void test_multiple_positive_email_domain_matches() { uaaDef.setEmailDomain(null); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(Arrays.asList("test.org","test2.org")); ldapDef.setEmailDomain(Collections.singletonList("test.org")); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(ldapProvider, samlProvider2)); }
@Test public void test_multiple_positive_email_domain_matches_wildcard() { uaaDef.setEmailDomain(null); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(Collections.singletonList("*.org")); ldapDef.setEmailDomain(Collections.singletonList("*.org")); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(ldapProvider, samlProvider2)); }
@Test public void test_multiple_positive_long_email_domain_matches_wildcard() { uaaDef.setEmailDomain(null); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(Collections.singletonList("*.*.*.com")); ldapDef.setEmailDomain(Collections.singletonList("*.*.test2.com")); configureTestData(); assertThat(filter.filter(activeProviders, client, "user@test.test1.test2.com"), Matchers.containsInAnyOrder(ldapProvider, samlProvider2)); }
@Test public void test_multiple_positive_email_domain_matches_single_client_allowed_provider() { uaaDef.setEmailDomain(null); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(Arrays.asList("test.org","test2.org")); ldapDef.setEmailDomain(Collections.singletonList("test.org")); client.addAdditionalInformation(ALLOWED_PROVIDERS, Collections.singletonList(samlProvider2.getOriginKey())); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(samlProvider2)); client.addAdditionalInformation(ALLOWED_PROVIDERS, Arrays.asList(samlProvider2.getOriginKey(), samlProvider1.getOriginKey())); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(samlProvider2)); client.addAdditionalInformation(ALLOWED_PROVIDERS, Collections.singletonList(samlProvider1.getOriginKey())); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder()); }
@Test public void test_single_client_allowed_provider() { client.addAdditionalInformation(ALLOWED_PROVIDERS, Collections.singletonList(ldapProvider.getOriginKey())); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder()); ldapDef.setEmailDomain(Collections.singletonList("test.org")); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(ldapProvider)); }
@Test public void test_multiple_client_allowed_providers() { client.addAdditionalInformation(ALLOWED_PROVIDERS, Arrays.asList(ldapProvider.getOriginKey(), uaaProvider.getOriginKey())); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(uaaProvider)); client.addAdditionalInformation(ALLOWED_PROVIDERS, Arrays.asList(ldapProvider.getOriginKey(), samlProvider2.getOriginKey())); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder()); ldapDef.setEmailDomain(Collections.singletonList("test.org")); configureTestData(); client.addAdditionalInformation(ALLOWED_PROVIDERS, Arrays.asList(ldapProvider.getOriginKey(), uaaProvider.getOriginKey())); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(ldapProvider)); }
@Test public void test_uaa_is_catch_all() { ldapDef.setEmailDomain(EMPTY_LIST); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(EMPTY_LIST); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(uaaProvider)); }
@Test public void test_uaa_is_not_catch_all_without_fallback() { ldapDef.setEmailDomain(EMPTY_LIST); samlDef1.setEmailDomain(EMPTY_LIST); samlDef2.setEmailDomain(EMPTY_LIST); configureTestData(); assertThat(filter.filter(activeProviders, client, email, false), not(Matchers.containsInAnyOrder(uaaProvider))); }
@Test public void test_uaa_is_catch_all_with_null_email_domain_list() { ldapDef.setEmailDomain(null); samlDef1.setEmailDomain(null); samlDef2.setEmailDomain(null); configureTestData(); assertThat(filter.filter(activeProviders, client, email), Matchers.containsInAnyOrder(uaaProvider)); }