Project Spring with Security and Oauth2

This is a project template using Java and Spring Boot, configured with Spring Security and OAuth2. The project includes an Authorization Server for token generation and a Resource Server for authentication and authorization of requests, with token validation at the route level. The project uses the H2 database for data storage.

Requirements

  • JDK 21
  • Spring 3.3.0
  • Maven 3.8+

Project Structure

  1. config: Responsible for managing authentication and token issuance.

  2. controllers: Contains application controllers responsible for handling HTTP requests and returning appropriate responses.

  3. entities: Domain entities representing objects persisted in the database.

  4. projections: Projections used to efficiently transfer data for specific operations.

  5. repositories: Data repositories responsible for interacting with the database or other data sources.

  6. services: Application services containing business logic and coordinating interaction between controllers, repositories, and other layers.

Project Setup

  1. Clone the repository:

    git clone https://github.com/Rudersonvf/spring-security-oauth2.git
    cd seu-repositorio
  2. Import the project into your IDE:

    • For IntelliJ IDEA: File -> Open -> Select the project folder.
    • For Eclipse: File -> Import -> Existing Maven Projects -> Select the project folder.
  3. Start the project:

    • Run the project according to your IDE.

Postman Setup

  1. Endpoints:

    • [ Post ] Login: /oauth2/token
    • [ Get ] Admin request: /test/admin
    • [ Get ] User request: /test/user
    • [ Get ] Free request: /test/free
  2. Globals:

Fork collection in Postman:

Run In Postman

Autor

Ruderson Florentino

https://www.linkedin.com/in/rudersonvf

Licence

NPM