Search in sources :

Example 6 with AuthServiceExtension

use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.

the class PortabilityAuthServiceExtensionRegistryTest method testGetExportServices1.

@Test
public void testGetExportServices1() {
    List<String> supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS");
    List<String> supportedServiceTypes2 = ImmutableList.of("CONTACTS");
    AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider(supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1");
    AuthServiceExtension mockAuthProvider2 = getMockedAuthProvider(supportedServiceTypes2, supportedServiceTypes2, "mockAuthProvider2");
    AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2));
    Set<String> actual = registry.getExportServices("CONTACTS");
    final String[] services = new String[] { "mockAuthProvider1", "mockAuthProvider2" };
    Set<String> expected = new HashSet<>(Arrays.asList(services));
    Assert.assertEquals(actual, expected);
}
Also used : AuthServiceProviderRegistry(org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry) AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with AuthServiceExtension

use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.

the class ApiMain method initializeHttps.

public void initializeHttps(TrustManagerFactory trustManagerFactory, KeyManagerFactory keyManagerFactory, KeyStore keyStore) {
    // TODO init with types
    TypeManager typeManager = new TypeManagerImpl();
    typeManager.registerTypes(TokenAuthData.class, TokensAndUrlAuthData.class, TokenSecretAuthData.class);
    SettingsExtension settingsExtension = getSettingsExtension();
    settingsExtension.initialize();
    ApiExtensionContext extensionContext = new ApiExtensionContext(typeManager, settingsExtension, monitor);
    if (trustManagerFactory != null) {
        extensionContext.registerService(TrustManagerFactory.class, trustManagerFactory);
    }
    if (keyManagerFactory != null) {
        extensionContext.registerService(KeyManagerFactory.class, keyManagerFactory);
    }
    if (keyStore != null) {
        extensionContext.registerService(KeyStore.class, keyStore);
    }
    extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
    extensionContext.registerService(JsonFactory.class, new JacksonFactory());
    // Services that need to be shared between authServiceExtensions or load types in the
    // typemanager get initialized first.
    serviceExtensions = new ArrayList<>();
    ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtensions::add);
    serviceExtensions.forEach((se) -> se.initialize(extensionContext));
    CloudExtension cloudExtension = getCloudExtension();
    cloudExtension.initialize(extensionContext);
    // Needed for GoogleAuthServiceExtension
    extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
    extensionContext.registerService(JobStore.class, cloudExtension.getJobStore());
    extensionContext.registerService(TemporaryPerJobDataStore.class, cloudExtension.getJobStore());
    extensionContext.registerService(AppCredentialStore.class, cloudExtension.getAppCredentialStore());
    // TODO: Load up only "enabled" services
    List<AuthServiceExtension> authServiceExtensions = new ArrayList<>();
    ServiceLoader.load(AuthServiceExtension.class).iterator().forEachRemaining((authServiceExtension) -> {
        authServiceExtension.initialize(extensionContext);
        authServiceExtensions.add(authServiceExtension);
    });
    // TODO: make configurable
    SymmetricKeyGenerator keyGenerator = new AesSymmetricKeyGenerator(monitor);
    TokenManager tokenManager;
    try {
        // TODO: we store the JWT Token with the application credentials, but dont need to have a key
        // consider using a blobstore type of thing or allowing the AppCredentialStore to return a
        // cred that doesn't contain a key.
        tokenManager = new JWTTokenManager(cloudExtension.getAppCredentialStore().getAppCredentials(JWTTokenManager.JWT_KEY_NAME, JWTTokenManager.JWT_SECRET_NAME).getSecret(), monitor);
    } catch (IOException e) {
        monitor.info(() -> "Unable to initialize JWTTokenManager, did you specify a JWT_KEY and JWT_SECRET?", e);
        throw new RuntimeException(e);
    }
    Injector injector;
    try {
        injector = Guice.createInjector(new ApiServicesModule(typeManager, cloudExtension.getJobStore(), keyGenerator, trustManagerFactory, keyManagerFactory, authServiceExtensions, tokenManager, extensionContext));
    } catch (Exception e) {
        monitor.info(() -> "Error initializing Guice", e);
        throw e;
    }
    extensionContext.registerService(Injector.class, injector);
    bindActions(injector, extensionContext);
}
Also used : ArrayList(java.util.ArrayList) JWTTokenManager(org.datatransferproject.api.token.JWTTokenManager) TypeManagerImpl(org.datatransferproject.launcher.types.TypeManagerImpl) IOException(java.io.IOException) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) IOException(java.io.IOException) SettingsExtension(org.datatransferproject.config.extension.SettingsExtension) SettingsExtensionLoader.getSettingsExtension(org.datatransferproject.config.extension.SettingsExtensionLoader.getSettingsExtension) CloudExtension(org.datatransferproject.spi.cloud.extension.CloudExtension) CloudExtensionLoader.getCloudExtension(org.datatransferproject.spi.cloud.extension.CloudExtensionLoader.getCloudExtension) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) SymmetricKeyGenerator(org.datatransferproject.security.SymmetricKeyGenerator) AesSymmetricKeyGenerator(org.datatransferproject.security.AesSymmetricKeyGenerator) Injector(com.google.inject.Injector) TypeManager(org.datatransferproject.api.launcher.TypeManager) AesSymmetricKeyGenerator(org.datatransferproject.security.AesSymmetricKeyGenerator) AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension) JWTTokenManager(org.datatransferproject.api.token.JWTTokenManager) TokenManager(org.datatransferproject.spi.api.token.TokenManager)

