Skip to content

Spring Security Integration with Spring Boot Appliction. Implemented Basic, Form Based and JWT Authentication

Notifications You must be signed in to change notification settings

manasacharyya25/SpringSecurityWithJwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringSecurityWithJwt

About

Demo Application for integrating Spring Security with Spring Boot Application, that increments gradually from Basic Authentication to Form Based Authentication and finally JWT Authentication.

Follow Commit History to understand the incremental changes made in the application.

Concepts Explored

Usage

Prerequisites

  • Java 8
  • PostgreSQL (Required only if you wish to use Persistent DB. Else Application works fine with H2 in-memory DB)

Build and Deploy Project

  • Clone JwtAuthentication Branch
  • In Root Directory, Execute
    			gradlew build
    

    This will pull all project dependencies and build the Java Executable

  • Once Build Completes, Execute
    			gradlew bootRun
    

    to start the application. The application will be hosted at http://localhost:8080

Application Details

    The application by default works with in-memory H2 Database. To change this behaviour and use PostgreSQL, steps to follow:
  • In build.gradle under dependencies, comment out
  •       runtimeOnly 'com.h2database:h2'
    
  • In build.gradle under dependencies, uncomment out
  • 	runtimeOnly 'org.postgresql:postgresql'
    
  • Inclue Database Configuration in application.yml
  • 	datasource:  
    		url: jdbc:postgresql://localhost:5431/<Database Name>  
    		username: postgres  
    		password: Password
    

Test using Postman

Upon Application Statup, the database is seeded with 2 user details. Check resources/data.sql for more details.

  • Step 1: Obtain JWT Token
  • Perform POST Request to http://localhost:8080/authenticate. Returns a JWT Token in Response.

    image

  • Step 2: Access Protected Resource with JWT Token
  • Perform GET Request to http://localhost:8080/home. Add JWT Token obtained in previous step, as Bearer Token under Authorization Tab of Postman Request.

    image

  • You should get 200OK Response, if you provided the correct JWT Token. Else 403 Forbidden Response.
  • Author

    Manas Acharyya

         linkedin.com/in/manasacharyya25

About

Spring Security Integration with Spring Boot Appliction. Implemented Basic, Form Based and JWT Authentication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •