@Test public void shouldFetchProvidersFromDataManager() { final DataManager dataManager = mock(DataManager.class); final CredentialProviderRegistry registry = new CredentialProviderRegistry(dataManager); final Connector connector = new Connector.Builder().id("test-provider") .putProperty("clientId", new ConfigurationProperty.Builder().addTag(Credentials.CLIENT_ID_TAG).build()) .putProperty("clientSecret", new ConfigurationProperty.Builder().addTag(Credentials.CLIENT_SECRET_TAG).build()) .putConfiguredProperty("clientId", "a-client-id").putConfiguredProperty("clientSecret", "a-client-secret") .build(); when(dataManager.fetch(Connector.class, "test-provider")).thenReturn(connector); assertThat(registry.providerWithId("test-provider")).isInstanceOfSatisfying(TestCredentialProvider.class, p -> { assertThat(p.getProperties().getAppId()).isEqualTo("a-client-id"); assertThat(p.getProperties().getAppSecret()).isEqualTo("a-client-secret"); }); }
@Override public CredentialProvider providerWithId(final String providerId) { final Connector connector = dataManager.fetch(Connector.class, providerId); if (connector == null) { throw new IllegalArgumentException("Unable to find connector with id: " + providerId); } final String providerToUse = determineProviderFrom(connector); final CredentialProviderFactory credentialProviderFactory = credentialProviderFactories.get(providerToUse); if (credentialProviderFactory == null) { throw new IllegalArgumentException("Unable to locate credential provider factory with id: " + providerId); } final SocialProperties socialProperties = createSocialProperties(providerToUse, connector); final CredentialProvider providerWithId = credentialProviderFactory.create(socialProperties); if (providerWithId == null) { throw new IllegalArgumentException("Unable to locate credential provider with id: " + providerId); } return providerWithId; }
CredentialProviderRegistry implements CredentialProviderLocator { @Override public CredentialProvider providerWithId(final String providerId) { final Connector connector = dataManager.fetch(Connector.class, providerId); if (connector == null) { throw new IllegalArgumentException("Unable to find connector with id: " + providerId); } final String providerToUse = determineProviderFrom(connector); final CredentialProviderFactory credentialProviderFactory = credentialProviderFactories.get(providerToUse); if (credentialProviderFactory == null) { throw new IllegalArgumentException("Unable to locate credential provider factory with id: " + providerId); } final SocialProperties socialProperties = createSocialProperties(providerToUse, connector); final CredentialProvider providerWithId = credentialProviderFactory.create(socialProperties); if (providerWithId == null) { throw new IllegalArgumentException("Unable to locate credential provider with id: " + providerId); } return providerWithId; } }
CredentialProviderRegistry implements CredentialProviderLocator { @Override public CredentialProvider providerWithId(final String providerId) { final Connector connector = dataManager.fetch(Connector.class, providerId); if (connector == null) { throw new IllegalArgumentException("Unable to find connector with id: " + providerId); } final String providerToUse = determineProviderFrom(connector); final CredentialProviderFactory credentialProviderFactory = credentialProviderFactories.get(providerToUse); if (credentialProviderFactory == null) { throw new IllegalArgumentException("Unable to locate credential provider factory with id: " + providerId); } final SocialProperties socialProperties = createSocialProperties(providerToUse, connector); final CredentialProvider providerWithId = credentialProviderFactory.create(socialProperties); if (providerWithId == null) { throw new IllegalArgumentException("Unable to locate credential provider with id: " + providerId); } return providerWithId; } CredentialProviderRegistry(final DataManager dataManager); }
CredentialProviderRegistry implements CredentialProviderLocator { @Override public CredentialProvider providerWithId(final String providerId) { final Connector connector = dataManager.fetch(Connector.class, providerId); if (connector == null) { throw new IllegalArgumentException("Unable to find connector with id: " + providerId); } final String providerToUse = determineProviderFrom(connector); final CredentialProviderFactory credentialProviderFactory = credentialProviderFactories.get(providerToUse); if (credentialProviderFactory == null) { throw new IllegalArgumentException("Unable to locate credential provider factory with id: " + providerId); } final SocialProperties socialProperties = createSocialProperties(providerToUse, connector); final CredentialProvider providerWithId = credentialProviderFactory.create(socialProperties); if (providerWithId == null) { throw new IllegalArgumentException("Unable to locate credential provider with id: " + providerId); } return providerWithId; } CredentialProviderRegistry(final DataManager dataManager); @Override CredentialProvider providerWithId(final String providerId); }
CredentialProviderRegistry implements CredentialProviderLocator { @Override public CredentialProvider providerWithId(final String providerId) { final Connector connector = dataManager.fetch(Connector.class, providerId); if (connector == null) { throw new IllegalArgumentException("Unable to find connector with id: " + providerId); } final String providerToUse = determineProviderFrom(connector); final CredentialProviderFactory credentialProviderFactory = credentialProviderFactories.get(providerToUse); if (credentialProviderFactory == null) { throw new IllegalArgumentException("Unable to locate credential provider factory with id: " + providerId); } final SocialProperties socialProperties = createSocialProperties(providerToUse, connector); final CredentialProvider providerWithId = credentialProviderFactory.create(socialProperties); if (providerWithId == null) { throw new IllegalArgumentException("Unable to locate credential provider with id: " + providerId); } return providerWithId; } CredentialProviderRegistry(final DataManager dataManager); @Override CredentialProvider providerWithId(final String providerId);  }