Java 如何仅在Spring Security上对特定URL强制使用https?
在我的spring安全应用程序中,我们使用java配置,如下所示。我只想用模式mydomain.com/secure/etc为那些URL配置https。但是其他URL模式应该保持不安全,即HTTP。以下是我在WebSecurity配置适配器中的代码Java 如何仅在Spring Security上对特定URL强制使用https?,java,spring,security,spring-security,Java,Spring,Security,Spring Security,在我的spring安全应用程序中,我们使用java配置,如下所示。我只想用模式mydomain.com/secure/etc为那些URL配置https。但是其他URL模式应该保持不安全,即HTTP。以下是我在WebSecurity配置适配器中的代码 http .authorizeRequests() .antMatchers("/non-secure/**").permitAll() .antMatchers("/secure/**").hasAuthority("use
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()