All Projects → alexatiks → spring-security-jwt-csrf

alexatiks / spring-security-jwt-csrf

Licence: MIT License
A demonstration of stateless JWT authentication with Spring Security, Spring Boot and Vue js

Programming Languages

java
68154 projects - #9 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to spring-security-jwt-csrf

Jwt Spring Security Jpa
Backend MVP showcasing JWT (Json Web Token) authentication with multiple login, timeout / refresh / logout (with in memory invalidation) using Spring Security & MySQL JPA.
Stars: ✭ 202 (+225.81%)
Mutual labels:  spring-security, jwt-authentication
TASK-Management-System
Spring Boot and Angular 7 web application for task management .
Stars: ✭ 34 (-45.16%)
Mutual labels:  spring-security, jwt-authentication
angular-11-spring-boot-jwt-authentication
Angular 11 Spring Boot JWT Authentication example with Authorization | User Registration & Login
Stars: ✭ 62 (+0%)
Mutual labels:  spring-security, jwt-authentication
Clean Architecture Delivery Example
A example of clean architecture in Java 8 and Spring Boot 2.0
Stars: ✭ 140 (+125.81%)
Mutual labels:  spring-security, jwt-authentication
jersey-jwt-springsecurity
Example of REST API with JWT authentication using Spring Boot, Spring Security, Jersey and Jackson.
Stars: ✭ 44 (-29.03%)
Mutual labels:  spring-security, jwt-authentication
Javasecurity
Java web and command line applications demonstrating various security topics
Stars: ✭ 182 (+193.55%)
Mutual labels:  spring-security, csrf
spring-boot-login-example
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example
Stars: ✭ 50 (-19.35%)
Mutual labels:  spring-security, jwt-authentication
Spring Boot Spring Security Jwt Authentication
Spring Boot + Security: Token Based Authentication example with JWT, Authorization, Spring Data & MySQL
Stars: ✭ 292 (+370.97%)
Mutual labels:  spring-security, jwt-authentication
www-project-csrfguard
The aim of this project is to protect Java applications against CSRF attacks with the use of Synchronizer Tokens
Stars: ✭ 43 (-30.65%)
Mutual labels:  csrf, csrf-protection
spring-examples
Starter projects with Spring using Java and Kotlin. Contains modules that covers Security with JWT, Spring with Kotlin, Dependency injection simplified etc.
Stars: ✭ 33 (-46.77%)
Mutual labels:  spring-security, jwt-authentication
Webfluxtemplate
Spring Webflux template application with working Spring Security, Web-sockets, Rest, Web MVC, and Authentication with JWT.
Stars: ✭ 107 (+72.58%)
Mutual labels:  spring-security, jwt-authentication
okta-spring-boot-react-crud-example
Simple CRUD with React and Spring Boot 2.0
Stars: ✭ 214 (+245.16%)
Mutual labels:  csrf, csrf-protection
Simplemall
基于SpringCloud的微服务架构实战案例项目,以一个简单的购物流程为示例,融合spring cloud 相关组件,如spring-cloud-netflix、swagger等
Stars: ✭ 687 (+1008.06%)
Mutual labels:  spring-security, jwt-authentication
Spring Webflux Security Jwt
A JWT authorization and authentication implementation with Spring Reactive Webflux, Spring Boot 2 and Spring Security 5
Stars: ✭ 190 (+206.45%)
Mutual labels:  spring-security, jwt-authentication
Springboot Jwt Starter
A Spring Boot JWT starter kit for stateless and token-based authentication apps.
Stars: ✭ 538 (+767.74%)
Mutual labels:  spring-security, jwt-authentication
spring-boot-refresh-token-jwt
Spring Boot Refresh Token using JWT example - Expire and Renew JWT Token
Stars: ✭ 156 (+151.61%)
Mutual labels:  spring-security, jwt-authentication
Jwt Spring Security Demo
This is a demo for using JWT (JSON Web Token) with Spring Security and Spring Boot. I completely rewrote my first version. Now this solution is based on the code base from the JHipster Project. I tried to extract the minimal configuration and classes that are needed for JWT-Authentication and did some changes.
Stars: ✭ 2,843 (+4485.48%)
Mutual labels:  spring-security, jwt-authentication
Zuul Auth Example
Use Zuul and Spring Security for a global authentication.
Stars: ✭ 271 (+337.1%)
Mutual labels:  spring-security, jwt-authentication
zainabed-spring-security-jwt
Authentication & Authorization module for standalone Spring Boot app or Spring Cloud applications
Stars: ✭ 24 (-61.29%)
Mutual labels:  spring-security, jwt-authentication
fastify-csrf
A fastify csrf plugin.
Stars: ✭ 88 (+41.94%)
Mutual labels:  csrf, csrf-protection

