com.google.inject.binder.AnnotatedBindingBuilder Java Examples

The following examples show how to use com.google.inject.binder.AnnotatedBindingBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BindingDefinition.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
void apply(Binder binder) {
    if (from != null) {
        AnnotatedBindingBuilder<T> bind = binder.bind(from);
        if (!from.isAssignableFrom(target)) {
            throw SeedException.createNew(CoreErrorCode.INVALID_BINDING)
                    .put("key", from)
                    .put("target", target);
        }
        if (qualifier != null) {
            LOGGER.debug("Binding {} annotated with {} to {}", from.getName(), qualifier, target.getName());
            bind.annotatedWith(qualifier).to(target);
        } else {
            LOGGER.debug("Binding {} to {}", from.getName(), target.getName());
            bind.to(target);
        }
    } else {
        if (qualifier != null) {
            LOGGER.debug("Binding {} annotated with {} to itself", target.getName(), qualifier);
            binder.bind(target).annotatedWith(qualifier);
        } else {
            LOGGER.debug("Binding {} to itself", target.getName());
            binder.bind(target);
        }
    }
}
 
Example #2
Source File: SecurityInternalModuleUnitTest.java    From seed with Mozilla Public License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
@Before
public void before() {
    PrivateBinder binder = mock(PrivateBinder.class);
    AnnotatedBindingBuilder ab = mock(AnnotatedBindingBuilder.class);
    when(binder.bind(any(Class.class))).thenReturn(ab);
    when(ab.annotatedWith(any(Annotation.class))).thenReturn(ab);
    AnnotatedElementBuilder aeb = mock(AnnotatedElementBuilder.class);
    when(binder.expose(any(Class.class))).thenReturn(aeb);
    ScopedBindingBuilder sb = mock(ScopedBindingBuilder.class);
    when(ab.toProvider(any(Provider.class))).thenReturn(sb);
    when(binder.bind(any(TypeLiteral.class))).thenReturn(ab);
    when(binder.skipSources(any(Class.class), any(Class.class))).thenReturn(binder);
    when(binder.skipSources(any(Class.class))).thenReturn(binder);
    securityConfigurer = mock(SecurityConfigurer.class);
    underTest = new SecurityInternalModule(securityConfigurer, new HashMap<>());
    Whitebox.setInternalState(underTest, "binder", binder);
}
 
Example #3
Source File: GrammarAccessExtensions2Test.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Injector getInjector() {
  Injector _xblockexpression = null;
  {
    TerminalsStandaloneSetup.doSetup();
    XtextRuntimeModule _xtextRuntimeModule = new XtextRuntimeModule();
    _xblockexpression = Guice.createInjector(_xtextRuntimeModule, new com.google.inject.Module() {
      @Override
      public void configure(final Binder binder) {
        AnnotatedBindingBuilder<IXtextProjectConfig> _bind = binder.<IXtextProjectConfig>bind(IXtextProjectConfig.class);
        StandardProjectConfig _standardProjectConfig = new StandardProjectConfig();
        _bind.toInstance(_standardProjectConfig);
      }
    });
  }
  return _xblockexpression;
}
 
Example #4
Source File: TestDriver.java    From vespa with Apache License 2.0 6 votes vote down vote up
private static List<Module> newModuleList(final Application app, final Class<? extends Application> appClass,
                                          Module... guiceModules) {
    List<Module> lst = new LinkedList<>();
    lst.addAll(Arrays.asList(guiceModules));
    lst.add(new AbstractModule() {

        @Override
        public void configure() {
            AnnotatedBindingBuilder<Application> builder = bind(Application.class);
            if (app != null) {
                builder.toInstance(app);
            } else {
                builder.to(appClass);
            }
        }
    });
    return lst;
}
 
Example #5
Source File: ClientBridgeSecurityModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> bind) {     
  shiroSessionListeners = Multibinder.newSetBinder(binder(), SessionListener.class, Names.named(GuicySessionManager.PROP_SESSION_LISTENERS));
  shiroSessionListeners.addBinding().to(ShiroSessionRegistryExpirer.class).asEagerSingleton();

  bind.to(GuicySessionManager.class).asEagerSingleton();
  bind(GuicySessionManager.class);
  bindRealm().to(AppHandoffRealm.class);
}
 
Example #6
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> bind) {
bind.to(DefaultSessionManager.class).asEagerSingleton();
bind(DefaultSessionManager.class);
   bindConstant().annotatedWith(Names.named("shiro.globalSessionTimeout")).to(globalSessionTimeoutInSecs * 1000L);
   bindConstant().annotatedWith(Names.named("shiro.sessionValidationSchedulerEnabled")).to(false);
}
 
