Is it possible to use a different Spring Security AuthenticationProvider in different servlets, same WAR?

杀马特。学长 韩版系。学妹 提交于 2019-12-24 22:28:21

问题


I have a single WAR that runs two servlets. One provides AMF remoting to Flex clients and other SOAP/HTTP to web service clients. I currently have Spring Security configured to authenticate the Flex clients using DaoAuthenticationProvider. However, I'd like to use a different authentication provide for the SOAP/HTTP. Possibly basic authentication or some other form.

Is it possible? or do I need two WARs?


回答1:


I think you'll run into problems issues with instantiating two security filter chains. The problem is that the <http> element constructs a security filter chain with a hard-wired bean name ("springSecurityFilterChain"). If you have more than one active <http> element in the webapp's spring configs, this is likely to fail.

In theory you could work around this by not using the SpringSecurity namespace and configuring the filter chains "by hand" using plain Spring XML wiring of the SpringSecurity classes. In practice, configuring SpringSecurity that way is hard.




回答2:


You might be able to start two separate securityChains, I don't know if you'll run into the issues Stephen outlines.

If you filter on two different url patterns corresponding to the two servlet url patterns you should be able to filter appropriately.

<filter> 
    <filter-name>flexSpringSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>flexSpringSecurityFilterChain</filter-name> 
    <url-pattern>/messagebroker/*</url-pattern> 
</filter-mapping>

<filter> 
    <filter-name>webSpringSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>webSpringSecurityFilterChain</filter-name> 
    <url-pattern>/web/*</url-pattern> 
</filter-mapping>


来源:https://stackoverflow.com/questions/3766004/is-it-possible-to-use-a-different-spring-security-authenticationprovider-in-diff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!