SPRING in ACTION 4th Note-Chapter Nineth Securing Web Applications-011-to convert sensitive information requests to HTTPS (Requireschannel ())

Source: Internet
Author: User

1. It is safer to turn a request that contains sensitive information into an HTTPS request, but how do I turn all requests to HTTPS only if there is a request for security? can be used Requireschannel ()

1 @Override2 protected voidConfigure (Httpsecurity http)throwsException {3 http4 . Authorizerequests ()5. Antmatchers ("/spitter/me"). Hasrole ("Spitter").)6. Antmatchers (Httpmethod.post, "/spittles"). Hasrole ("Spitter")7 . Anyrequest (). Permitall ();8 . and ()9 . Requireschannel ()Ten. Antmatchers ("/spitter/form"). Requiressecure (); One}

Any time a request comes in For/spitter/form, Spring Security would see that it requiresa secure channel (per the call to Requiressecure ()) and automatically redirect therequest to go over HTTPS.
Conversely, some pages don ' t need to being sent over HTTPS. The home page, forexample, doesn ' t carry any sensitive information and should is sent over HTTP. Youcan declare that the home page is always being sent over HTTP by using requires-Insecure () instead of requiressecure:. Antmatchers ("/"). Requiresinecure ();If a request for/comes in over HTTPS, Spring Security would redirect the request toflow over the insecure HTTP.

SPRING in ACTION 4th Note-Chapter Nineth Securing Web Applications-011-to convert sensitive information requests to HTTPS (Requireschannel ())

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.