Spring Security 3.1.3请求查询字符串被剥离

use*_*600 34 java spring-security

我正在保护我的应用程序使用,Spring Security 3.1.3并且我要求允许用户通过第三方应用程序中的链接登录.

但是,第三方应用程序中的链接将重定向到特定资源,而不是重定向到登录页面,其中用户希望访问的资源将被定义为查询字符串参数.因此,例如,链接的形式为//server.com/app/build/panel.jsp?resourceid ='blah'`

当用户单击此链接时,应将它们带到我的Spring Security配置中定义的登录页面,如果经过身份验证,则应将其重定向到包含querystring参数的原始链接.querystring参数对用户应如何进行身份验证没有影响,它仅仅是资源的id.

现在,除了查询字符串之外,这一切都运行正常,在进入请求处理流程之前,它被Spring Security剥离.这在Spring Security的调试输出中显示;

org.springframework.security.web.savedrequest.HttpSessionRequestCache:DefaultSavedRequest已添加到Session:DefaultSavedRequest [ http://server.com:8080/app/build/panel.jsp]

即,查询字符串未保存?resourceid ='blah'已被删除.

注意,我目前正在使用Ant匹配.我没有必要实际匹配查询字符串.

在Spring Security的早期版本中,看起来你可以通过使用BeanPostProcessor来影响这种行为,根据这篇文章, Spring Security - Url请求参数规则被忽略.但是从Spring Security 3.1.3中删除了DefaultFilterInvocationSecurityMetadataSource.setStripQueryStringFromUrls()方法.

如何配置Spring Security以不从原始请求中删除查询字符串?那么当用户在登录到原始URL后被重定向时,将保留querystring参数?

非常感谢霍华德

jpg*_*z18 0

基本上是成功处理程序。

你可以看一下这个例子:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
      .authorizeRequests()
      .antMatchers("/login*")
      .permitAll()
      .anyRequest()
      .authenticated()
      .and()
      .formLogin()
      .successHandler(new RefererAuthenticationSuccessHandler());
}
Run Code Online (Sandbox Code Playgroud)

有关它的更多信息: http: //www.baeldung.com/spring-security-redirect-login