@Test public void testConfigure() { final MockRealm mockRealm = createMock(MockRealm.class); AuthenticationToken authToken = createMock(AuthenticationToken.class); AuthenticationInfo info = new SimpleAuthenticationInfo("mockUser", "password", "mockRealm"); expect(mockRealm.supports(authToken)).andReturn(true); expect(mockRealm.getAuthenticationInfo(authToken)).andReturn(info); replay(mockRealm); Injector injector = Guice.createInjector(new ShiroModule() { @Override protected void configureShiro() { bindRealm().to(MockRealm.class); } @Provides public MockRealm createRealm() { return mockRealm; } }); SecurityManager securityManager = injector.getInstance(SecurityManager.class); assertNotNull(securityManager); SecurityUtils.setSecurityManager(securityManager); final Subject subject = new Subject.Builder(securityManager).buildSubject(); securityManager.login(subject, authToken); verify(mockRealm); }
public void configure() { 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()); }
ShiroModule extends PrivateModule implements Destroyable { public void configure() { 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()); } }
ShiroModule extends PrivateModule implements Destroyable { public void configure() { 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()); }  }
ShiroModule extends PrivateModule implements Destroyable { public void configure() { 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()); }  void configure(); final void destroy(); void add(Destroyable destroyable); }
ShiroModule extends PrivateModule implements Destroyable { public void configure() { 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()); }  void configure(); final void destroy(); void add(Destroyable destroyable);  }