Search in sources :

Example 1 with AuthServiceExtension

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

the class PortabilityAuthServiceProviderRegistry method getAuthDataGenerator.

@Override
public AuthDataGenerator getAuthDataGenerator(String serviceId, String transferDataType, AuthMode mode) {
    AuthServiceExtension provider = authServiceProviderMap.get(serviceId);
    Preconditions.checkArgument(provider != null, "AuthServiceExtension not found for serviceId [%s]", serviceId);
    switch(mode) {
        case EXPORT:
            Preconditions.checkArgument(supportedExportTypes.contains(transferDataType), "AuthMode [%s] not valid for TransferDataType [%s]", mode, transferDataType);
            break;
        case IMPORT:
            Preconditions.checkArgument(supportedImportTypes.contains(transferDataType), "AuthMode [%s] not valid for TransferDataType [%s]", mode, transferDataType);
            break;
        default:
            throw new IllegalArgumentException("AuthMode [" + mode + "] not supported");
    }
    return provider.getAuthDataGenerator(transferDataType, mode);
}
Also used : AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension)

Example 2 with AuthServiceExtension

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

the class PortabilityAuthServiceExtensionRegistryTest method testGetTransferDataTypes.

@Test
public void testGetTransferDataTypes() {
    List<String> supportedServiceTypes = ImmutableList.of("PHOTOS", "CONTACTS");
    AuthServiceExtension mockAuthProvider = getMockedAuthProvider(supportedServiceTypes, supportedServiceTypes, "mockAuthProvider");
    AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider", mockAuthProvider));
    Set<String> actual = registry.getTransferDataTypes();
    final String[] services = new String[] { "PHOTOS", "CONTACTS" };
    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 3 with AuthServiceExtension

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

the class PortabilityAuthServiceExtensionRegistryTest method testGetImportServices1.

@Test
public void testGetImportServices1() {
    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("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 4 with AuthServiceExtension

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

the class PortabilityAuthServiceExtensionRegistryTest method requireImportAndExportTest.

@Test
public void requireImportAndExportTest() {
    List<String> supportedImportTypes = ImmutableList.of("PHOTOS", "CONTACTS");
    List<String> supportedExportTypes = ImmutableList.of("CONTACTS");
    AuthServiceExtension mockAuthProvider = getMockedAuthProvider(supportedImportTypes, supportedExportTypes, "mockAuthProvider");
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("available for import but not export");
    AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider", mockAuthProvider));
}
Also used : AuthServiceProviderRegistry(org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry) AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension) Test(org.junit.Test)

Example 5 with AuthServiceExtension

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

the class PortabilityAuthServiceExtensionRegistryTest method getMockedAuthProvider.

private AuthServiceExtension getMockedAuthProvider(List<String> supportedImportTypes, List<String> supportedExportTypes, String serviceId) {
    AuthServiceExtension mockAuthProvider = mock(AuthServiceExtension.class);
    when(mockAuthProvider.getExportTypes()).thenReturn(supportedExportTypes);
    when(mockAuthProvider.getImportTypes()).thenReturn(supportedImportTypes);
    when(mockAuthProvider.getServiceId()).thenReturn(serviceId);
    return mockAuthProvider;
}
Also used : AuthServiceExtension(org.datatransferproject.spi.api.auth.extension.AuthServiceExtension)

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