Coder Social home page Coder Social logo

nakebenihime / springboot-security-project Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 88 KB

This repository contains some basic security concepts using the springboot security dependency.

Java 100.00%
springboot-security java springboot basic-authentication form-based-authentication jwt-authentication mongodb

springboot-security-project's Introduction

SPRING BOOT SECURITY BASIC CONCEPTS

This repository contains some basic security concepts using the springboot security dependency. This repository has three tag versions (v1, v2, v3), each of them corresponds to a specific way to authenticate to the application.

v1 - BASIC HTTP AUTHENTICATION

  • refers to a simple authentication scheme built into the HTTP protocol.

v2 - FORM-BASED AUTHENTICATION

  • refers to the notion of a user to whom is given an editable "form" to be filled out and submitted to connect to any system or service.

v3 - JWT AUTHENTICATION

  • similar to session id technologies - it refers to a secure token-based authentication.

TECHNOLOGY STACK

COMPONENT TECHNOLOGY FOR MORE INFORMATION
Languages & Frameworks springboot https://spring.io/projects/spring-boot
Databases mongoDB https://www.mongodb.com/
Java Tools lombok maven https://projectlombok.org/ & https://maven.apache.org/
User Management and Authentication java-jwt https://github.com/auth0/java-jwt
Security spring security https://spring.io/projects/spring-security

PREREQUISITES

These instructions will allow you to get a copy of the project on your windows machine, you must have the following software correctly installed in order to build the project.

GETTING STARTED

Clone the application, run the following command:

git clone https://github.com/Nakebenihime/springboot-security-project.git

Run the following command to list the git tags (three git tags must appear) :

git tag -l
v1.0.0-HTTPBASIC
v2.0.0-FORM-BASED-AUTH
v3.0.0-JWT-AUTH

You can now switch to each of the git tags using the following command:

git checkout v1.0.0-HTTPBASIC |OR| v2.0.0-FORM-BASED-AUTH |OR| v3.0.0-JWT-AUTH

Generate a keystore:

keytool -genkeypair -alias bootsecurity -storetype PKCS12 -keyalg RSA -keysize 2048  -keystore bootsecurity.p12 -validity 3650

Configure SSL properties:

server:
port: 8443
ssl:
enabled: true
key-store: src/main/resources/bootsecurity.p12
key-store-password: bootsecurity
key-store-type: PKCS12
key-alias: bootsecurity

Build the application with the following command:

mvnw clean package

Run the application with the following command:

java -jar boot-security-project-1.0.0-HTTPBASIC.jar |OR| java -jar boot-security-project-2.0.0-FORM-BASED-AUTH.jar |OR| java -jar boot-security-project-3.0.1-SNAPSHOT.jar

or run with maven command:

mvnw spring-boot:run

##EXPLORE THE APPLICATION For each git tag (v1-...,v2-...,v3-...) you have three users (user, manager and admin); all these users have distinct roles/permissions in the application

USER ROLES/PERMISSIONS ACCESS
USER USER / "" profile/index
MANAGER MANAGER / "ACCESS_TEST1" profile/index & manager/index /api/public/test1
ADMIN ADMIN / "ACCESS_TEST1,ACCESS_TEST2" profile/index & manager/index & admin/index & /api/public/test1 & /api/public/test2

cURL - v3.0.0-JWT-AUTH

Retrieve JWT access token (change username and password to have alternate authorities and roles)

curl --location --request POST 'https://localhost:8443/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username":"user",
"password":"user123"
}'

GET test1 (resource available to all the authenticated users)

curl --location --request GET 'https://localhost:8443/api/public/test1' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNjA4NDA2NTkyfQ.dWptNWtBsvYC01IxRCuilkK1GaTy1ZQCbrk5lidGs4RYtI-RQkOKwYbyKeVeKgahtuWagAFtkXdIAy5Rt4CKwA'

GET reports (resource available to managers)

curl --location --request GET 'https://localhost:8443/api/public/manager/reports' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNjA4NDA2NTkyfQ.dWptNWtBsvYC01IxRCuilkK1GaTy1ZQCbrk5lidGs4RYtI-RQkOKwYbyKeVeKgahtuWagAFtkXdIAy5Rt4CKwA'

GET users (resource available to admins)

curl --location --request GET 'https://localhost:8443/api/public/admin/users' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ1c2VyIiwiZXhwIjoxNjA4NDA2NTkyfQ.dWptNWtBsvYC01IxRCuilkK1GaTy1ZQCbrk5lidGs4RYtI-RQkOKwYbyKeVeKgahtuWagAFtkXdIAy5Rt4CKwA'

springboot-security-project's People

Contributors

nakebenihime avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.