Coder Social home page Coder Social logo

romasszhs / springsecurity-jwt-vue-deom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from puzhiweizuishuai/springsecurity-jwt-vue-deom

0.0 1.0 0.0 3.88 MB

A demonstration of stateless JWT authentication with Spring Security, Spring Boot and Vue js

License: MIT License

Java 68.16% JavaScript 3.92% HTML 0.55% Vue 27.38%

springsecurity-jwt-vue-deom's Introduction

JWT Spring Boot Security

Chinese Documents 中文文档

About

This is a demonstration of stateless token-based authentication using JSON Web Token and CSRF protection, Spring Security, Spring Boot and Vue js.

Technology Stack

Component Technology
Frontend Vue.js 2
Backend (REST) SpringBoot (Java)
Security Token Based (Spring Security, JJWT, CSRF)
Client Build Tools vue-cli, Webpack, npm
Server Build Tools Maven

Quick start

Run Environment: Java11, Node 12, Maven3

Clone this project

git clone https://github.com/PuZhiweizuishuai/SpringSecurity-JWT-Vue-Deom.git

Run back end server

cd spring-security-jwt
mvn clean package

Then

java -jar target/security-0.0.1-SNAPSHOT.jar

Run front end server

cd vue
npm install

Then

npm run serve

Final

Open

http://127.0.0.1:8080

Screenshots

主页

登陆

管理员页

Security

JWT token

To generating and verifying JWT I use JJWT. JJWT – a self-contained Java library providing end-to-end JSON Web Tokens creation and verification.

JWT storing strategy

We have a couple of options where to store the token:

HTML5 Web Storage (localStorage or sessionStorage) Cookies

Main problem of Web Storage

It is accessible through JavaScript on the same domain. This means that any JavaScript running on your site will have access to web storage, and because of this can be vulnerable to cross-site scripting (XSS) attacks.

So, to prevent XSS I store the JWT token in a Http-Only/Secure cookie. Cookies, when used with the HttpOnly cookie flag, are not accessible through JavaScript, and are immune to XSS.

CSRF attack

However, cookies are vulnerable to a different type of attack: cross-site request forgery (CSRF). A CSRF attack is a type of attack that occurs when a malicious web site, email, or blog causes a user’s web browser to perform an unwanted action on a trusted site on which the user is currently authenticated.

To prevent CSRF attacks, we must create an extra Javascript readable cookie which is called: XSRF-TOKEN. This cookie must be created when the user is logged in and should contain a random, un-guessable string. Every time the JavaScript application wants to make a request, it will need to read this token and send it along in a custom HTTP header.

Reference document

Spring Security Reference

Vue.js

Dependency software

mavonEditor

element ui

Copyright and license

The code is released under the MIT license.

springsecurity-jwt-vue-deom's People

Contributors

puzhiweizuishuai 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.