Search in sources :

Example 66 with Provider

use of com.google.inject.Provider in project che by eclipse.

the class ImportProjectWizardPresenter method getWizardForImporter.

/** Creates or returns import wizard for the specified importer. */
private ImportWizard getWizardForImporter(@NotNull ProjectImporterDescriptor importer) {
    if (wizardsCache.containsKey(importer)) {
        return wizardsCache.get(importer);
    }
    final ImportWizardRegistrar wizardRegistrar = wizardRegistry.getWizardRegistrar(importer.getId());
    if (wizardRegistrar == null) {
        // should never occur
        throw new IllegalStateException("WizardRegistrar for the importer " + importer.getId() + " isn't registered.");
    }
    List<Provider<? extends WizardPage<MutableProjectConfig>>> pageProviders = wizardRegistrar.getWizardPages();
    final ImportWizard importWizard = createDefaultWizard();
    for (Provider<? extends WizardPage<MutableProjectConfig>> provider : pageProviders) {
        importWizard.addPage(provider.get(), 1, false);
    }
    wizardsCache.put(importer, importWizard);
    return importWizard;
}
Also used : ImportWizardRegistrar(org.eclipse.che.ide.api.project.wizard.ImportWizardRegistrar) MutableProjectConfig(org.eclipse.che.ide.api.project.MutableProjectConfig) ImportWizard(org.eclipse.che.ide.projectimport.wizard.ImportWizard) WizardPage(org.eclipse.che.ide.api.wizard.WizardPage) Provider(com.google.inject.Provider)

Example 67 with Provider

use of com.google.inject.Provider in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet method getServiceSecurityManagerProvider.

/**
	 * Gets a custom service security manager provider.  If this is null, the system will us a default provider.
	 * @return Gets a service security manager provider.
	 */
protected Provider<ServiceSecurityManager> getServiceSecurityManagerProvider() {
    Provider<ServiceSecurityManager> retVal = null;
    String providerClazz = GatewayConfiguration.getConfigurationParam(SecurityAndTrustMailetOptions.SERVICE_SECURITY_MANAGER_PROVIDER, this, "");
    if (providerClazz != null && !providerClazz.isEmpty()) {
        try {
            // create an instance of the provider
            @SuppressWarnings("unchecked") Class<Provider<ServiceSecurityManager>> clazz = (Class<Provider<ServiceSecurityManager>>) getClass().getClassLoader().loadClass(providerClazz);
            retVal = clazz.newInstance();
        } catch (Exception e) {
            LOGGER.warn("Failed to load service security manager provider class " + providerClazz + ": " + e.getMessage(), e);
            retVal = new OpenServiceSecurityManagerProvider();
        }
    } else {
        retVal = new OpenServiceSecurityManagerProvider();
    }
    if (retVal instanceof MailetAwareProvider)
        ((MailetAwareProvider) retVal).setMailet(this);
    return retVal;
}
Also used : ServiceSecurityManager(org.nhindirect.common.rest.ServiceSecurityManager) OpenServiceSecurityManagerProvider(org.nhindirect.common.rest.provider.OpenServiceSecurityManagerProvider) MailetAwareProvider(org.nhindirect.gateway.smtp.provider.MailetAwareProvider) MessagingException(javax.mail.MessagingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) MalformedURLException(java.net.MalformedURLException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) RejectedRecipientDSNCreatorProvider(org.nhindirect.gateway.smtp.dsn.provider.RejectedRecipientDSNCreatorProvider) URLAccessedConfigProvider(org.nhindirect.gateway.smtp.provider.URLAccessedConfigProvider) SecureURLAccessedConfigProvider(org.nhindirect.gateway.smtp.provider.SecureURLAccessedConfigProvider) OpenServiceSecurityManagerProvider(org.nhindirect.common.rest.provider.OpenServiceSecurityManagerProvider) WSSmtpAgentConfigProvider(org.nhindirect.gateway.smtp.provider.WSSmtpAgentConfigProvider) XMLSmtpAgentConfigProvider(org.nhindirect.gateway.smtp.provider.XMLSmtpAgentConfigProvider) MailetAwareProvider(org.nhindirect.gateway.smtp.provider.MailetAwareProvider) KeyStoreProtectionConfigProvider(org.nhindirect.gateway.smtp.provider.KeyStoreProtectionConfigProvider) Provider(com.google.inject.Provider)

Example 68 with Provider

use of com.google.inject.Provider in project gerrit by GerritCodeReview.

the class Daemon method createSysInjector.

