All Projects → szerhusenBC → Jwt Spring Security Demo

szerhusenBC / Jwt Spring Security Demo

Licence: mit
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.

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language
HTML
75241 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to Jwt Spring Security Demo

Spring Security Pac4j
pac4j security library for Spring Security: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 231 (-91.87%)
Mutual labels:  spring-boot, authentication, jwt, spring-security
Spring Boot In Action
Spring Boot 系列实战合集
Stars: ✭ 4,153 (+46.08%)
Mutual labels:  spring-boot, springframework, jwt, spring-security
Spring Security React Ant Design Polls App
Full Stack Polls App built using Spring Boot, Spring Security, JWT, React, and Ant Design
Stars: ✭ 1,336 (-53.01%)
Mutual labels:  spring-boot, authentication, jwt, spring-security
Springboot Jwt Starter
A Spring Boot JWT starter kit for stateless and token-based authentication apps.
Stars: ✭ 538 (-81.08%)
Mutual labels:  spring-boot, jwt, spring-security, jwt-authentication
Simplemall
基于SpringCloud的微服务架构实战案例项目,以一个简单的购物流程为示例,融合spring cloud 相关组件,如spring-cloud-netflix、swagger等
Stars: ✭ 687 (-75.84%)
Mutual labels:  spring-boot, jwt, 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 (-93.32%)
Mutual labels:  spring-boot, jwt, spring-security, jwt-authentication
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (-83.05%)
Mutual labels:  spring-boot, authentication, jwt, spring-security
Spring Boot Jwt
JWT auth service using Spring Boot, Spring Security and MySQL
Stars: ✭ 795 (-72.04%)
Mutual labels:  spring-boot, authentication, jwt, spring-security
Spring Boot Webflux Jjwt
Example Spring Boot and WebFlux (Reactive Web) with Spring Security and JWT for token Authentication and Authorization
Stars: ✭ 71 (-97.5%)
Mutual labels:  spring-boot, authentication, jwt, spring-security
Springboot Registration Login Theperfectexample
Login & Signup tutorial for every website ,mixes a lot of microservices together with the latest spring framework api in combined with full security
Stars: ✭ 89 (-96.87%)
Mutual labels:  spring-boot, authentication, spring-security
Webfluxtemplate
Spring Webflux template application with working Spring Security, Web-sockets, Rest, Web MVC, and Authentication with JWT.
Stars: ✭ 107 (-96.24%)
Mutual labels:  spring-boot, spring-security, jwt-authentication
Spring Webmvc Pac4j
Security library for Spring Web MVC: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 110 (-96.13%)
Mutual labels:  spring-boot, authentication, jwt
Easy Notes
🍋 简笔记(easy notes)打造你的轻便私人笔记。接口涉及Spring Security、OAuth2、Jwt、MongoDB,客户端采用 Vue.js 、Ant Design
Stars: ✭ 89 (-96.87%)
Mutual labels:  spring-boot, jwt, spring-security
Sample Spring Oauth2 Microservices
some examples that show basic and more advanced implementations of oauth2 authorization mechanism in spring-cloud microservices environment
Stars: ✭ 109 (-96.17%)
Mutual labels:  spring-boot, jwt, spring-security
Spring Boot Oauth2 Jwt Swagger Ui
Spring Boot , OAuth 2 , JWT (Json Web Token) and Swagger UI
Stars: ✭ 77 (-97.29%)
Mutual labels:  spring-boot, authentication, jwt-authentication
Milkomeda
Spring extend componets which build from experience of bussiness, let developers to develop with Spring Boot as fast as possible.(基于Spring生态打造的一系列来自业务上的快速开发模块集合。)
Stars: ✭ 117 (-95.88%)
Mutual labels:  spring-boot, jwt, spring-security
Securing Rest Api Spring Security
Spring Boot 2.2.x + Spring 5.2.x Rest Api Security Example
Stars: ✭ 117 (-95.88%)
Mutual labels:  spring-boot, jwt, spring-security
Ixortalk.aws.cognito.jwt.security.filter
Spring Boot security filter for decoding Cognito JWT IdTokens
Stars: ✭ 75 (-97.36%)
Mutual labels:  spring-boot, jwt, spring-security
Spring Cloud Flycloud
🔥🔥🔥FlyClould 微服务实战项目框架,在该框架中,包括了用 Spring Cloud 构建微服务的一系列基本组件和框架,对于后台服务框架的搭建有很大的参考价值,大家可以参考甚至稍加修改可以直接应用于自己的实际的项目开发中,该项目没有采用Maven进行项目构建,Maven通过xml进行依赖管理,导致整个配置文件太过臃肿,另外灵活性也不是很强,所以我采用Gradle进行项目构建和依赖管理,在FlyTour项目中我们见证了Gradle的强大,通过简单的一些配置就可以轻松的实现组件化的功能。该项目共有11个Module工程。其中10个位微服务工程,这10个微服务工程构成了一个完整的微服务系统,微服务系统包含了8个基础服务,提供了一整套微服务治理功能,他们分别是配置中心module_c…
Stars: ✭ 1,514 (-46.75%)
Mutual labels:  spring-boot, springframework, spring-security
Springboot Restful Angular
springBoot,restful,jwt,angular4 搭建的前后端分离后台管理系统
Stars: ✭ 121 (-95.74%)
Mutual labels:  spring-boot, jwt, spring-security