Example 8 with AuthServiceExtension

use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.

the class PortabilityAuthServiceExtensionRegistryTest method testGetExportServices2.

@Test
public void testGetExportServices2() {
    List<String> supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS");
    List<String> supportedServiceTypes2 = ImmutableList.of("CONTACTS");
    AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider(supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1");
    AuthServiceExtension mockAuthProvider2 = getMockedAuthProvider(supportedServiceTypes2, supportedServiceTypes2, "mockAuthProvider2");
    AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2));
    Set<String> actual = registry.getExportServices("PHOTOS");
    final String[] services = new String[] { "mockAuthProvider1" };
    Set<String> expected = new HashSet<>(Arrays.asList(services));
    Assert.assertEquals(actual, expected);
}
Also used : AuthServiceProviderRegistry(org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry) AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with AuthServiceExtension

use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.

the class PortabilityAuthServiceExtensionRegistryTest method testGetImportServices2.

@Test
public void testGetImportServices2() {
    List<String> supportedServiceTypes1 = ImmutableList.of("PHOTOS", "CONTACTS");
    List<String> supportedServiceTypes2 = ImmutableList.of("CONTACTS");
    AuthServiceExtension mockAuthProvider1 = getMockedAuthProvider(supportedServiceTypes1, supportedServiceTypes1, "mockAuthProvider1");
    AuthServiceExtension mockAuthProvider2 = getMockedAuthProvider(supportedServiceTypes2, supportedServiceTypes2, "mockAuthProvider2");
    AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider1", mockAuthProvider1, "mockServiceProvider2", mockAuthProvider2));
    Set<String> actual = registry.getImportServices("PHOTOS");
    final String[] services = new String[] { "mockAuthProvider1" };
    Set<String> expected = new HashSet<>(Arrays.asList(services));
    Assert.assertEquals(actual, expected);
}
Also used : AuthServiceProviderRegistry(org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry) AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with AuthServiceExtension

use of org.datatransferproject.spi.api.auth.extension.AuthServiceExtension in project data-transfer-project by google.

the class PortabilityAuthServiceExtensionRegistryTest method testGetAuthDataGenerator.

@Test
public void testGetAuthDataGenerator() {
    List<String> supportedServiceTypes = ImmutableList.of("PHOTOS", "CONTACTS");
    AuthServiceExtension mockAuthProvider = getMockedAuthProvider(supportedServiceTypes, supportedServiceTypes, "mockAuthProvider");
    when(mockAuthProvider.getAuthDataGenerator("CONTACTS", AuthServiceProviderRegistry.AuthMode.EXPORT)).thenReturn(mock(AuthDataGenerator.class));
    AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider", mockAuthProvider));
    AuthDataGenerator actual = registry.getAuthDataGenerator("mockServiceProvider", "CONTACTS", AuthServiceProviderRegistry.AuthMode.EXPORT);
    Assert.assertNotNull(actual);
}
Also used : AuthDataGenerator(org.datatransferproject.spi.api.auth.AuthDataGenerator) AuthServiceProviderRegistry(org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry) AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension) Test(org.junit.Test)

Aggregations

AuthServiceExtension (org.datatransferproject.spi.api.auth.extension.AuthServiceExtension)10 AuthServiceProviderRegistry (org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)5 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 Injector (com.google.inject.Injector)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TypeManager (org.datatransferproject.api.launcher.TypeManager)1 JWTTokenManager (org.datatransferproject.api.token.JWTTokenManager)1 SettingsExtension (org.datatransferproject.config.extension.SettingsExtension)1 SettingsExtensionLoader.getSettingsExtension (org.datatransferproject.config.extension.SettingsExtensionLoader.getSettingsExtension)1 TypeManagerImpl (org.datatransferproject.launcher.types.TypeManagerImpl)1 AesSymmetricKeyGenerator (org.datatransferproject.security.AesSymmetricKeyGenerator)1 SymmetricKeyGenerator (org.datatransferproject.security.SymmetricKeyGenerator)1 AuthDataGenerator (org.datatransferproject.spi.api.auth.AuthDataGenerator)1 TokenManager (org.datatransferproject.spi.api.token.TokenManager)1 CloudExtension (org.datatransferproject.spi.cloud.extension.CloudExtension)1 CloudExtensionLoader.getCloudExtension (org.datatransferproject.spi.cloud.extension.CloudExtensionLoader.getCloudExtension)1