SpringSecurity : How to configure Spring Security with Spring boot

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

  1. Add the dependency in your build.gradle

  2. Run your application gradle bootRun for gradle and mvn spring:run for maven

Image

  1. 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

  1. Add the following in your application.properties
security.user.name=user
security.user.password=password
security.user.role=USER, ADMIN
  1. Using this approach you will be able to login to your application using the username and password defined by you.

  2. The default Roles assigned on login will be the one specified by you in properties file.

Also Read

No comments :

Post a Comment