use of org.dataportabilityproject.spi.gateway.auth.extension.AuthServiceExtension in project data-transfer-project by google.
the class ApiMain method initializeHttps.
public void initializeHttps(TrustManagerFactory trustManagerFactory, KeyManagerFactory keyManagerFactory) {
// TODO init with types
TypeManager typeManager = new TypeManagerImpl();
typeManager.registerTypes(TokenAuthData.class, TokensAndUrlAuthData.class, TokenSecretAuthData.class);
SettingsExtension settingsExtension = getSettingsExtension();
settingsExtension.initialize(null);
ApiExtensionContext extensionContext = new ApiExtensionContext(typeManager, settingsExtension);
// Services that need to be shared between authServiceExtensions or load types in the
// typemanager get initialized first.
ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtension -> serviceExtension.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(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();
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());
} catch (IOException e) {
logger.error("Unable to initialize JWTTokenManager, did you specify a JWT_KEY and JWT_SECRET?");
throw new RuntimeException(e);
}
Injector injector = Guice.createInjector(new ApiServicesModule(typeManager, cloudExtension.getJobStore(), keyGenerator, trustManagerFactory, keyManagerFactory, authServiceExtensions, tokenManager), new ReferenceApiModule(extensionContext));
// Launch the application
// TODO: Support other server implementations, e.g. Jetty, Tomcat
server = injector.getInstance(ReferenceApiServer.class);
}
use of org.dataportabilityproject.spi.gateway.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);
}
use of org.dataportabilityproject.spi.gateway.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 = mock(AuthServiceExtension.class);
when(mockAuthProvider.getExportTypes()).thenReturn(supportedExportTypes);
when(mockAuthProvider.getImportTypes()).thenReturn(supportedImportTypes);
when(mockAuthProvider.getServiceId()).thenReturn("mockAuthProvider");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("available for import but not export");
AuthServiceProviderRegistry registry = new PortabilityAuthServiceProviderRegistry(ImmutableMap.of("mockServiceProvider", mockAuthProvider));
}
Aggregations