Home > other >  Import and use a spring security project in a spring boot project
Import and use a spring security project in a spring boot project

Time:12-18

I'm a beginner in Spring Framework. I created in two separate projects:

  • Project "A" for Spring Security and JWT with a DB for User, Permission, Role, etc. Used for authentication and permissions;
  • Project "B" for Spring Boot with a DB for business tables. Used as a backend for a web-app;

Both projects have controllers and starters (do not import).

I would like to know how to use authentication check ( JWTFilter ) and permissions ( PermissionEvaluator ) from the security project in the backend project. In the future, I want to use same spring security project for multiple spring boot projects.

If necessary, I can add the basic structure (packages) of each project.

AGGIORNAMENTO

After so much research, Should I separate Spring Security from Spring Boot project and Spring Boot configure and use two data sources threads were very helpful in solving my problem.

However, in my case I didn't need to diversify the dataSource because the DB is unique but with a different schema for the business and security tables. Then, I added the "schema" key to the spring @Table annotation. Also, to solve the problem for visibility of the repositories and entities I added the spring annotations @ComponentScan, @EnableJpaRepository and @EntityScan

CodePudding user response:

You have two approaches to implement your project:

  1. Deploy all packages of project B in the project A. this approach appropriate for small project.
  2. Similar the approach 1 use the multi module architecture that is a clean way to implement. but in this approach you must set basic package in all of the modules
  • Related