Securing web applications-011-把敏感信息请求转为https(requiresChannel())
Posted shamgod
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Securing web applications-011-把敏感信息请求转为https(requiresChannel())相关的知识,希望对你有一定的参考价值。
1.把包含敏感信息的请求转为https请求,则较为安全,但如何只把有需要安全的请求转为https,而不是不加分辩就把所有请求都转为https呢?可以用requiresChannel()
1 @Override 2 protected void configure(HttpSecurity http) throws Exception { 3 http 4 .authorizeRequests() 5 .antMatchers("/spitter/me").hasRole("SPITTER") 6 .antMatchers(HttpMethod.POST, "/spittles").hasRole("SPITTER") 7 .anyRequest().permitAll(); 8 .and() 9 .requiresChannel() 10 .antMatchers("/spitter/form").requiresSecure(); 11 }
Any time a request comes in for /spitter/form, Spring Security will see that it requires a secure channel (per the call to requiresSecure() ) and automatically redirect the request to go over HTTPS .
Conversely, some pages don’t need to be sent over HTTPS . The home page, for example, doesn’t carry any sensitive information and should be sent over HTTP . You can declare that the home page always be sent over HTTP by using requires-Insecure() instead of requiresSecure :.antMatchers("/").requiresInecure();If a request for / comes in over HTTPS , Spring Security will redirect the request to flow over the insecure HTTP .
以上是关于Securing web applications-011-把敏感信息请求转为https(requiresChannel())的主要内容,如果未能解决你的问题,请参考以下文章
SPRING IN ACTION 第4版笔记-第九章Securing web applications-004-对密码加密passwordEncoder
SPRING IN ACTION 第4版笔记-第九章Securing web applications-003-把用户数据存在数据库
SPRING IN ACTION 第4版笔记-第九章Securing web applications-001-SpringSecurity简介(DelegatingFilterProxyAbstr(
SPRING IN ACTION 第4版笔记-第九章Securing web applications-002-把用户数据存在memory里(AuthenticationManagerBuilder(
SPRING IN ACTION 第4版笔记-第九章Securing web applications-008-使用非关系型数据库时如何验证用户(自定义UserService)