【问题标题】:How to force https on certain URL only on Spring Security?如何仅在 Spring Security 上对某些 URL 强制使用 https?
【发布时间】:2015-07-30 04:13:08
【问题描述】:

在我的 spring 安全应用程序中,我们使用如下 java 配置。我只想为模式为 mydomain.com/secure/etc 的那些 URL 配置 https。然而,其他 url 模式应该保持不安全,即 HTTP。以下是我在 WebSecurityConfigurerAdapter 中的代码

http
    .authorizeRequests()
    .antMatchers("/non-secure/**").permitAll()
    .antMatchers("/secure/**").hasAuthority("user")
    .and()
    .requiresChannel()
    .antMatchers("/secure/**").requiresSecure()

我应该只保护带有模式 mydomain.com/secure/etc 的 url。

但是使用上面的配置,系统中的所有页面都被重定向到https,包括/non-secure/**,而不仅仅是那些匹配的。有人可以帮忙吗?

【问题讨论】:

    标签: java spring security spring-security


    【解决方案1】:

    您可以尝试以下方法吗?

    http
     .authorizeRequests()
     .antMatchers("/non-secure/**").permitAll()
     .antMatchers("/secure/**").hasAuthority("user")
     .and().requiresChannel().antMatchers("/non-secure/**").requiresInsecure()
     .and().requiresChannel().antMatchers("/secure/**").requiresSecure()
    

    【讨论】:

      猜你喜欢
      • 2015-06-22
      • 2011-03-19
      • 2012-07-11
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 2011-07-24
      • 1970-01-01
      • 2011-10-25
      相关资源
      最近更新 更多