Skip to content

Modern example of spring security, and without deprecated classes. Utilizing Authentication, Authorizations, JWT tokens and other methods and techs.

Notifications You must be signed in to change notification settings

alpha-mo/SpringBootSecurityExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring boot security with JWT example

this example is NOT based on OAuth2


important to know

  • In this example I configure web-security with the new component-based configuration.
  • Please note that the WebSecurityConfigurerAdapter has been deprecated since Spring Boot v 2.7
  • I did not include any tests at the moment, as the intention was to demonstrate how to configure web-security with JWT.

About this example

This simple project is built with the idea in mind that we will be storing some users with different authorities in a database and use them to allow/deny access to some end points accordingly. the project has:

  • a simple Rest API to reach end-points.
  • a simple Entity POJO with it's services and repositories.
  • a security layer. Some dummy data is added using Java Faker

Dependencies:

Nothing fancy some basic dependencies:

Dependency artifactId version
Spring Data JPA spring-boot-starter-data-jpa
Spring Security spring-boot-starter-security
Spring Web spring-boot-starter-web
MySQL Connector mysql-connector-java
lombok lombok
Java Faker javafaker 1.0.2
auth0 JWT java-jwt 4.0.0

The workflow

  • Each user will have a list of roles wich will allow/deny access to end points accordingly.
  • authenticating will be user-name / password based.
  • authorization will be based on user's authorities using the access token.
  • the process will generate an access token and a refresh token
  • The user will be able to log in and get the tokens needed.
  • both acc/refresh tokens will have expiration time.

Next:?

next example will utilize the OAuth2 soon.

You can visit my portfolio to know more about me.

About

Modern example of spring security, and without deprecated classes. Utilizing Authentication, Authorizations, JWT tokens and other methods and techs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages