All Projects → zainabed → zainabed-spring-security-jwt

zainabed / zainabed-spring-security-jwt

Licence: MIT license
Authentication & Authorization module for standalone Spring Boot app or Spring Cloud applications

Programming Languages

java
68154 projects - #9 most used programming language

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

Simplemall
基于SpringCloud的微服务架构实战案例项目,以一个简单的购物流程为示例,融合spring cloud 相关组件,如spring-cloud-netflix、swagger等
Stars: ✭ 687 (+2762.5%)
Mutual labels:  spring-cloud, spring-security, jwt-authentication
Cloud Book
《Spring Cloud 微服务架构进阶》各章节附录源码
Stars: ✭ 142 (+491.67%)
Mutual labels:  spring-cloud, spring-security
My Moments
Instagram Clone - Cloning Instagram for learning purpose
Stars: ✭ 140 (+483.33%)
Mutual labels:  spring-cloud, jwt-authentication
Mcloud
基于Spring Cloud,实现微服务中常用的基础模块,包括 OAuth2 认证服务,统一注册中心,系统监控中心, 统一配置中心,API网关以及熔断器
Stars: ✭ 185 (+670.83%)
Mutual labels:  spring-cloud, spring-security
Learning Path Spring Boot Microservices
Curated path for learning Spring Boot & Microservices based on published videos in TechPrimers
Stars: ✭ 116 (+383.33%)
Mutual labels:  spring-cloud, spring-security
Jiiiiiin Security
一个前后端分离的内管基础项目
Stars: ✭ 132 (+450%)
Mutual labels:  spring-cloud, spring-security
Spring Samples
A series of examples used to demonstrate certain features of Spring.
Stars: ✭ 154 (+541.67%)
Mutual labels:  spring-cloud, spring-security
Mall
mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。
Stars: ✭ 54,797 (+228220.83%)
Mutual labels:  spring-cloud, spring-security
Springcloud Shop
基于Spring Boot、Spring Cloud的微服务商城demo
Stars: ✭ 198 (+725%)
Mutual labels:  spring-cloud, spring-security
spring-boot-login-example
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example
Stars: ✭ 50 (+108.33%)
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 (+158.33%)
Mutual labels:  spring-security, jwt-authentication
Spring Cloud Flycloud
🔥🔥🔥FlyClould 微服务实战项目框架,在该框架中,包括了用 Spring Cloud 构建微服务的一系列基本组件和框架,对于后台服务框架的搭建有很大的参考价值,大家可以参考甚至稍加修改可以直接应用于自己的实际的项目开发中,该项目没有采用Maven进行项目构建,Maven通过xml进行依赖管理,导致整个配置文件太过臃肿,另外灵活性也不是很强,所以我采用Gradle进行项目构建和依赖管理,在FlyTour项目中我们见证了Gradle的强大,通过简单的一些配置就可以轻松的实现组件化的功能。该项目共有11个Module工程。其中10个位微服务工程,这10个微服务工程构成了一个完整的微服务系统,微服务系统包含了8个基础服务,提供了一整套微服务治理功能,他们分别是配置中心module_c…
Stars: ✭ 1,514 (+6208.33%)
Mutual labels:  spring-cloud, 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 (+354.17%)
Mutual labels:  spring-cloud, spring-security
Mi S
基于SpringBoot+SpringCloud+Mybatis主流框架搭建的分布式敏捷开发系统架构,为中、小型项目打造企业级基础开发多种解决方案。
Stars: ✭ 140 (+483.33%)
Mutual labels:  spring-cloud, spring-security
Spring Cloud Study
spring-cloud学习
Stars: ✭ 108 (+350%)
Mutual labels:  spring-cloud, spring-security
Javadevjournal
Source code for the tutorials published on the Javadevjournal site.
Stars: ✭ 141 (+487.5%)
Mutual labels:  spring-cloud, spring-security
OnlineStore
REST api for an online store using microservices architecture.
Stars: ✭ 27 (+12.5%)
Mutual labels:  spring-cloud, spring-security
Sample Boot Micro
Spring Cloud + Gradle Multi Project + Java8
Stars: ✭ 72 (+200%)
Mutual labels:  spring-cloud, spring-security
Awesome Spring
A curated list of awesome books, tutorials, courses, and resources for the Spring framework ecosystem.
Stars: ✭ 186 (+675%)
Mutual labels:  spring-cloud, spring-security
spring-boot-refresh-token-jwt
Spring Boot Refresh Token using JWT example - Expire and Renew JWT Token
Stars: ✭ 156 (+550%)
Mutual labels:  spring-security, jwt-authentication

Zainabed Spring Security JWT

Build Status

Security JWT makes it easy to configure authentication and authorization security system into Spring Boot applications. It secures application with few configurations.

Our objectives are

  • Application specific authentication
  • Decouple authentication & authorization
  • Configurable JWT token based security

Concept

Authentication

Spring Security Jwt uses Basic Authentication schema to validate user.

Basic authentication is a simple authentication scheme built into the HTTP protocol. The client sends HTTP requests with the Authorization header that contains user credentials. Authorization header is constructed using string username:password encoded in Base64 and prefixed with String Basic

Authorization: Basic dGVzdDp0ZXN0
Authorization

Once the user is logged in, Spring Security JWT creates JWT token as HTTP response to client.

Response example

{
    token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
    type: Bearer
    refereshToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
}

Then each subsequent request will have to include the JWT token, allowing the user to access resources that are permitted with that token.

Whenever the user wants to access a protected resource, the client should send the JWT token in the Authorization header using the Bearer schema. The content of the header should look like the following:

Authorization: Bearer <token>

Installation

Use your favorite Maven-compatible build tool to pull the dependencies from Maven Central

Maven

<dependency>
  <groupId>com.zainabed.spring</groupId>
  <artifactId>zainabed-spring-security-jwt</artifactId>
  <version>1.0.0</version>
</dependency>

Configuration

First step is to enable JWT security by extending JwtWebSecuriy class and annotation it with @EnableJwtSecurity.

    import com.zainabed.spring.security.jwt.annotation.EnableJwtSecurity;
    import com.zainabed.spring.security.jwt.security.JwtWebSecuriy;

    @EnableJwtSecurity
    public class ApplicationWebSecurity extends JwtWebSecuriy{
    }

Second step is to set JWT properties in application.properties file.

jwt.token.secret= <secret value>
jwt.token.expiration= <expiration time in seconds>

This is common configuration to enable both authentication and authorization.

Authentication

To activate authentication define JWT authentication property and set value as true.

jwt.authentication=true

Authentication is mapped at "/auth" route. To generate JWT token HTTP POST request should call "/auth" request with Basic Authentication header which should include user credentials which should be encoded with Base64

URL: http://localhost:8080/auth

Header:
Authorization: Basic <username-value:password-value>
Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l

Security authentication controller let you to define your own authentication module to verify user credential. to do so you have to implement JwtAuthenticationService and annotate it with @Service.

@Service
public class JwtAuthenticationServiceImpl implements JwtAuthenticationService {

	@Override
	public UserDetail authenticate(UserCredential userCredential) throws AuthenticationException {
		// Define your own authentication mechanism and return result as UserDetail object
	}

}
Authorization

Authorization process get activated when you define token secret and expiration time in properties file and extend JwtWebSecuriy , you can secure you REST controller as

@RestController
@RequestMapping(value = "/test")
public class TestControlller {

	@Secured("ROLE_USER")
	@RequestMapping(value = "/user", method = RequestMethod.GET)
	public String testUserWithRole() {
		return "Test user with User role.";
	}

	@Secured(value = "ROLE_ADMIN")
	@RequestMapping(value = "/admin", method = RequestMethod.GET)
	public String testAdmin() {
		return "Test user with Admin role.";
	}
}
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].