How to integrate Spring Security with Spring boot
Add the following dependency in your build.gradle
compile('org.springframework.boot:spring-boot-starter-security')
Basic Spring Security Configurations
Add the dependency in your build.gradle
Run your application gradle bootRun for gradle and mvn spring:run for maven
- The default username is user and the password will be printed in the logs as shown in the image above. So in this case you can login using
username = user
password = // printed in logs
Note
A new password will be created each time the application restarts.
Spring Security Configurations with defined username and password
- Add the following in your application.properties
security.user.name=user
security.user.password=password
security.user.role=USER, ADMIN
Using this approach you will be able to login to your application using the username and password defined by you.
The default Roles assigned on login will be the one specified by you in properties file.
Also Read
- Configure Spring Security with Spring boot
- Configure JDBC Authetication using MYSQL Query
- Authenticate User with Custom UserDetailsService
- Implement Role Hierarchy with In-Memory Authentication
- How to list the User Authorities in Controller,Filter and Services
- Disable Session Creation for Stateless Authentication
Comments
Post a Comment