忽略Spring Security SavedRequest中的WebSocket连接。

29

我有一个使用spring-security-core插件和Atmosphere框架的Grails应用程序。

如果我从打开了WebSocket连接的页面注销,那么Spring Security会将WebSocket连接的URL保存为SavedRequest。

DEBUG savedrequest.HttpSessionRequestCache  - DefaultSavedRequest added to Session: DefaultSavedRequest[http://localhost:8080/formx/formX/update]
DEBUG savedrequest.HttpSessionRequestCache  - DefaultSavedRequest added to Session: DefaultSavedRequest[http://localhost:8080/formx/formX/notifications/?X-Atmosphere-Transport=close&X-Atmosphere-tracking-id=b5d8fde4-d950-41fd-9b49-02e06799a36f&conversationId=988080042]

日志中的第一条记录具有正确的SavedRequest值,但是不知何故它被Atmosphere WebSocket连接覆盖了。

我该如何告诉Spring Security不要将Atmosphere WebSocket连接用作SavedRequest?

我猜可以使用一些Atmosphere Protocol Specific Header来区分连接。


1
在 Atmosphere 处理程序上添加“无安全性”怎么样:security:http<security:intercept-url pattern="**/X-Atmosphere-Transport**" access="none"/></security:http> - willome
你好,试图清理未回答的问题。你解决了吗?也许你可以回答自己的问题。 - Neoryder
不好意思,我没有解决方案。 - Aram Arabyan
1个回答

1
在Java配置中,您可以设置RequestMatcher,然后就很容易了。
在WebSecurityConfigurerAdapter中:
protected void configure(HttpSecurity http) {
    HttpSessionRequestCache cache = new HttpSessionRequestCache(); //this one is used by default
    cache.setRequestMatcher(AnyRequestMatcher.INSTANCE); //change the request matcher, so it do not match your Atmosphere requests
    http.requestCache().requestCache(cache);
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接