Social Network Book Application: A Comprehensive Web Application using Spring Boot, Angular, Docker, and Keycloak

Posted by


In this tutorial, we will walk you through the process of building a Book Social Network web application using Spring Boot for the backend, Angular for the frontend, Docker for containerization, and Keycloak for authentication and authorization.

Prerequisites:

  1. Basic knowledge of Java, Spring Boot, Angular, Docker, and Keycloak.
  2. Java Development Kit (JDK) installed on your machine.
  3. Node.js and npm installed on your machine.
  4. Docker installed on your machine.
  5. Keycloak server installed and running.
  6. IDE (Integrated Development Environment) like IntelliJ IDEA or Eclipse.

Let’s get started!

Step 1: Setting up the Spring Boot backend

  1. Create a new Spring Boot project using your IDE or by running the following command:

    spring init --name=book-social-network --dependencies=web,devtools,data-jpa
  2. Create the necessary entities for the application such as User, Book, Review, etc.
  3. Implement the RESTful APIs for CRUD operations on these entities.
  4. Configure the application.properties file with the database connection details.
  5. Implement security configurations using Spring Security and integrate with Keycloak for authentication and authorization.

Step 2: Setting up the Angular frontend

  1. Generate a new Angular project using Angular CLI by running the following command:

    ng new book-social-network
  2. Install necessary Angular dependencies such as Angular Material, HTTP Client, etc.
  3. Create components, services, and models for the application.
  4. Implement the logic for displaying books, creating reviews, etc. in the components.
  5. Configure API endpoints in the environment.ts file.

Step 3: Dockerizing the application

  1. Create a Dockerfile in the root directory of the project for both the backend and frontend.
  2. Build the backend Spring Boot application JAR file using Maven and copy it to the Docker container.
  3. Build the frontend Angular application using Angular CLI and copy the dist folder to the Docker container.
  4. Create a docker-compose.yml file to define the services and their configurations.
  5. Build and run the Docker containers using the docker-compose up command.

Step 4: Setting up Keycloak

  1. Download and install Keycloak on your machine or server.
  2. Configure a new realm for the application in Keycloak.
  3. Create a client for the application in Keycloak and configure the authentication flow.
  4. Integrate Keycloak with the backend Spring Boot application using the Keycloak Spring Boot Starter.
  5. Secure API endpoints using Keycloak roles and permissions.

Congratulations! You have successfully built a Book Social Network web application using Spring Boot, Angular, Docker, and Keycloak. You can now deploy the application to a server and start connecting book lovers from around the world. Happy coding!

0 0 votes
Article Rating

Leave a Reply

39 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@zach_learning_tech
3 hours ago

07:00:00

@codingman8056
3 hours ago

Hello Alibou, i have been watching your content for a quite a long time, and been Java developer for a more than 6-7 years, our juniors and interns are consuming your content as well. Really thank you for such a awesome and free content to make available on YouTube. 🙌

Just one suggestion, when you are making long videos and having multiple API endpoints, try to test them along with development , as it helps with Attention span as well as finding bug easily for those viewer who are still Intern or Junior level position .

@siddharthlodhi9158
3 hours ago

Please create a video on how to create open api specifications from scratch

@siddharthlodhi9158
3 hours ago

If u have already fetched user details based on the username extracted from the token ,the username equals check might seem redundant in the validation

@shivamshankhdhar4238
3 hours ago

timestamp 5:52:40 feedback -> it's masterpiece ❤ love from INDIA 🇮🇳

@shivamshankhdhar4238
3 hours ago

Intro of live project in starting to explain the features of it will help

@danielpark5137
3 hours ago

Wow I have found an Awesome Lecture Finally~~

@ferhatyildirim2927
3 hours ago

Hello Ali,

First of all, I am grateful for this tutorial series.

1-) How do I do this if I want to use more than one API versioning through this template? For example: I made an edit to the Feedback entity and will use it as API/v2. At the same time, I want it to remain active in the v1 version. I also made a mobile application for this application. I want the old distributions to continue to work.

2-) I also wrote public API endpoints. Is it correct to allow permissions on the SecurityConfig side and use RateLimitter for this? We are making a social media and the user should be able to see things without registering to the system and if they want, they should register to the system. In short, I will allow them to see some things, even if they are limited, without registering.

