Step-by-Step Java Spring Boot Security Web App Project Solution

Verified

Added on  2023/04/22

|5
|580
|442
Project
AI Summary
This project solution demonstrates building a secure Java web application using Spring Boot, Maven, and IntelliJ IDE. It explains the project structure, including the `pom.xml` file for dependency management and the `Application.java` class for the main method. The solution details the use of Spring MVC for web page creation (login.html and home.html) and the configuration of view controllers in the `WebConfig` class. Security is implemented using `spring-boot-starter-security` and configured in the `WebSecurityConfig` class, ensuring user authentication with username and password. The solution provides step-by-step instructions on how to run the code using IntelliJ IDE, including importing the project, running the `Application.java` class, and accessing the application in a web browser. This solution offers a comprehensive guide to understanding and implementing Spring Boot security in a web application.
Document Page
Running head: JAVA PROGRAMMING 1
The project uses a java framework called Spring Boot
Clients Name
Affiliate Institution
Date
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
2
It uses maven to manage dependencies used across the application. In the Pom.xml file
inside <build></build> tag, spring boot maven plugin artifact is defined. The spring boot maven
plugin consolidates the jar files in the projects and builds a single executable jar. When running
the application, it is the spring boot plugin that finds the main method that is public static void
function main () in the Application.java class and make the class runnable.
The web pages that makes up a web application are located in the src/main/resources/templates/
directory. The web pages are login.html and home.html. The login html file has the login form
and css. The home html file contains welcome message and logout link.
The web application made by the two html pages are based on Spring MVC (Model View
Controller). The Spring MVC together with view controllers have been configured in the
config/WebConfig class to expose the template files. The addViewControllers method in the
config/WebConfig class adds two view controllers. The two view controllers are
I. home view which is defined in home.html file
Ii login view which is defined in login.html
In order to go to home page the user must login with correct username and password. In
the code, security has been set up using spring-boot-starter-security dependency defined in the
pom.xml file. The security configuration is in the config/WebSecurityConfig.java class. The user
login credentials i.e. username and password. When the user inputs wrong username or wrong
password. The user won't be able to login. The spring boot security links the login credentials
keyed by the user on the login page to the security functionality defined in the
WebConfigSecurity class.
Document Page
3
How to run the code using intellij IDE
1. Download the zip file with the code and extract it.
2. On the editor click on file, the open folder then select the security folder extracted
from zip. You should see the project structure from security which is the main director, the src
folder, the pom.xml file. In the src folder, there is main/java folder which contains the config
directory with WebConfig class and WebConfigSecurity class. In addition, the directory has
Application.java class which contain the main method. All java applications run from the main
method.
3. Go to the src/main/java/com.e016276.security/Application.java. Right click on the
file and select Run ‘Application. Main ()’.
The screen below shows the execution results of the application. When a spring boot
project runs it shows the icon or image of spring boot at top. It also shows the execution
information (INFO).
Tomcat web server is used to serve the application on the web. The application runs on
localhost on port 8080 as shown on the screenshot
Document Page
4
4. Go to your bowser and put http://localhost:8080 in the tab. You will should see login
page. Key in the username and password which have set on the config/WebConfigSecurity class.
Click login and you will be directed to the home page.
References
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
5
https://www.jetbrains.com/help/idea/creating-and-running-your-first-java-application.html
https://spring.io/guides/gs/securing-web/
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]