Skip to content

Demo project for Spring Boot Security OAuth2 With MySQL Database

Notifications You must be signed in to change notification settings

jigneshkhatri/spring-boot-security-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-boot-security-db

Demo project for Spring Boot Security OAuth2 With MySQL Database.

OAuth2 authentication and role based authorization for spring boot project, with user and client credentials stored in MySQL database. Tokens (access and refresh) are stored in database as well. Passwords are encrypted with BCrypt algorithm.

Libraries used:

  • Spring boot
  • Spring data JPA and Hibernate
  • Liquibase (for database management)
  • Spring security
  • Spring OAuth2

Database description:

Below are the main tables which will be used in authentication/authorization process.

  • users table: Contains basic user details (email and password) used for user to login. Here BCrypt encrypted passwords are stored.
  • roles table: Contains allowed roles.
  • user_role table: Mapping table to user and role.
  • oauth_client_details table: Contains client related details.
  • oauth_access_token table: Contains access tokens for authenticated users.
  • oauth_refreh_token table: Contains refresh tokens for authenticated users.

NOTE:

If you add more roles, you will also need to add those roles in RolesEnum and update antMatchers in ResourceServerConfig class.

Project configurations - application.properties:

  • Database configuration: You can modify database related configurations in application.properties.
  • /spring-security-demo/api is context path of this project. You can modify it as per you choice.

How to run this project:

To run the project, open the command-line at the project's root directory, and run this command: mvnw spring-boot:run. It will automatically create the database, required tables, and insert preliminary data.

Endpoints of interest:

References:

Mixture of below tutorials :)

About

Demo project for Spring Boot Security OAuth2 With MySQL Database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published