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:
- Basic knowledge of Java, Spring Boot, Angular, Docker, and Keycloak.
- Java Development Kit (JDK) installed on your machine.
- Node.js and npm installed on your machine.
- Docker installed on your machine.
- Keycloak server installed and running.
- IDE (Integrated Development Environment) like IntelliJ IDEA or Eclipse.
Let’s get started!
Step 1: Setting up the Spring Boot backend
-
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
- Create the necessary entities for the application such as User, Book, Review, etc.
- Implement the RESTful APIs for CRUD operations on these entities.
- Configure the application.properties file with the database connection details.
- Implement security configurations using Spring Security and integrate with Keycloak for authentication and authorization.
Step 2: Setting up the Angular frontend
-
Generate a new Angular project using Angular CLI by running the following command:
ng new book-social-network
- Install necessary Angular dependencies such as Angular Material, HTTP Client, etc.
- Create components, services, and models for the application.
- Implement the logic for displaying books, creating reviews, etc. in the components.
- Configure API endpoints in the environment.ts file.
Step 3: Dockerizing the application
- Create a Dockerfile in the root directory of the project for both the backend and frontend.
- Build the backend Spring Boot application JAR file using Maven and copy it to the Docker container.
- Build the frontend Angular application using Angular CLI and copy the dist folder to the Docker container.
- Create a docker-compose.yml file to define the services and their configurations.
- Build and run the Docker containers using the docker-compose up command.
Step 4: Setting up Keycloak
- Download and install Keycloak on your machine or server.
- Configure a new realm for the application in Keycloak.
- Create a client for the application in Keycloak and configure the authentication flow.
- Integrate Keycloak with the backend Spring Boot application using the Keycloak Spring Boot Starter.
- 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!
07:00:00
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 .
Please create a video on how to create open api specifications from scratch
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
timestamp 5:52:40 feedback -> it's masterpiece ❤ love from INDIA 🇮🇳
Intro of live project in starting to explain the features of it will help
Wow I have found an Awesome Lecture Finally~~
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.
Great content. thank you.
Hi M.Ali
You deserve more than 58,3K subscribers.
At least 2M is what you deserve.
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.
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
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?
How are the tables created on postgresql
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
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]
hi what is the point of checking SecurityContextHolder.getContext().getAuthentication() == null in the jwt filter its always will return null ?
Hi thanks for the content SIR. Please how to run JUnit Test for method saveBook with parameter Authentication ?
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 ??
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