1 installation
First put the Spring Boot security starter dependency package into pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
When the application starts, Spring Boot's automatic configuration function will detect that Spring Security is in the classpath, and then it will initialize some basic security configurations.
2 Basic usage
After the application is successfully launched, enter http://127.0.0.1:8080 in the browser, and you will enter the login page:
The default user name is user, and the password is randomly generated. It can be found in the application log file and looks like:
By adding Spring Security to the application, we will immediately have the following security features:
-
All HTTP request paths require authentication;
-
Authentication is achieved through the login page.
-
The login account name is user and there is only one.
The following functions can be achieved with Spring Security:
-
User authentication through a custom login page;
-
You can define which certain request paths do not require verification, and some request paths require authentication. You can customize the security rules.