private Injector createSysInjector() {
    final List<Module> modules = new ArrayList<>();
    modules.add(SchemaVersionCheck.module());
    modules.add(new DropWizardMetricMaker.RestModule());
    modules.add(new LogFileCompressor.Module());
    // Index module shutdown must happen before work queue shutdown, otherwise
    // work queue can get stuck waiting on index futures that will never return.
    modules.add(createIndexModule());
    modules.add(new WorkQueue.Module());
    modules.add(new StreamEventsApiListener.Module());
    modules.add(new EventBroker.Module());
    modules.add(test ? new H2AccountPatchReviewStore.InMemoryModule() : new JdbcAccountPatchReviewStore.Module(config));
    modules.add(new ReceiveCommitsExecutorModule());
    modules.add(new DiffExecutorModule());
    modules.add(new MimeUtil2Module());
    modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
    modules.add(new SearchingChangeCacheImpl.Module(slave));
    modules.add(new InternalAccountDirectory.Module());
    modules.add(new DefaultPermissionBackendModule());
    modules.add(new DefaultCacheFactory.Module());
    modules.add(cfgInjector.getInstance(MailReceiver.Module.class));
    if (emailModule != null) {
        modules.add(emailModule);
    } else {
        modules.add(new SmtpEmailSender.Module());
    }
    modules.add(new SignedTokenEmailTokenVerifier.Module());
    modules.add(new PluginRestApiModule());
    modules.add(new RestCacheAdminModule());
    modules.add(new GpgModule(config));
    modules.add(new StartupChecks.Module());
    if (MoreObjects.firstNonNull(httpd, true)) {
        modules.add(new CanonicalWebUrlModule() {

            @Override
            protected Class<? extends Provider<String>> provider() {
                return HttpCanonicalWebUrlProvider.class;
            }
        });
    } else {
        modules.add(new CanonicalWebUrlModule() {

            @Override
            protected Class<? extends Provider<String>> provider() {
                return CanonicalWebUrlProvider.class;
            }
        });
    }
    if (sshd) {
        modules.add(SshKeyCacheImpl.module());
    } else {
        modules.add(NoSshKeyCache.module());
    }
    modules.add(new AbstractModule() {

        @Override
        protected void configure() {
            bind(GerritOptions.class).toInstance(new GerritOptions(config, headless, slave, polyGerritDev));
            if (test) {
                bind(String.class).annotatedWith(SecureStoreClassName.class).toInstance(DefaultSecureStore.class.getName());
                bind(SecureStore.class).toProvider(SecureStoreProvider.class);
            }
        }
    });
    modules.add(new GarbageCollectionModule());
    if (!slave) {
        modules.add(new ChangeCleanupRunner.Module());
    }
    return cfgInjector.createChildInjector(modules);
}
Also used : ArrayList(java.util.ArrayList) InternalAccountDirectory(com.google.gerrit.server.account.InternalAccountDirectory) WorkQueue(com.google.gerrit.server.git.WorkQueue) MimeUtil2Module(com.google.gerrit.server.mime.MimeUtil2Module) SignedTokenEmailTokenVerifier(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) StartupChecks(com.google.gerrit.server.StartupChecks) ChangeCleanupRunner(com.google.gerrit.server.change.ChangeCleanupRunner) GarbageCollectionModule(com.google.gerrit.server.git.GarbageCollectionModule) RestCacheAdminModule(com.google.gerrit.server.config.RestCacheAdminModule) DropWizardMetricMaker(com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker) GpgModule(com.google.gerrit.gpg.GpgModule) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) EventBroker(com.google.gerrit.common.EventBroker) SearchingChangeCacheImpl(com.google.gerrit.server.git.SearchingChangeCacheImpl) PluginRestApiModule(com.google.gerrit.server.plugins.PluginRestApiModule) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) GerritOptions(com.google.gerrit.server.config.GerritOptions) SecureStoreProvider(com.google.gerrit.server.securestore.SecureStoreProvider) StreamEventsApiListener(com.google.gerrit.server.events.StreamEventsApiListener) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) DataSourceProvider(com.google.gerrit.server.schema.DataSourceProvider) CanonicalWebUrlProvider(com.google.gerrit.server.config.CanonicalWebUrlProvider) HttpCanonicalWebUrlProvider(com.google.gerrit.httpd.HttpCanonicalWebUrlProvider) SecureStoreProvider(com.google.gerrit.server.securestore.SecureStoreProvider) Provider(com.google.inject.Provider) AbstractModule(com.google.inject.AbstractModule) LogFileCompressor(com.google.gerrit.pgm.util.LogFileCompressor) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) SmtpEmailSender(com.google.gerrit.server.mail.send.SmtpEmailSender) AuthConfigModule(com.google.gerrit.server.config.AuthConfigModule) Module(com.google.inject.Module) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) DummyIndexModule(com.google.gerrit.server.index.DummyIndexModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) LuceneIndexModule(com.google.gerrit.lucene.LuceneIndexModule) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) OAuthModule(com.google.gerrit.httpd.auth.oauth.OAuthModule) MimeUtil2Module(com.google.gerrit.server.mime.MimeUtil2Module) GarbageCollectionModule(com.google.gerrit.server.git.GarbageCollectionModule) WebSshGlueModule(com.google.gerrit.httpd.WebSshGlueModule) SshModule(com.google.gerrit.sshd.SshModule) SshAddressesModule(com.google.gerrit.server.ssh.SshAddressesModule) HttpPluginModule(com.google.gerrit.httpd.plugins.HttpPluginModule) DefaultCommandModule(com.google.gerrit.sshd.commands.DefaultCommandModule) WebModule(com.google.gerrit.httpd.WebModule) PluginRestApiModule(com.google.gerrit.server.plugins.PluginRestApiModule) ReceiveCommitsExecutorModule(com.google.gerrit.server.git.ReceiveCommitsExecutorModule) ElasticIndexModule(com.google.gerrit.elasticsearch.ElasticIndexModule) GitOverHttpModule(com.google.gerrit.httpd.GitOverHttpModule) IndexModule(com.google.gerrit.server.index.IndexModule) StaticModule(com.google.gerrit.httpd.raw.StaticModule) RestCacheAdminModule(com.google.gerrit.server.config.RestCacheAdminModule) IndexCommandsModule(com.google.gerrit.sshd.commands.IndexCommandsModule) JettyModule(com.google.gerrit.pgm.http.jetty.JettyModule) DiffExecutorModule(com.google.gerrit.server.patch.DiffExecutorModule) NoSshModule(com.google.gerrit.server.ssh.NoSshModule) GpgModule(com.google.gerrit.gpg.GpgModule) OpenIdModule(com.google.gerrit.httpd.auth.openid.OpenIdModule) SshHostKeyModule(com.google.gerrit.sshd.SshHostKeyModule) AbstractModule(com.google.inject.AbstractModule) ReceiveCommitsExecutorModule(com.google.gerrit.server.git.ReceiveCommitsExecutorModule)

