The article provides a step-by-step guide on setting up a Spring Boot application called StarVote with Keycloak or Okta as the Identity Provider, covering an overview, project setup, and prerequisites.
Abstract
The article is part of a series detailing the implementation of a Spring Boot application named StarVote, which allows users to vote for their favorite movie stars. It outlines the process of setting up the Spring Boot project, including the essential dependencies and project structure, and introduces three types of users with different roles and capabilities. The StarVote application acts as both a backend API provider and a frontend UI, with Keycloak or Okta serving as the Identity Provider for user authentication. The guide emphasizes the importance of Java 17+ for following along with the tutorial and provides a link to generate the Spring Boot application with the necessary dependencies, such as Spring Web, Spring Data JPA, H2 Database, Lombok, and Validation. The article concludes by inviting readers to engage with the content, follow the author on social media, and look forward to the next part of the series, which will focus on the backend implementation.
Opinions
The author suggests that using Keycloak or Okta as the Identity Provider enhances user experience and security.
The article implies that the H2 in-memory database is suitable for development and testing but not for production environments.
The use of Lombok is recommended for reducing boilerplate code and maintaining clean and maintainable code.
The author expresses enthusiasm for the StarVote application's potential, hinting at the dynamic ranking system and the user-friendly UI as key features.
By encouraging claps, shares, follows, and newsletter subscriptions, the author seeks to build a community around their work and ensure readers do not miss future content.
Building a Single Spring Boot App with Keycloak or Okta as IdP: Overview and Project Setup
An overview and step-by-step instructions on setting up the Spring Boot project for the StarVote application
This article is part of a series that explores the implementation of a Single Spring Boot application called StarVote. The application will use Keycloak or Okta as Identity Provider.
In the introductory article, we outline the sections we will cover.
Here’s a sneak peek of how the StarVote application will be at the end!
In this particular article, we will provide an overview of the StarVote application and guide you through setting up the Spring Boot project. We’ll cover essential dependencies and project structure needed for our application.
So, let’s get started!
Overview
StarVote is a Spring Boot application that allows users to vote for their favorite actors or actresses, commonly referred to as movie “stars”. It serves as a “single” application, acting as both a backend that delivers an API (Application Programming Interface) and a frontend application that provides a user-friendly UI (User Interface).
Draft of the main home page
Within StarVote, we have three distinct types of users, each with their own roles and capabilities. First, we have the “admins.” These individuals hold the STAR-VOTE-ADMIN role, granting them exclusive rights to register new stars within the system. However, the admins are not allowed to vote for any stars themselves.
A draft showcasing the menu options available to adminsDraft of the admin’s page for adding new stars
Next, we have the “users” of the StarVote application. These are individuals who have created an account and gained access to the system, holding the STAR-VOTE-USER role. As users, they possess the ability to cast their votes for their favorite stars. Additionally, they can explore the dynamic ranking system that showcases the most popular stars based on the total number of votes they have received.
A draft showcasing the menu options available to usersDraft of the Star’s list page, where users can view the stars and vote for their favorites
Lastly, there are those who do not have an account within the StarVote application. While they cannot actively participate by voting, they still have the opportunity to view the star’s ranking and witness the overall popularity of each actor or actress.
Daft of the Star’s rank page
To enhance user experience and security, the StarVote application offers a streamlined Sign Up or Login process through Keycloak or Okta as the Identity Provider. These authentication services provide a seamless and reliable way for users to create new accounts or access their existing ones.
Prerequisites
If you would like to follow along, you must have Java 17+ installed on your machine.
Creating the Spring Boot application
Let’s generate a Spring Boot application using Spring Initializr. We will use com.example for the group name and single-star-vote-app for the artifact name. We’ll include the following dependencies:
Spring Web: Framework for building web applications, including RESTful APIs, using Spring MVC. It leverages Apache Tomcat as the default embedded container, providing a powerful foundation for developing web-based solutions;
Spring Data JPA: Simplifies working with relational databases by providing a higher-level abstraction over JPA, allowing us to perform database operations efficiently and easily;
H2: An in-memory relational database engine suitable for development and testing purposes, offering a lightweight and fast solution without the need for a full-fledged database management system;
Lombok: A library that reduces boilerplate code by automatically generating commonly used code, such as getters, setters and constructors, resulting in cleaner and more maintainable code;
Validation: Framework that ensures data integrity by defining validation rules and constraints on data models, helping to validate user inputs and maintain data consistency.
We will use the Spring Boot version 3.1.1 and Java 17. Here is the link that contains all the setup mentioned previously.
Click the GENERATE button to download a zip file. Unzip the file to a preferred folder and then open the single-star-vote-app project in your IDE.
The initial project structure should match the one displayed below.
.
├── HELP.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── example
│ │ └── singlestarvoteapp
│ │ └── SingleStarVoteAppApplication.java
│ └── resources
│ ├── application.properties
│ ├── static
│ └── templates
└── test
└── java
└── com
└── example
└── singlestarvoteapp
└── SingleStarVoteAppApplicationTests.java
To organize our project effectively, we will create three essential packages: client, controller, model, repository, security, and service. Please proceed to create these packages. By the end of this step, the project structure should be configured as follows:
.
├── HELP.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── example
│ │ └── singlestarvoteapp
│ │ ├── SingleStarVoteAppApplication.java
│ │ ├── client
│ │ ├── controller
│ │ ├── model
│ │ ├── repository
│ │ ├── security
│ │ └── service
│ └── resources
│ ├── application.properties
│ ├── static
│ └── templates
└── test
└── java
└── com
└── example
└── singlestarvoteapp
└── SingleStarVoteAppApplicationTests.java
Up Next
We will implement the backend of the StarVote application.