Handling User Authentication
WRITE UP :
➢ [Link]: The Maven configuration file where you define project dependencies.
➢ [Link]: The main class of the Spring
Boot application that launches the application.
➢ [Link]: The controller class
that handles HTTP requests and contains methods for showing greeting, login page,
and authenticating user credentials.
➢ [Link]: An entity class representing a user. It
includes fields such as id, name, email, and password.
➢ [Link]: A custom exception
class for handling user not found scenarios.
➢ [Link]: A repository
interface that extends the CrudRepository interface for performing CRUD operations
on the User entity.
➢ [Link]: A service class that
provides methods for retrieving user data from the repository and validating user
passwords.
➢ src/main/resources/[Link]: The application configuration file where
you define properties such as the database connection details and view
configurations.
➢ src/main/webapp/jsp: A directory where JSP files for different views are [Link]
flow of the authentication process is as follows:
➢ The user accesses the landing page ("/").
➢ From the landing page, the user can navigate to the login page ("/Auth").
➢ On the login page, the user enters their username and password and submits the
form.
➢ The authenticateUser method in the AuthenticationController class is invoked, which
calls the GetUserByName method from the AuthenticationService to retrieve the
user details based on the provided username.
➢ If the user is found, the entered password is compared with the stored password
using the isValidPassword method.
➢ Depending on the password validation, the controller returns either the "success" or
"failure" view, which is then rendered to the user