Search in sources :

Example 1 with ContextModule

use of keywhiz.inject.ContextModule in project keywhiz by square.

the class ServiceDataSourceModuleTest method injectsDataSources.

@Test
public void injectsDataSources() {
    class Holder {

        @Inject
        ManagedDataSource readWrite;

        @Inject
        @Readonly
        ManagedDataSource readonly;
    }
    Holder holder = new Holder();
    ServiceContext context = ServiceContext.create();
    Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule()).injectMembers(holder);
    assertNotNull(holder.readWrite);
    assertNotNull(holder.readonly);
}
Also used : ServiceContext(keywhiz.test.ServiceContext) ContextModule(keywhiz.inject.ContextModule) ServiceDataSourceModule(keywhiz.ServiceDataSourceModule) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Test(org.junit.Test)

Example 2 with ContextModule

use of keywhiz.inject.ContextModule in project keywhiz by square.

the class ServiceModule method configure.

@Override
protected void configure() {
    // Initialize the BouncyCastle security provider for cryptography support.
    BouncyCastle.require();
    bind(ClientCertificateFilter.class).toProvider(ClientCertificateFilter::new);
    bind(Clock.class).toInstance(Clock.systemUTC());
    bind(CookieConfig.class).annotatedWith(SessionCookie.class).toInstance(config.getSessionCookieConfig());
    bind(SecurityHeadersFilter.class).toProvider(SecurityHeadersFilter::new);
    bind(SessionMeResource.class).toProvider(SessionMeResource::new);
    install(new ContextModule(config, environment));
    install(new CookieModule(config.getCookieKey()));
    install(new CryptoModule(config.getDerivationProviderClass(), config.getContentKeyStore()));
    install(new DaoModule());
    install(new StrictGuiceModule());
}
Also used : ClientCertificateFilter(keywhiz.auth.mutualssl.ClientCertificateFilter) CryptoModule(keywhiz.service.crypto.CryptoModule) ContextModule(keywhiz.inject.ContextModule) SessionCookie(keywhiz.auth.cookie.SessionCookie) SessionMeResource(keywhiz.service.resources.admin.SessionMeResource) CookieModule(keywhiz.auth.cookie.CookieModule) Clock(java.time.Clock) SecurityHeadersFilter(keywhiz.service.filters.SecurityHeadersFilter) DaoModule(keywhiz.service.daos.DaoModule) StrictGuiceModule(keywhiz.inject.StrictGuiceModule)

Example 3 with ContextModule

use of keywhiz.inject.ContextModule in project keywhiz by square.

the class ServiceDataSourceModuleTest method dataSourcesAreSingletons.

@Test
public void dataSourcesAreSingletons() {
    class Holder {

        @Inject
        ManagedDataSource readWrite;

        @Inject
        @Readonly
        ManagedDataSource readonly;
    }
    Holder holder1 = new Holder();
    Holder holder2 = new Holder();
    ServiceContext context = ServiceContext.create();
    Injector injector = Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment()), new ServiceDataSourceModule());
    injector.injectMembers(holder1);
    injector.injectMembers(holder2);
    assertSame(holder1.readWrite, holder2.readWrite);
    assertSame(holder1.readonly, holder2.readonly);
}
Also used : ServiceContext(keywhiz.test.ServiceContext) Injector(com.google.inject.Injector) ContextModule(keywhiz.inject.ContextModule) ServiceDataSourceModule(keywhiz.ServiceDataSourceModule) ManagedDataSource(io.dropwizard.db.ManagedDataSource) Test(org.junit.Test)

Aggregations

ContextModule (keywhiz.inject.ContextModule)3 ManagedDataSource (io.dropwizard.db.ManagedDataSource)2 ServiceDataSourceModule (keywhiz.ServiceDataSourceModule)2 ServiceContext (keywhiz.test.ServiceContext)2 Test (org.junit.Test)2 Injector (com.google.inject.Injector)1 Clock (java.time.Clock)1 CookieModule (keywhiz.auth.cookie.CookieModule)1 SessionCookie (keywhiz.auth.cookie.SessionCookie)1 ClientCertificateFilter (keywhiz.auth.mutualssl.ClientCertificateFilter)1 StrictGuiceModule (keywhiz.inject.StrictGuiceModule)1 CryptoModule (keywhiz.service.crypto.CryptoModule)1 DaoModule (keywhiz.service.daos.DaoModule)1 SecurityHeadersFilter (keywhiz.service.filters.SecurityHeadersFilter)1 SessionMeResource (keywhiz.service.resources.admin.SessionMeResource)1