[英]How to use the spring-security filters without an application context?
我想直接使用java代碼中沒有spring應用程序上下文(或spring容器)的spring-security web-filters。
這可能嗎? 我可以直接調用不同的彈簧實時循環方法嗎?如果有的話,是否有一個如何做到這一點的樣本(需要注意哪些不同的接口及其排序)?
我想在沒有spring應用程序上下文的情況下使用spring-security web-filters
你不能。
因為在web.xml
定義過濾器鏈代理時:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
DelegatingFilterProxy
實際上希望在那里找到您的contextConfigLocation
和有效的配置文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- This must be valid otherwise your .war deployment will fail -->
<param-value>WEB-INF/spring-contexts/spring-contexts.xml</param-value>
</context-param>
我認為這是可能的,但它不值得。
Spring是一個復雜的框架,可以隔離您配置Java應用程序的負擔。 你為什么要在沒有Spring的情況下使用Spring?
關於你的問題,以前的Spring安全性Acegi聲稱可以在沒有Spring的情況下使用。
所以你可以嘗試,但你的主要問題是在服務器啟動時加載整個應用程序。 您需要復制包含ContextLoaderListener的功能。
嘗試創建自己的偵聽器而不是
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
然后為你的應用程序配置主servlet(因為我認為你不想使用Spring MVC)和Simeon所說的安全過濾器。
還有祝你好運。
或者,您可以嘗試Apache SHIRO
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.