Example 69 with Provider

use of com.google.inject.Provider in project gerrit by GerritCodeReview.

the class OAuthWebFilter method selectProvider.

private void selectProvider(HttpServletRequest req, HttpServletResponse res, @Nullable String errorMessage) throws IOException {
    String self = req.getRequestURI();
    String cancel = MoreObjects.firstNonNull(urlProvider != null ? urlProvider.get() : "/", "/");
    cancel += LoginUrlToken.getToken(req);
    Document doc = header.parse(OAuthWebFilter.class, "LoginForm.html");
    HtmlDomUtil.find(doc, "hostName").setTextContent(req.getServerName());
    HtmlDomUtil.find(doc, "login_form").setAttribute("action", self);
    HtmlDomUtil.find(doc, "cancel_link").setAttribute("href", cancel);
    Element emsg = HtmlDomUtil.find(doc, "error_message");
    if (Strings.isNullOrEmpty(errorMessage)) {
        emsg.getParentNode().removeChild(emsg);
    } else {
        emsg.setTextContent(errorMessage);
    }
    Element providers = HtmlDomUtil.find(doc, "providers");
    Set<String> plugins = oauthServiceProviders.plugins();
    for (String pluginName : plugins) {
        Map<String, Provider<OAuthServiceProvider>> m = oauthServiceProviders.byPlugin(pluginName);
        for (Map.Entry<String, Provider<OAuthServiceProvider>> e : m.entrySet()) {
            addProvider(providers, pluginName, e.getKey(), e.getValue().get().getName());
        }
    }
    sendHtml(res, doc);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Map(java.util.Map) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) SortedMap(java.util.SortedMap) OAuthServiceProvider(com.google.gerrit.extensions.auth.oauth.OAuthServiceProvider) Provider(com.google.inject.Provider)

Example 70 with Provider

use of com.google.inject.Provider in project gerrit by GerritCodeReview.

the class Schema_150_to_151_Test method setUp.

@Before
public void setUp() throws Exception {
    Injector injector = Guice.createInjector(new InMemoryModule());
    injector.injectMembers(this);
    lifecycle = new LifecycleManager();
    lifecycle.add(injector);
    lifecycle.start();
    try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
        schemaCreator.create(underlyingDb);
    }
    db = schemaFactory.open();
    Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
    IdentifiedUser user = userFactory.create(userId);
    requestContext.setContext(new RequestContext() {

        @Override
        public CurrentUser getUser() {
            return user;
        }

        @Override
        public Provider<ReviewDb> getReviewDbProvider() {
            return Providers.of(db);
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Provider(com.google.inject.Provider) Before(org.junit.Before)

Aggregations

Provider (com.google.inject.Provider)133 Injector (com.google.inject.Injector)72 AbstractModule (com.google.inject.AbstractModule)63 Module (com.google.inject.Module)44 Key (com.google.inject.Key)17 TypeLiteral (com.google.inject.TypeLiteral)10 ArrayList (java.util.ArrayList)10 ProvisionException (com.google.inject.ProvisionException)9 Dependency (com.google.inject.spi.Dependency)9 Map (java.util.Map)8 Before (org.junit.Before)7 CurrentUser (com.google.gerrit.server.CurrentUser)6 RequestContext (com.google.gerrit.server.util.RequestContext)6 ThreadLocalRequestContext (com.google.gerrit.server.util.ThreadLocalRequestContext)6 InMemoryModule (com.google.gerrit.testutil.InMemoryModule)6 PrivateModule (com.google.inject.PrivateModule)6 Scope (com.google.inject.Scope)6 List (java.util.List)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Annotation (java.lang.annotation.Annotation)5