java - 如何仅在 Spring Security 上对某些 URL 强制使用 https?

标签 java spring security 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()

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

相关文章:

java - 在Java中将double转换为float

java - 使用 Unitils 针对 Postgres 数据库运行单元测试时出现 NullPointerException

android - Android 应用中使用 RecognizerIntent 的数据安全性

java - “Your security settings have blocked a local application from running” Java 8

c++ - 获取所有 Windows 内核对象及其安全权限

java - 如何自动查找Java字节码中的相似之处?

java - 如何解决 WebLogic 服务器 BEA-000117 和 BEA-101162 错误?

java - Recyclerview 加载速度很慢

json - 为 2 个 Controller 配置 2 个不同的 MessageConverter

java - 我应该或者可以在 EJB 中使用 Spring