All Projects → nielsutrecht → Jwt Angular Spring

nielsutrecht / Jwt Angular Spring

Licence: mit
JSON Web Token example that integrates both a Spring backend with an AngularJS frontend.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Jwt Angular Spring

Spring Cloud Bus
Spring Cloud event bus
Stars: ✭ 342 (-4.47%)
Mutual labels:  spring-boot, spring
App Engine
分布式App服务端快速开发框架
Stars: ✭ 313 (-12.57%)
Mutual labels:  spring-boot, spring
Mmorpg
springboot编写的轻量级高性能mmorpg手游服务端框架,基本功能逐渐完善中。
Stars: ✭ 309 (-13.69%)
Mutual labels:  spring-boot, spring
Ibase4j Springboot
Spring,SpringBoot,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,Spring-Session单点登录,Quartz分布式集群调度,Restful服务,QQ/微信登录,App token登录,微信/支付宝支付;日期转换、数据类型转换、序列化、汉字转拼音、身份证号码验证、数字转人民币、发送短信、发送邮件、加密解密、图片处理、excel导入导出、FTP/SFTP/fastDFS上传下载、二维码、XML读写、高精度计算、系统配置工具类等等。
Stars: ✭ 348 (-2.79%)
Mutual labels:  spring-boot, spring
Efo
EFO是一个基于SpringBoot和Vue构建的文件分享系统,包括文件的上传与下载,文件的权限管理,远程文件管理等功能。
Stars: ✭ 327 (-8.66%)
Mutual labels:  spring-boot, spring
Awesome Spring Boot
Code based and real world examples of Spring Boot and shiny things. 😍
Stars: ✭ 303 (-15.36%)
Mutual labels:  spring-boot, spring
Java server
基于SpringMVC+spring+Mybatis的校园o2o电商项目的后台和管理平台
Stars: ✭ 341 (-4.75%)
Mutual labels:  spring-boot, spring
Spring Boot File Upload Download Rest Api Example
Spring Boot File Upload / Download Rest API Example
Stars: ✭ 300 (-16.2%)
Mutual labels:  spring-boot, spring
Java Spring Cloud
Distributed tracing for Spring Boot, Cloud and other Spring projects
Stars: ✭ 326 (-8.94%)
Mutual labels:  spring-boot, spring
Trampoline
Admin Spring Boot Locally
Stars: ✭ 325 (-9.22%)
Mutual labels:  spring-boot, spring
Romaniancoderexamples
Java / SpringBoot / Angular examples for the Romanian Coder YouTube channel
Stars: ✭ 353 (-1.4%)
Mutual labels:  spring-boot, spring
Thymeleaf Spring
Thymeleaf integration module for Spring
Stars: ✭ 349 (-2.51%)
Mutual labels:  spring-boot, spring
Springboot Analysis
🍃 something about springboot
Stars: ✭ 301 (-15.92%)
Mutual labels:  spring-boot, spring
Micro Company
Rest-full, Hipermedia-based distributed application. Spring boot & cloud. Angular. CQRS. Eventsourcing. Axonframework. Microservices. Docker. CloudFoundry
Stars: ✭ 307 (-14.25%)
Mutual labels:  spring-boot, spring
Spring Webmvc Jwt Sample
Secures REST APIs with Spring Security and JWT Token based Authentication
Stars: ✭ 299 (-16.48%)
Mutual labels:  spring-boot, spring
Angularjs Springmvc Sample Boot
A RESTful sample using Spring Boot, Spring MVC, Spring Data and Angular/Bootstrap.
Stars: ✭ 309 (-13.69%)
Mutual labels:  spring-boot, spring
Atom
Java course materials
Stars: ✭ 293 (-18.16%)
Mutual labels:  spring-boot, spring
Angular Spring Starter
Full stack starter kit featuring Angular 7, Spring boot and stateless JWT authentication.
Stars: ✭ 294 (-17.88%)
Mutual labels:  spring-boot, spring
Poi
☀️ Read and Write Excel file using Java and Apache POI
Stars: ✭ 321 (-10.34%)
Mutual labels:  spring-boot, spring
Spring Best Practices
spring 最佳实践 Demo案例
Stars: ✭ 333 (-6.98%)
Mutual labels:  spring-boot, spring

JSON Web Token / AngularJS / Spring Boot example

Blog post on this subject

This is an example project where a Spring REST API is secured using JSON Web Tokens. Since there are relatively few examples available for Java and there are some pitfalls (such as most sources pointing to a Java lib that's not straightforward to use) I decided to extract my proof of concept into a stand-alone example and publish it for all to see.

JSON Web Tokens

JSON Web Tokens have a few benefits over just sending a 'regular' token over the line. The more common approach to securing a REST API (outside of normal HTTP Basic Auth) is to send a random string as a token on succesful login from the server to the client. The client then sends this token on every request, and the server does an internal lookup on that token (in for example a REDIS cache or a simple Hashtable) to retrieve the corresponding user data.

With JSON Web Tokens the latter part isn't needed: the token itself contains a representation of the 'claims' of client: this can be just a username, but can also be extended to include any data you wish. This token is transmitted from the client on every request. The contents of the token are encrypted and a hash is added to prevent tampering: this way the content is secure: the server is the one signing and encrypting the token and is also the only one who had the key needed to decrypt the token.

In this example this key is fixed ("secretkey") but in a real life situations the secret key would simply be an array of bytes randomly generated on application startup. This has the added benefit that any tokens get automatically invalidated when you restart the service. If this behaviour is undesired you can persist the keys in for example REDIS.

Server side: Spring Boot

I like using Spring (Boot) to create RESTful services. On the server side, the JWT signing is done in the user/login REST call in UserController. It contains a tiny 'database' of 2 users, one of which has the 'admin' rights. The verification is done in a Filter (JwtFilter): it filters every request that matches "/api/*". If a correct token isn't found an exception is thrown. If a correct token is found, the claims object is added to the Http Request object and can be used in any REST endpoint (as shown in ApiController).

The heavy lifting for JWT signing is done by the more than excellent Java JWT library.

Client Side: AngularJS

The simple Angular app shows a login page. On successful login it checks with 'the API' which roles are available (of which the 'foo' role doesn't exist for any user).

Running

It is a standard Maven project and can be imported into your favorite IDE. You run the example by starting the WebApplication class (it has a main) and navigating to http://localhost:8080/. If everything is correct you should see a "Welcome to the JSON Web Token / AngularJR / Spring example!" message and a login form.

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