
Learn to implement spring security with json web tokens and refresh tokens for login, access control, and a starter project with user roles and permissions.
Explore jwt (json web token) as a small, self-contained tool for transmitting user information and permissions for api authorization, using header, payload, and signature.
Authentication verifies who you are by checking credentials via a login form. Authorization uses tokens to determine access to resources based on permissions and roles.
See how authentication issues a token after credentials are validated, enabling secure requests to access resources. Learn how access tokens and refresh tokens work together to maintain seamless authorization.
Create domain models by defining user and role entities, mapping a many-to-many relationship with eager fetching, and applying JPA and Lombok annotations for streamlined persistence.
Create domain model repositories for user and role by defining interfaces that extend the repository and add find by username and find by name methods.
Define a user service interface and its spring service implementation to manage users and roles, including save user, get users, save role, and add role to user.
Add logs to track saving a user, saving a role, and fetching users to monitor service calls, then inject the service into the controller and apply mass scale configuration.
Inject a user service into a Spring controller and expose /api/users to return all users with a response entity. Configure MySQL database and application properties for the api and logs.
implement api resource part 2 by adding endpoints to save users and save roles, and an endpoint to add roles to users, using request bodies and response entities.
Initialize the database with users and roles via a Spring Boot command line runner and user service, then assign roles to users and verify data in the browser.
Configure Spring Security to authenticate users with your own user details service and manage authorization by roles, using a password encoder and a security config class.
Implement a custom authentication filter to process login credentials, authenticate with the authentication manager, and return an access and refresh token on success while enabling stateless sessions and disabling csrf.
Generate and sign an access token and a refresh token after successful login using a Java JWT library, populating claims from the authenticated user and returning tokens in the response.
Encode user passwords with a password encoder before saving, then test login to receive an access token and a refresh token in json.
Verify and parse bearer tokens to grant access by intercepting requests with an authorization filter, extract user roles from the JWT, and set the security context.
Handle authorization filter exceptions by logging the error and returning a 403 with a JSON error to the client.
implement a refresh token flow in spring security with JWT, validating refresh tokens and issuing new access tokens through a dedicated endpoint, while handling bearer authorization and token expiry.
JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object - (from JWT website). In this course, you will understand and learn how to generate and sign a Json Web Token with a refresh token that users can use to securely access your RESTful application.
This course teaches how to use JWT (JSON Web Token) to embed users' roles and permissions to delegate user's authorization(what they can and can't do) in the application. This course also dives into defining and creating API, exposing API Endpoints over HTTP, and handling HTTP Requests and File Upload through API Endpoints. It covers testing API Endpoints (using an HTTP client - Postman).
This course is short and focuses only on the generation of a JSON web token with a refresh token, and shows how you can use the refresh token to generate a new access token for a user. If you would like to learn more and build a full stack application and see how of this in practice, and way much more, please refer to my other course on Udemy, JSON Web Token (JWT) with Spring Security And Angular