@habt_a
3 hours ago

Great content. thank you.

@Takeiteasy4Ever
3 hours ago

Hi M.Ali
You deserve more than 58,3K subscribers.
At least 2M is what you deserve.

@Swanhtetaung-b7l
3 hours ago

hello, i gained lots of knowledge from this video you made but where can i find keycloack section? the video ended up at 11.26.52. can you tell me if you don't mind? Thanks.

@siliaelghazi2897
3 hours ago

please i have a question ,after following this course with you and after learning can i share it on my linkedin or cv to look for an intership ( i'm a student} and thankyou so much Ali for your efforts

@pirate227
3 hours ago

Hi Ali, this is a great video but, I'm getting an error during the USER table creation. The error is "JDBC [ERROR: syntax error at or near "user" Position: 19]. Is this a known issue or did I fat finger something?

@yamashanmukhchandra636
3 hours ago

How are the tables created on postgresql

@jomelbarbadillo6370
3 hours ago

Hi Bouali Ali,

I’m grateful for your tutorials. I’m planning to switch from Application System Engineer to DevOps, and your content has been a great help in keeping me updated while I’m on the bench and upskilling. I hope you have active courses on Udemy that focus on Spring Boot/Python and DevOps topics like Kubernetes, Azure, AWS, microservices, Vagrant, VMs, AWS, Terraform, Ansible, Infrastructure as Code (IaC), and more. I look forward to purchasing them!

Best regards,
Hasbet

@christopherami8142
3 hours ago

getting some weird issues….
java.lang.NullPointerException: Cannot invoke "org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(java.sql.SQLException, String)" because the return value of "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.sqlExceptionHelper()" is null

at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:116) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:290) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:123) ~[hibernate-core-6.5.2.Final.jar:6.5.2.Final]

2024-09-29T16:12:36.445+04:00 WARN 28352 — [ main] org.hibernate.orm.deprecation : HHH90000025: PostgreSQLDialect does not need to be specified explicitly using 'hibernate.dialect' (remove the property setting and it will be selected by default)

2024-09-29T16:12:37.397+04:00 INFO 28352 — [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)

2024-09-29T16:12:37.410+04:00 INFO 28352 — [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 – Starting…

2024-09-29T16:12:38.595+04:00 WARN 28352 — [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 28P01

2024-09-29T16:12:38.595+04:00 ERROR 28352 — [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : FATAL: password authentication failed for user "username"

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jwtFilter' defined in file [C:UserschramiDesktopProjectbook-social-networkbook-networktargetclassescomaliboubook_networksecurityJwtFilter.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'userDetailsServiceImpl' defined in file [C:UserschramiDesktopProjectbook-social-networkbook-networktargetclassescomaliboubook_networksecurityUserDetailsServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'userRepository' defined in com.alibou.book_network.entity.user.UserRepository defined in @EnableJpaRepositories declared on BookNetworkApiApplication: Cannot resolve reference to bean 'jpaSharedEM_entityManagerFactory' while setting bean property 'entityManager'

at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:795) ~[spring-beans-6.1.12.jar:6.1.12]

at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:237) ~[spring-beans-6.1.12.jar:6.1.12]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1375) ~[spring-beans-6.1.12.jar:6.1.12]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1212) ~[spring-beans-6.1.12.jar:6.1.12]

@mohammedalabed-c4e
3 hours ago

hi what is the point of checking SecurityContextHolder.getContext().getAuthentication() == null in the jwt filter its always will return null ?

@sidof8065
3 hours ago

Hi thanks for the content SIR. Please how to run JUnit Test for method saveBook with parameter Authentication ?

@mohammedalabed-c4e
3 hours ago

hi,
about validate token method if you have already fetched the UserDetails based on the username extracted from the token, the username check might seem redundant right so why u check (username.equals(userDetails.getUsername())) any answer ??

@Lordmaryo
3 hours ago

i'm having ambiguous error message when i try running in debug mode, but when i run it on normal mode it have no errors … i've been stuck on this problem for days now

39
0
Would love your thoughts, please comment.x
()
x