![]() |
VOOZH | about |
Authentication and Authorization are the core pillars of security in Spring Boot 3.0 applications using Spring Security. They ensure that users are properly verified and granted access only to permitted resources, maintaining application integrity and data protection.
Authentication is the process of verifying the identity of a user when they log in using credentials like username and password. In Spring Security, the provided credentials are validated against a configured data source.
Authorization is the process of determining what actions or resources an authenticated user is allowed to access. In Spring Security, access is controlled based on roles or permissions assigned to the user.
Follow the steps below to create and secure a Spring Boot application using Spring Security.
Go to Spring Initializr and create a new project with the following options:
Dependency:
Create a REST controller to define public and secured endpoints using role-based access control.
Configure authentication, authorization, and user roles using Spring Security.
Run the application and test endpoints using browser or Postman.
Test 1: Public Endpoint
Open in browser and test following URL
http://localhost:8080/auth/welcome
You can access this endpoint without any authentication as it is not secured.
👁 Authentication-and-Authorization-in-Spring-Boot-30-with-Spring-Security-1
Test 2: User Profile (Authentication Required)
Now, hit the following URL:
http://localhost:8080/auth/user/userProfile
If Not Logged In: You will be redirected to the below URL:
http://localhost:8080/login
Output:
After putting the correct Username and Password you can access your endpoint. Put this Username and Password
And you will get the output screen like this,
After logging in with the correct credentials, you will be able to access this endpoint if your role includes USER.