如何仅在 Spring 安全性上对某些 URL 强制使用 https?
How to force https on certain URL only on Spring Security?
在我的 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/**
,而不仅仅是那些匹配项。有人可以帮忙吗?
您可以尝试以下方法吗?
http
.authorizeRequests()
.antMatchers("/non-secure/**").permitAll()
.antMatchers("/secure/**").hasAuthority("user")
.and().requiresChannel().antMatchers("/non-secure/**").requiresInsecure()
.and().requiresChannel().antMatchers("/secure/**").requiresSecure()
在我的 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/**
,而不仅仅是那些匹配项。有人可以帮忙吗?
您可以尝试以下方法吗?
http
.authorizeRequests()
.antMatchers("/non-secure/**").permitAll()
.antMatchers("/secure/**").hasAuthority("user")
.and().requiresChannel().antMatchers("/non-secure/**").requiresInsecure()
.and().requiresChannel().antMatchers("/secure/**").requiresSecure()