protected final void bindShiroInterceptorWithHierarchy(final AnnotationMethodInterceptor methodInterceptor) { bindInterceptor(Matchers.any(), new AbstractMatcher<Method>() { public boolean matches(final Method method) { final Class<? extends Annotation> annotation = methodInterceptor.getHandler().getAnnotationClass(); return resolver.getAnnotationFromMethod(method, annotation) != null; } }, new AopAllianceMethodInterceptorAdapter(methodInterceptor)); } }
@Override protected void configureInterceptors(final AnnotationResolver resolver) { super.configureInterceptors(resolver); if (!KillBillShiroModule.isRBACEnabled()) { return; } final PermissionAnnotationHandler permissionAnnotationHandler = new PermissionAnnotationHandler(); // Inject the Security API requestInjection(permissionAnnotationHandler); final PermissionAnnotationMethodInterceptor methodInterceptor = new PermissionAnnotationMethodInterceptor(permissionAnnotationHandler, resolver); bindShiroInterceptorWithHierarchy(methodInterceptor); }
@Test(groups = "fast") public void testAOPForClass() throws Exception { // Make sure it works as expected without any AOP magic final IAopTester simpleTester = new AopTester(); try { simpleTester.createRefund(); } catch (Exception e) { Assert.fail(e.getLocalizedMessage()); } // Now, verify the interception works configureShiro(); // Shutdown the cache manager to avoid duplicate exceptions CacheManager.getInstance().shutdown(); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new KillBillShiroModule(configSource), new KillBillShiroAopModule(), new SecurityModule(), new AbstractModule() { @Override protected void configure() { bind(IDBI.class).toInstance(Mockito.mock(IDBI.class)); } }); final AopTester aopedTester = injector.getInstance(AopTester.class); verifyAopedTester(aopedTester); }
@Test(groups = "fast") public void testAOPForInterface() throws Exception { // Make sure it works as expected without any AOP magic final IAopTester simpleTester = new AopTesterImpl(); try { simpleTester.createRefund(); } catch (Exception e) { Assert.fail(e.getLocalizedMessage()); } // Now, verify the interception works configureShiro(); // Shutdown the cache manager to avoid duplicate exceptions CacheManager.getInstance().shutdown(); final Injector injector = Guice.createInjector(Stage.PRODUCTION, new KillBillShiroModule(configSource), new KillBillShiroAopModule(), new SecurityModule(), new AbstractModule() { @Override public void configure() { bind(IDBI.class).toInstance(Mockito.mock(IDBI.class)); bind(IAopTester.class).to(AopTesterImpl.class).asEagerSingleton(); } }); final IAopTester aopedTester = injector.getInstance(IAopTester.class); verifyAopedTester(aopedTester); }
@Override protected void configure() { super.configure(); install(new GuicyKillbillTestNoDBModule()); install(new MockNonEntityDaoModule()); install(new MockGlobalLockerModule()); install(new InMemoryBusModule(configSource)); install(new MockNotificationQueueModule(configSource)); installAuditMock(); install(new KillBillShiroModule(configSource)); install(new KillBillShiroAopModule()); install(new SecurityModule()); } }