public void configure() { // setup security manager bindSecurityManager(bind(SecurityManager.class)); bindSessionManager(bind(SessionManager.class)); bindEnvironment(bind(Environment.class)); bindListener(BeanTypeListener.MATCHER, new BeanTypeListener()); bindEventBus(bind(EventBus.class)); bindListener(Matchers.any(), new SubscribedEventTypeListener()); bindListener(Matchers.any(), new EventBusAwareTypeListener()); final DestroyableInjectionListener.DestroyableRegistry registry = new DestroyableInjectionListener.DestroyableRegistry() { public void add(Destroyable destroyable) { ShiroModule.this.add(destroyable); } @PreDestroy public void destroy() { ShiroModule.this.destroy(); } }; bindListener(LifecycleTypeListener.MATCHER, new LifecycleTypeListener(registry)); expose(SecurityManager.class); expose(EventBus.class); configureShiro(); bind(realmCollectionKey()) .to(realmSetKey()); bind(DestroyableInjectionListener.DestroyableRegistry.class).toInstance(registry); BeanTypeListener.ensureBeanTypeMapExists(binder()); }
@PreDestroy public void destroy() { ShiroModule.this.destroy(); } };
public void add(Destroyable destroyable) { ShiroModule.this.add(destroyable); }
@Override protected void bindSecurityManager(final AnnotatedBindingBuilder<? super SecurityManager> bind) { super.bindSecurityManager(bind); final RedisCacheConfig redisCacheConfig = new ConfigurationObjectFactory(new ConfigSource() { @Override public String getString(final String propertyName) { return configSource.getString(propertyName); } }).build(RedisCacheConfig.class); // Magic provider to configure the cache manager if (redisCacheConfig.isRedisCachingEnabled()) { bind(CacheManager.class).toProvider(RedisShiroManagerProvider.class).asEagerSingleton(); } else { bind(CacheManager.class).toProvider(EhcacheShiroManagerProvider.class).asEagerSingleton(); } }
/** * This is the preferred manner to bind a realm. The {@link org.apache.shiro.mgt.SecurityManager} will be injected with any Realm bound * with this method. * * @return a binding builder for a realm */ protected final LinkedBindingBuilder<Realm> bindRealm() { Multibinder<Realm> multibinder = Multibinder.newSetBinder(binder(), Realm.class); return multibinder.addBinding(); }
@Override protected void bindSecurityManager(final AnnotatedBindingBuilder<? super SecurityManager> bind) { super.bindSecurityManager(bind); // Magic provider to configure the cache manager bind(CacheManager.class).toProvider(EhCacheManagerProvider.class).asEagerSingleton(); }
/** * Binds a key to use for injecting setters in shiro classes. * @param typeLiteral the bean property type * @param key the key to use to satisfy the bean property dependency * @param <T> */ protected final <T> void bindBeanType(TypeLiteral<T> typeLiteral, Key<? extends T> key) { BeanTypeListener.bindBeanType(binder(), typeLiteral, key); }
public void configure() { // setup security manager bindSecurityManager(bind(SecurityManager.class)); bindSessionManager(bind(SessionManager.class)); bindEnvironment(bind(Environment.class)); bindListener(BeanTypeListener.MATCHER, new BeanTypeListener()); bindEventBus(bind(EventBus.class)); bindListener(Matchers.any(), new SubscribedEventTypeListener()); bindListener(Matchers.any(), new EventBusAwareTypeListener()); final DestroyableInjectionListener.DestroyableRegistry registry = new DestroyableInjectionListener.DestroyableRegistry() { public void add(Destroyable destroyable) { ShiroModule.this.add(destroyable); } @PreDestroy public void destroy() { ShiroModule.this.destroy(); } }; bindListener(LifecycleTypeListener.MATCHER, new LifecycleTypeListener(registry)); expose(SecurityManager.class); expose(EventBus.class); configureShiro(); bind(realmCollectionKey()) .to(realmSetKey()); bind(DestroyableInjectionListener.DestroyableRegistry.class).toInstance(registry); BeanTypeListener.ensureBeanTypeMapExists(binder()); }
@Override protected void bindSecurityManager(final AnnotatedBindingBuilder<? super SecurityManager> bind) { super.bindSecurityManager(bind); final RedisCacheConfig redisCacheConfig = new ConfigurationObjectFactory(new ConfigSource() { @Override public String getString(final String propertyName) { return configSource.getString(propertyName); } }).build(RedisCacheConfig.class); // Magic provider to configure the cache manager if (redisCacheConfig.isRedisCachingEnabled()) { bind(CacheManager.class).toProvider(RedisShiroManagerProvider.class).asEagerSingleton(); } else { bind(CacheManager.class).toProvider(EhcacheShiroManagerProvider.class).asEagerSingleton(); } }
@Test public void testDestroy() throws Exception { final MockRealm mockRealm = createMock(MockRealm.class); final MyDestroyable myDestroyable = createMock(MyDestroyable.class); myDestroyable.destroy(); replay(myDestroyable); final ShiroModule shiroModule = new ShiroModule() { @Override protected void configureShiro() { bindRealm().to(MockRealm.class); bind(MyDestroyable.class).toInstance(myDestroyable); expose(MyDestroyable.class); } @Provides public MockRealm createRealm() { return mockRealm; } }; Injector injector = Guice.createInjector(shiroModule); injector.getInstance(MyDestroyable.class); shiroModule.destroy(); verify(myDestroyable); }
/** * This is the preferred manner to bind a realm. The {@link org.apache.shiro.mgt.SecurityManager} will be injected with any Realm bound * with this method. * * @return a binding builder for a realm */ protected final LinkedBindingBuilder<Realm> bindRealm() { Multibinder<Realm> multibinder = Multibinder.newSetBinder(binder(), Realm.class); return multibinder.addBinding(); }
public void add(Destroyable destroyable) { ShiroModule.this.add(destroyable); }
@PreDestroy public void destroy() { ShiroModule.this.destroy(); } };
/** * Binds a key to use for injecting setters in shiro classes. * @param typeLiteral the bean property type * @param key the key to use to satisfy the bean property dependency * @param <T> */ protected final <T> void bindBeanType(TypeLiteral<T> typeLiteral, Key<? extends T> key) { BeanTypeListener.bindBeanType(binder(), typeLiteral, key); }