SPRING IN ACTION 第4版筆記-第九章Securing web applications-011-把敏感資訊請求轉為https(requiresChannel())

來源:互聯網
上載者:User

標籤:

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 .

SPRING IN ACTION 第4版筆記-第九章Securing web applications-011-把敏感資訊請求轉為https(requiresChannel())

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.