我试图通过任何渠道提供所有静态资源(css、javascript 和图像),但无法让它与.anyRequest().requiresInsecure()
:
@Configuration
@EnableWebMvcSecurity
@PropertySource("classpath:security.properties")
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Value("${security.auth_urls}")
private String[] authUrls;
@Value("${security.secured_urls}")
private String[] securedUrls;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers(authUrls).authenticated()
.and()
.formLogin()
.loginPage("/login.html")
.permitAll()
.and()
.logout()
.logoutUrl("/logout.html")
.permitAll()
.and()
.requiresChannel()
.antMatchers("/resources/**,/res/**").requires(ChannelDecisionManagerImpl.ANY_CHANNEL)
.antMatchers(securedUrls).requiresSecure()
.anyRequest().requiresInsecure();
}
// ...
}
注释掉的时候.anyRequest.requiresInsecure()
有用。
我想使用 HTTPS 提供特定页面,使用 HTTP 提供所有其他页面,并使用两者提供静态资源。
在我的应用程序中,我需要使主页网址不安全(需要 http),而其他网址则需要安全(仅限 https)。我设法通过遵循下一个命令来做到这一点:
...
.and().requiresChannel().antMatchers(homeUrls).requiresInsecure()
.and().requiresChannel().anyRequest().requiresSecure()
...
即首先是允许的规则(不安全|两者),然后是禁止的规则(仅安全)。
HTH
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)