在我的 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()
关于java - 如何仅在 Spring Security 上对某些 URL 强制使用 https?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30306898/