GithubHelp home page GithubHelp logo

bhanukad610 / jwtauthentication Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 58 KB

How to implement a Spring Boot Application that makes use of JWT authentication for securing an exposed REST API.

Java 100.00%
spring-boot jwt-authentication spring-security

jwtauthentication's Introduction

JwtAuthentication

How to implement a Spring Boot Application that makes use of JWT authentication for securing an exposed REST API. This is for the article - https://medium.com/javarevisited/authentication-using-json-web-tokens-part-ii-b21455692a0b

WebsecurityConfig

It is the place where all the security configurations are defined. This class is implemented by Spring Security’s WebSecurityConfigurer interface. It provides default security configurations and allows other classes to extend it and customize the security configurations by overriding its methods.

UserDetailsService

UserDetailsService is an interface that has a single method that loads a user based on username.

JwtAuthenticationEntryPoint

JwtAuthenticationEntryPoint is used to return a 401 unauthorized error to clients that try to access a protected resource without proper authentication. Only permitted request in which the token is returning is defined and all the other requests are authenticated. Used stateless sessions that won’t be used to store the user’s state. And then JwtRequestFilter is added to validate the tokens in requests headers.

JwtRequestFilter

JwtRequestFilter is the class responsible for reads JWT authentication token from the Authorization header of all the requests. It loads the user details associated with the token using JwtUserDetailsService. Token generation and validation are done using the JwtTokenService class.

JwtTokenService

Here define claims of the token, like Issuer, Expiration, Subject, and the ID and sign the JWT using the HS512 algorithm and secret key which is defined in the application.properties file. And also the validation of tokens is done here.

AuthController & Hello controller

AuthController is the controller that exposes a POST API for authenticating. The POST API gets username and password in the body and authenticates the username and password by the AuthService. If the credentials are valid, a JWT token is created using the JWTTokenService and provided to the client. HelloController is the controller class for exposing a GET REST API which can be accessed by the client if the request has a valid token.

jwtauthentication's People

Contributors

bhanukad610 avatar

Watchers

James Cloos avatar  avatar

Forkers

brkse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.