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

Basic Spring Security Configurations

  • Step 1 : Add the dependency in your build.gradle
  • Step 2 : 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.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.

No comments :

Post a Comment