IdentityProviderLinker implements EntityLinker<IdentityProvider> { @Override public void link(IdentityProvider entity, Bundle bundle, Bundle targetBundle) { if (entity.getType() != IdentityProviderType.FEDERATED) { return; } FederatedIdentityProviderDetail identityProviderDetail = (FederatedIdentityProviderDetail) entity.getIdentityProviderDetail(); if (identityProviderDetail != null) { Set<String> certIds = identityProviderDetail.getCertificateReferences(); Set<TrustedCert> trustedCerts = bundle.getEntities(TrustedCert.class).values() .stream() .filter(e -> certIds.contains(e.getId())) .collect(Collectors.toSet()); if (!trustedCerts.isEmpty()) { entity.setIdentityProviderDetail(new FederatedIdentityProviderDetail(trustedCerts.stream().map(TrustedCert::getName).collect(Collectors.toSet()))); } } }  @Override Class<IdentityProvider> getEntityClass(); @Override void link(IdentityProvider entity, Bundle bundle, Bundle targetBundle);  }
@Test void linkBindOnly() { Bundle bundle = new Bundle(); final IdentityProvider identityProvider = new IdentityProvider.Builder() .name("Test") .type(IdentityProviderType.BIND_ONLY_LDAP) .build(); linker.link(identityProvider, bundle, bundle); assertNull(identityProvider.getIdentityProviderDetail()); }
@Test void linkNoDetail() { Bundle bundle = new Bundle(); final IdentityProvider identityProvider = createIdentityProvider(); identityProvider.setIdentityProviderDetail(null); linker.link(identityProvider, bundle, bundle); assertNull(identityProvider.getIdentityProviderDetail()); }
@Test void linkNoCert() { link(); }
@Test void linkOneCert() { link("id1"); }
@Test void linkMultiCerts() { link("id1", "id2"); }