Example #7
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
protected void bindSecurityManager(AnnotatedBindingBuilder<? super SecurityManager> bind) {
	try {
		bind.toConstructor(DefaultSecurityManager.class.getConstructor(Collection.class)).asEagerSingleton();
  } catch (NoSuchMethodException e) {
      throw new ConfigurationException("This really shouldn't happen.  Either something has changed in Shiro, or there's a bug in " + ShiroModule.class.getSimpleName(), e);
  }
}
 
Example #8
Source File: ProviderDefinition.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void apply(Binder binder) {
    AnnotatedBindingBuilder<T> bind = binder.bind((TypeLiteral<T>) TypeLiteral.get(from));
    if (qualifier != null) {
        LOGGER.debug("Binding {} annotated with {} to provider {}",
                from.getTypeName(),
                qualifier,
                target.getName());
        bind.annotatedWith(qualifier).toProvider(target);
    } else {
        LOGGER.debug("Binding {} to provider {}", from.getTypeName(), target.getName());
        bind.toProvider(target);
    }
}
 
Example #9
Source File: DefaultSecurityModuleUnitTest.java    From seed with Mozilla Public License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testShiroModule() {
    SecurityGuiceConfigurer securityGuiceConfigurer = mock(SecurityGuiceConfigurer.class);
    DefaultSecurityModule underTest = new DefaultSecurityModule(securityGuiceConfigurer);
    PrivateBinder b = mock(PrivateBinder.class);
    AnnotatedBindingBuilder ab = mock(AnnotatedBindingBuilder.class);
    when(b.bind(any(Class.class))).thenReturn(ab);
    when(ab.annotatedWith(any(Annotation.class))).thenReturn(ab);
    AnnotatedElementBuilder aeb = mock(AnnotatedElementBuilder.class);
    when(b.expose(any(Class.class))).thenReturn(aeb);
    Whitebox.setInternalState(underTest, "binder", b);
    underTest.configureShiro();
}
 
Example #10
Source File: WebSecurityModule.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void bindSessionManager(final AnnotatedBindingBuilder<SessionManager> bind) {
  // use native web session management instead of delegating to servlet container
  // workaround for NEXUS-5727, see NexusDefaultWebSessionManager javadoc for clues
  bind.to(NexusWebSessionManager.class).asEagerSingleton();
  // this is a PrivateModule, so explicitly binding the NexusDefaultSessionManager class
  bind(NexusWebSessionManager.class);
}
 
Example #11
Source File: WebSecurityModule.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void bindWebSecurityManager(final AnnotatedBindingBuilder<? super WebSecurityManager> bind) {
  bind(NexusWebSecurityManager.class).asEagerSingleton();

  // bind RealmSecurityManager and WebSecurityManager to _same_ component
  bind(RealmSecurityManager.class).to(NexusWebSecurityManager.class);
  bind.to(NexusWebSecurityManager.class);

  // bindings used by external modules
  expose(RealmSecurityManager.class);
  expose(WebSecurityManager.class);
}
 
Example #12
Source File: IndexOnlyProjectTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public com.google.inject.Module getServerModule() {
  ServerModule _serverModule = new ServerModule();
  final com.google.inject.Module _function = (Binder it) -> {
    AnnotatedBindingBuilder<IMultiRootWorkspaceConfigFactory> _bind = it.<IMultiRootWorkspaceConfigFactory>bind(IMultiRootWorkspaceConfigFactory.class);
    _bind.toInstance(new MultiRootWorkspaceConfigFactory() {
      @Override
      public void addProjectsForWorkspaceFolder(final WorkspaceConfig workspaceConfig, final WorkspaceFolder workspaceFolder, final Set<String> existingNames) {
        String _uri = null;
        if (workspaceFolder!=null) {
          _uri=workspaceFolder.getUri();
        }
        boolean _tripleNotEquals = (_uri != null);
        if (_tripleNotEquals) {
          URI _uri_1 = this.getUriExtensions().toUri(workspaceFolder.getUri());
          String _uniqueProjectName = this.getUniqueProjectName(workspaceFolder.getName(), existingNames);
          final FileProjectConfig project = new FileProjectConfig(_uri_1, _uniqueProjectName) {
            @Override
            public boolean isIndexOnly() {
              return true;
            }
          };
          project.addSourceFolder(".");
          workspaceConfig.addProject(project);
        }
      }
    });
  };
  return Modules2.mixin(_serverModule, _function);
}
 
