Search in sources :

Example 1 with SymmetricKeyGenerator

use of org.datatransferproject.security.SymmetricKeyGenerator in project data-transfer-project by google.

the class WorkerMain method initialize.

public void initialize() {
    Monitor monitor = loadMonitor();
    SettingsExtension settingsExtension = getSettingsExtension();
    settingsExtension.initialize();
    WorkerExtensionContext extensionContext = new WorkerExtensionContext(settingsExtension, monitor);
    // TODO this should be moved into a service extension
    extensionContext.registerService(HttpTransport.class, new NetHttpTransport());
    extensionContext.registerService(OkHttpClient.class, new OkHttpClient.Builder().build());
    extensionContext.registerService(JsonFactory.class, new JacksonFactory());
    ServiceLoader.load(ServiceExtension.class).iterator().forEachRemaining(serviceExtension -> serviceExtension.initialize(extensionContext));
    // TODO: verify that this is the cloud extension that is specified in the configuration
    CloudExtension cloudExtension = getCloudExtension();
    cloudExtension.initialize(extensionContext);
    monitor.info(() -> "Using CloudExtension: " + cloudExtension.getClass().getName());
    JobStore jobStore = cloudExtension.getJobStore();
    extensionContext.registerService(JobStore.class, jobStore);
    extensionContext.registerService(TemporaryPerJobDataStore.class, jobStore);
    AppCredentialStore appCredentialStore = cloudExtension.getAppCredentialStore();
    extensionContext.registerService(AppCredentialStore.class, appCredentialStore);
    List<TransferExtension> transferExtensions = getTransferExtensions(monitor);
    // Load security extension and services
    SecurityExtension securityExtension = SecurityExtensionLoader.getSecurityExtension(extensionContext);
    monitor.info(() -> "Using SecurityExtension: " + securityExtension.getClass().getName());
    IdempotentImportExecutor idempotentImportExecutor = IdempotentImportExecutorLoader.load(extensionContext);
    monitor.info(() -> "Using IdempotentImportExecutor: " + idempotentImportExecutor.getClass().getName());
    // TODO: make configurable
    SymmetricKeyGenerator symmetricKeyGenerator = new AesSymmetricKeyGenerator(monitor);
    JobHooks jobHooks = loadJobHooks();
    Injector injector = null;
    try {
        injector = Guice.createInjector(new WorkerModule(extensionContext, cloudExtension, transferExtensions, securityExtension, idempotentImportExecutor, symmetricKeyGenerator, jobHooks));
    } catch (Exception e) {
        monitor.severe(() -> "Unable to initialize Guice in Worker", e);
        throw e;
    }
    worker = injector.getInstance(Worker.class);
    // Reset the JobMetadata in case set previously when running SingleVMMain
    JobMetadata.reset();
}
Also used : AppCredentialStore(org.datatransferproject.spi.cloud.storage.AppCredentialStore) JobHooks(org.datatransferproject.spi.transfer.hooks.JobHooks) JobHooksLoader.loadJobHooks(org.datatransferproject.spi.transfer.hooks.JobHooksLoader.loadJobHooks) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) SecurityExtension(org.datatransferproject.spi.transfer.security.SecurityExtension) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) IdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor) SettingsExtension(org.datatransferproject.config.extension.SettingsExtension) SettingsExtensionLoader.getSettingsExtension(org.datatransferproject.config.extension.SettingsExtensionLoader.getSettingsExtension) MonitorLoader.loadMonitor(org.datatransferproject.launcher.monitor.MonitorLoader.loadMonitor) Monitor(org.datatransferproject.api.launcher.Monitor) 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) TransferExtension(org.datatransferproject.spi.transfer.extension.TransferExtension) AesSymmetricKeyGenerator(org.datatransferproject.security.AesSymmetricKeyGenerator)

Example 2 with SymmetricKeyGenerator

use of org.datatransferproject.security.SymmetricKeyGenerator 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)

Aggregations

NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)2 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)2 Injector (com.google.inject.Injector)2 SettingsExtension (org.datatransferproject.config.extension.SettingsExtension)2 SettingsExtensionLoader.getSettingsExtension (org.datatransferproject.config.extension.SettingsExtensionLoader.getSettingsExtension)2 AesSymmetricKeyGenerator (org.datatransferproject.security.AesSymmetricKeyGenerator)2 SymmetricKeyGenerator (org.datatransferproject.security.SymmetricKeyGenerator)2 CloudExtension (org.datatransferproject.spi.cloud.extension.CloudExtension)2 CloudExtensionLoader.getCloudExtension (org.datatransferproject.spi.cloud.extension.CloudExtensionLoader.getCloudExtension)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Monitor (org.datatransferproject.api.launcher.Monitor)1 TypeManager (org.datatransferproject.api.launcher.TypeManager)1 JWTTokenManager (org.datatransferproject.api.token.JWTTokenManager)1 MonitorLoader.loadMonitor (org.datatransferproject.launcher.monitor.MonitorLoader.loadMonitor)1 TypeManagerImpl (org.datatransferproject.launcher.types.TypeManagerImpl)1 AuthServiceExtension (org.datatransferproject.spi.api.auth.extension.AuthServiceExtension)1 TokenManager (org.datatransferproject.spi.api.token.TokenManager)1 AppCredentialStore (org.datatransferproject.spi.cloud.storage.AppCredentialStore)1 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)1