我已經實現了Jaas登錄模塊,以執行身份驗證。我必須訪問數據庫以檢索此模塊中的用戶/傳遞信息。從jaas訪問spring上下文LoginModule
在同一個項目中,實現了一些DAO bean,但從jaas登錄模塊訪問Spring上下文來檢索DAO bean是不可能的。
¿任何人都可以幫助我嗎?
我正在使用Spring Security將Jaas集成到我的應用程序中。
我已經實現了Jaas登錄模塊,以執行身份驗證。我必須訪問數據庫以檢索此模塊中的用戶/傳遞信息。從jaas訪問spring上下文LoginModule
在同一個項目中,實現了一些DAO bean,但從jaas登錄模塊訪問Spring上下文來檢索DAO bean是不可能的。
¿任何人都可以幫助我嗎?
我正在使用Spring Security將Jaas集成到我的應用程序中。
如果您有權訪問LoginModule,只需添加接口ApplicationContextAware和LoginModule的bean定義即可。當應用程序啓動時,上下文將在模塊中可用。
public class LoginModule implements ApplicationContextAware {
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
Javadoc文檔接口: http://static.springsource.org/spring/docs/3.0.5.RELEASE/api/org/springframework/context/ApplicationContextAware.html
這是行不通的,至少在Jetty 9中是這樣。applicationContext爲null – 2012-12-12 01:01:11
@JuanCalero - ApplicationContext也必須是靜態的。這也是出於同樣的原因,其他bean必須是靜態的,如果你想在LoginModule中使用它們 - 實例化由JAAS執行,所以Spring的依賴注入不會引入。 – mmalmeida 2013-07-11 14:53:44
你試過SecurityContextHolder.getContext()?這是什麼在您的jaas登錄模塊中返回? – 2010-09-23 15:53:25