Example #13
Source File: MockDaoSecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected void bindCredentialsHashingStrategy(
      AnnotatedBindingBuilder<CredentialsHashingStrategy> bind) {
   bind.to(PlainCredentialsHashingStrategy.class).asEagerSingleton();
}
 
Example #14
Source File: KaryonBootstrapModule.java    From karyon with Apache License 2.0 4 votes vote down vote up
private static void bindHealthCheckInvocationStrategy(AnnotatedBindingBuilder<HealthCheckInvocationStrategy> bindingBuilder) {
    bindingBuilder.to(SyncHealthCheckInvocationStrategy.class);
}
 
Example #15
Source File: AbstractGeneratorFragmentTests.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public void configureIXtextProjectConfig(final Binder binder) {
  AnnotatedBindingBuilder<IXtextProjectConfig> _bind = binder.<IXtextProjectConfig>bind(IXtextProjectConfig.class);
  AbstractGeneratorFragmentTests.FakeProjectConfig _fakeProjectConfig = new AbstractGeneratorFragmentTests.FakeProjectConfig();
  _bind.toInstance(_fakeProjectConfig);
}
 
Example #16
Source File: ComponentRendererModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
protected <T extends BaseComponent> AnnotatedBindingBuilder<ComponentRenderer<? super T>> bindComponent(Class<T> componentType) {
    return bind(ComponentRenderers.rendererType(componentType));
}
 
Example #17
Source File: GriefDefenderImplModule.java    From GriefDefender with MIT License 4 votes vote down vote up
protected <T> AnnotatedBindingBuilder<T> bindAndExpose(final Class<T> type) {
    this.expose(type);
    return this.bind(type);
}
 
Example #18
Source File: MockDaoSecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected void bindSessionDAO(AnnotatedBindingBuilder<SessionDAO> bind) {
   bind.toInstance(EasyMock.createMock(SessionDAO.class));
   expose(SessionDAO.class);
}
 
Example #19
Source File: MockDaoSecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected void bindAuthenticationDAO(AnnotatedBindingBuilder<AuthenticationDAO> bind) {
   bind.toInstance(EasyMock.createMock(AuthenticationDAO.class));
   expose(AuthenticationDAO.class);
}
 
Example #20
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected void bindCredentialsHashingStrategy(AnnotatedBindingBuilder<CredentialsHashingStrategy> bind) {
   bind.to(Sha256CredentialsHashingStrategy.class);
}
 
Example #21
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected void bindPrincipalResolver(AnnotatedBindingBuilder<PrincipalResolver> bind) {
   bind.to(DefaultPrincipalResolver.class);
}
 
Example #22
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected void bindAuthorizationDAO(AnnotatedBindingBuilder<AuthorizationDAO> bind) {
   bind.to(NoopAuthorizationDAOImpl.class);
}
 
Example #23
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected void bindCacheManager(AnnotatedBindingBuilder<CacheManager> bind) {
   bind.to(MemoryConstrainedCacheManager.class);
}
 
Example #24
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected void bindSessionDAO(AnnotatedBindingBuilder<SessionDAO> bind) {
   bind.to(GuicedCassandraSessionDAO.class);
}
 
Example #25
Source File: PersonDAOSecurityModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@Override
protected void bindAuthenticationDAO(AnnotatedBindingBuilder<AuthenticationDAO> bind) {
   bind.to(PersonDAOImpl.class);
}
 
Example #26
Source File: GriefDefenderImplModule.java    From GriefDefender with MIT License 4 votes vote down vote up
protected <T> AnnotatedBindingBuilder<T> bindAndExpose(final Class<T> type) {
    this.expose(type);
    return this.bind(type);
}
 
Example #27
Source File: AbstractJerseyInstaller.java    From dropwizard-guicey with MIT License 3 votes vote down vote up
/**
 * Bind to guice context. Singleton scope will be forced if it's not disabled (
 * {@link ru.vyarus.dropwizard.guice.module.installer.InstallersOptions#ForceSingletonForJerseyExtensions}) and
 * if no explicit scope is declared with annotation on bean.
 *
 * @param binder guice binder
 * @param type   extension type
 */
protected void bindInGuice(final Binder binder, final Class<?> type) {
    final AnnotatedBindingBuilder<?> binding = binder.bind(type);
    if (isForceSingleton(type, false)) {
        // force singleton only if no explicit scope annotation present
        binding.in(Singleton.class);
    }
}
 
Example #28
Source File: SecurityModule.java    From arcusplatform with Apache License 2.0 votes vote down vote up
protected abstract void bindAuthenticationDAO(AnnotatedBindingBuilder<AuthenticationDAO> bind);