README in english

JWT Spring Boot Security

JWT Spring Security Demo

О проекте

Это демонстрация аутентификации на основе токена с использованием JSON Web Token и CSRF, Spring Security, Spring Boot и Vue js. Это решение частично основано на блогах Где хранить ваши JWT-файлы - Cookies vs HTML5 Web Storage и Где хранить JWT в браузере? Как защитить от CSRF?

Стек Технологий

Компонент Технология
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 Gradle

Безопасность (Security)

JWT token

Для генерации и проверки JWT я использую JJWT. JJWT - автономная библиотека Java, обеспечивающая создание и верификацию сквозных веб-токенов JSON.

JWT стратегия хранения

У нас есть несколько вариантов, где хранить маркер:

  • Веб-хранилище HTML5 (HTML5 Web Storage, а точнее localStorage или sessionStorage);
  • Cookies.
Основная проблема веб-хранилища

Он доступен через JavaScript в том же домене. Это означает, что любой JavaScript, запущенный на вашем сайте, будет иметь доступ к веб-хранилищу, и из-за этого может быть уязвим для атак межсайтового скриптинга (XSS).

Таким образом, чтобы предотвратить XSS, я храню маркер JWT в Http-Only/Secure куки. Файлы куки, если они используются с флагом HttpOnly, недоступны через JavaScript и невосприимчивы к XSS.

CSRF атака

Тем не менее, файлы куки уязвимы для атаки другого типа: межсайтовой подделки запроса (CSRF). Атака CSRF - это тип атаки, которая возникает, когда вредоносный веб-сайт, электронная почта или блог заставляют веб-браузер пользователя выполнять нежелательные действия на доверенном сайте, на котором пользователь в настоящее время аутентифицирован.

Чтобы предотвратить атаки CSRF, мы должны создать дополнительный Javascript читаемый файл куки, который называется: XSRF-TOKEN. Этот файл куки должен быть создан, когда пользователь вошел в систему и должен содержать случайную, недопустимую строку. Каждый раз, когда JavaScript приложение хочет сделать запрос, ему нужно будет прочитать этот токен и отправить его в пользовательский HTTP-заголовок.

Использование

Импорт проекта (Intellij IDEA)

  1. File -> New -> Project From Existing Source -> укажите путь к проекту;
  2. CTRL + SHIFT + ALT + S -> Modules -> + -> Import Module -> Выберите backend папку, указав что это GRADLE проект;
  3. -//- то же самое для папки frontend, только не указывая что это gradle-проект, а выбрав Create module from existing sources.

Запуск бэкэнда

gradle Build : Перейдите в корневую папку build.gradle и выполните:

gradle bootRun

или запустите из IDE класс com.alexatiks.Application.

Приложение будет запущено на http://localhost:8091.

Запуск фронтэнда

Перейдите в корневую папку frontend (должен содержать package.json)

npm install

npm run serve

Приложение будет запущено на http://localhost:8080.


Чтобы убить процесс на порту 8080 (Windows):

1. netstat -ano | findstr 8080
2. taskkill /pid ПОРТ /F

Аккаунты пользователей:

Admin - admin:password
User - user:password

Эндпоинты:

/login - эндпоинт аутентефикации authentication endpoint with unrestricted access
/secured - пример эндпоинта, который разрешён только для авторизованных пользователей
/onlyforadmin - пример эндпоинта, который разрешён только для пользователей с ролью 'ADMIN'

Скриншоты

JWT Spring Security Demo

JWT Spring Security Demo

JWT Spring Security Demo

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].