2012-04-15 38 views
1

因此,我能夠讓Vaidin獲得Apache Shiro與Guice(感謝ShiroWebModule)的合作。 Shiro註釋(@RequiresAuthentication,@RequiresPermission)僅適用於主Vaadin應用程序類和自定義類內。它們在CustomComponent/Window類中不起作用。Apache Shiro + Guice - 無法獲得註解工作

我試圖注入窗口類與供應商的應用程序類,通過injector.getInstance,它仍然無法正常工作......

我是新來吉斯和四郎,所以也許我失去了一些東西?

爲什麼它適用於其他自定義類?這工作正常(拋出異常)

public class TestClassImpl implements TestClass { 

    @Override 

    public void doSomeWork() { 
     //this will throw an exception as expected 
     test(); 
    } 

    @RequiresAuthentication 

    public void test() { 

    } 
} 

預期這不起作用(執行方法,在Apache四郎註釋被忽略):

public class LoginView extends CustomComponent { 

    public LoginWindow() { 
     setCompositionRoot(mainLayout); 
     //this will execture but it should not 
     test(); 
    } 

    @RequiresAuthentication 

    public void test() { 

    } 
} 

回答

2

使用這樣的註釋在運行時通常涉及AOP。

使用Spring AOP,你無法攔截自我來電:這是因爲Spring AOP的生成代理類,並攔截髮生在那些代理 - >它無法攔截到自己的電話。

我懷疑Guice AOP以同樣的方式工作。

NB:其中一個識別TestClass /默認地將Impl和LoginView之間的差異在於,識別TestClass實現一個接口;它可能是吉斯把接口代理和「普通班」代理不同的情況 - 我會嘗試改變的TestClass延長一個抽象類,看看會發生什麼在那裏。

+0

謝謝您的回覆。但是即使直接注入,TestClassImpl也可以工作,沒有接口。因此,這會不會引發異常(但應)'injector.getInstance(LoginView.class);'這按預期工作(會引發安全異常)\t'injector.getInstance(TestClassImpl.class);'。他們都在用@RequiresAuthentification註解的構造函數中調用一個方法。 – 2012-04-16 19:52:33

+0

好的,這裏有一個更基本的問題。 Guice不會在CustomComponents中注入任何類。我不知道爲什麼。這絕對應該工作,但我做錯了什麼。 – 2012-04-18 18:11:54

+0

更新。我有解決這個問題的辦法。只有構造函數注入在Components/Windows中工作(不知道爲什麼)。因此,我注入了我需要的服務類,並在裏面有Shiro註釋,這些都是可行的。我只需要編程檢查Vaadin組件/窗口類中的Shiro角色/權限。 – 2012-04-18 20:35:54