JWT Spring Security Demo

Screenshot from running application

About

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.

Build Status

Requirements

This demo is build with with Maven 3.6.x and Java 11.

Usage

Just start the application with the Spring Boot maven plugin (mvn spring-boot:run). The application is running at http://localhost:8080.

You can use the H2-Console for exploring the database under http://localhost:8080/h2-console:

Screenshot from h2-console login

Backend

There are three user accounts present to demonstrate the different levels of access to the endpoints in the API and the different authorization exceptions:

Admin - admin:admin
User - user:password
Disabled - disabled:password (this user is deactivated)

There are four endpoints that are reasonable for the demo:

/api/authenticate - authentication endpoint with unrestricted access
/api/user - returns detail information for an authenticated user (a valid JWT token must be present in the request header)
/api/persons - an example endpoint that is restricted to authorized users with the authority 'ROLE_USER' (a valid JWT token must be present in the request header)
/api/hiddenmessage - an example endpoint that is restricted to authorized users with the authority 'ROLE_ADMIN' (a valid JWT token must be present in the request header)

Frontend

I've written a small Javascript client and put some comments in the code that hopefully makes this demo understandable. You can find it at /src/main/resources/static/js/client.js.

Generating password hashes for new users

I'm using bcrypt to encode passwords. Your can generate your hashes with this simple tool: Bcrypt Generator

Using another database

Actually this demo is using an embedded H2 database that is automatically configured by Spring Boot. If you want to connect to another database you have to specify the connection in the application.yml in the resource directory. Here is an example for a MySQL DB:

spring:
  jpa:
    hibernate:
      # possible values: validate | update | create | create-drop
      ddl-auto: create-drop
  datasource:
    url: jdbc:mysql://localhost/myDatabase
    username: myUser
    password: myPassword
    driver-class-name: com.mysql.jdbc.Driver

Hint: For other databases like MySQL sequences don't work for ID generation. So you have to change the GenerationType in the entity beans to 'AUTO' or 'IDENTITY'.

You can find a reference of all application properties here.

Using Flyway

https://github.com/szerhusenBC/jwt-spring-security-demo/issues/81

Docker

This project has a docker image. You can find it at https://hub.docker.com/r/hubae/jwt-spring-security-demo/.

Questions

If you have project related questions please take a look at the past questions or create a new ticket with your question.

If you have questions that are not directly related to this project (e.g. common questions to the Spring Framework or Spring Security etc.) please search the web or look at Stackoverflow.

Sorry for that but I'm very busy right now and don't have much time.

Interesting projects

Author

Stephan Zerhusen

Copyright and license

The code is released under the MIT license.


Please feel free to send me some feedback or questions!

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