Skip to content

Example REST APIs in Java with JAX-RS and Jersey using JWT Authentication

Notifications You must be signed in to change notification settings

ederlopesgoncalves/java-restful-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

REST API in Java with JAX-RS and Jersey using JWT Authentication.

Filter Checking the JSON Web Token

The magic hides behind JsonTokenNeeded. Well, not really, it hides behind the BearerTokenFilter. JsonTokenNeeded is just a JAX-RS name binding (think of it as a CDI interceptor binding), so it’s just an annotation that binds to a filter.

1 - Gets the HTTP Authorization header from the request and checks for the JSON Web Token (the Bearer string)
2 - It validates the token (using the JWT library)
3 - If the token is valid, the method is invoked and provided correct result of request.
4 - If the token is invalid, a 401 Unauthorized is sent to the client

Installation

Install dependencies:

$ mvn clean install

Start the server:

$ mvn tomcat8:run

Usage example

http://localhost:8081/api

About

Example REST APIs in Java with JAX-RS and Jersey using JWT Authentication

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages