Skip to content
Advertisement

how to configure spring security for spring boot project

I’m trying to make a web application that uses: SpringBoot, Mysql, JDBC , MVC, DAO Thymeleaf, IntelliJ

And I’m trying to figure out how Spring security works (which I’m having a lot of difficulty with). My views are organized as follows:

JavaScript

I would like to do that unidentified users can access all views except those contained in “userOnly” and that my “loginPage” page is used as the login page.

If I understood correctly, I must create a class that inherits from “WebSecurityConfigurerAdapter”. What I have done. And then configure “configure”, which I can’t do correctly 🙁

JavaScript

Sorry if my questions seems strange but english is not my first language

Advertisement

Answer

As of Spring-Boot 2.7 the use of WebSecurityConfigurerAdapter is deprecated. If you’re using Spring-Boot 2.6 or older the other answers might suit you better.

To my best knowledge the recommended way for defining security config in Spring-Boot 2.7 is as follows:

JavaScript

The use of web.ignoring() in the answer from voucher_wolves is, I believe, not recommended, instead one should add those cases to http.mvcMatcher().permitAll(). On a side note, I would personally recommend whitelisting the public pages and adding authentication to everything else, (for example a public folder). This way if you forget to add security to a link it’s not public by default.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement