Virtual Checker
- The mobile application is for attending the inspection of vehicles that will be assigned to one inspector. This saves the image or video path in firebase but the real file in Azure storage.
- The angular application is the web admin for operators. They assign the supervision of vehicles to their inspectors.
- This is the API Backend that permits us to get, update, and insert the data in our PostgreSQL database. It gets additional information on firebase as image or video paths.
- This is our authentication/authorization server. It generates the tokens with a date of expiration. It gets the information of users and roles of the PostgreSQL database.
- This API Backend gets information on legacy systems to have the database of our solution updated to date.
Architecture
- Our Mobile App will be in Flutter. Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications for Android, iOS, Linux, Mac, Windows, Google Fuchsia, and the web from a single codebase. This application will be used by an inspector, customers, operators, etc. This app with the same codebase will be enabled to be deployed in Apple Store or Google Play.
- Our Web Admin will be in Angular. This web will be used by an operator or administrator.
- The communication in real-time between the Mobile app and Web admin will be through Firebase. We will be using Firestore. Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. While the Firestore interface has many of the same features as traditional databases, a NoSQL database differs from them in the way it describes relationships between data objects.
- Our Backend that provides all the APIS for the solution will be built with JakartaEE and Microprofile.
- Our Authentication/Authorization Server will be another JakartaEE project using Microprofile to work with JWT Tokens and JDBC Realm in Payara Server.
- The database SQL for the whole solution will be PostgreSQL.
- In this demo, we will be using Azure as a cloud provider specifically Virtual Machines, Azure PostgreSQL and Azure Storage to save images and videos.
Prerequisites
- You need an account in Azure.
- We will have two (2) servers as Azure Virtual machines for installing the Payara Servers. One of them will be used to install Nginx as an additional.
1 Payara Server
1 Nginx + 1 Payara Server
- In this demo, the installation of the Payara Server is omitted. But if you need it, you can see my post about the installation of PostgreSQL and Payara Server.
- We use the service of Azure PostgreSQL.
- You need an account in Firebase.
- Android Studio for flutter development, Intellij IDEA for JakartaEE and Microprofile or whatever you prefer, WebStorm for angular development or Visual Studio Code.
- Datagrip will be our database client tool.
Payara Servers
The API gestor will be running in this payara.
The API Backend of our web admin and the Authentication/Authorization server will be running in another payara.
In this same server, the Nginx will be installed and it's where our web admin based in angular will be running.
Authentication Server
In the past, I did a post about how to create tokens with Microprofile JWT and JDBC Realm. It has the details to generate a public and private .pem.
The source code is in this repository: https://github.com/joedayz/fps-auth-inspector
1. We need a JDBC connection Pool
Remember to give the details of the connection to your azure PostgreSQL server:
2. Next, we need a JDBC Resource connected with your JDBC Connection Pool:
3. Finally, We need to create un Realm based on JDBC:
It option is located in Configurations:
We need to create a JDBCRealm:
To be successful in this configuration, we have to indicate the table and columns where we will find the user information.
The table is like this:
The structure of the table in PostgreSQL is below:
create table usuario(username varchar(50) not nullconstraint usuario_pkprimary key,password varchar(50) not null,activo char not null,id_ct_rol char(7) not nullconstraint fk_usuario_coretablereferences core.core_table,password_encrypt varchar);
4. The clients send the username and password to be validated. In the figure below the verification is done in point 1 and returns an access token in point 2.
5. The token is generated using a private key and nimbus-jose:
<dependency><groupId>com.nimbusds</groupId><artifactId>nimbus-jose-jwt</artifactId><version>7.9</version></dependency>
It uses the private key explained in our old post about JWT Tokens. The private key is located in src/main/resources:
This code permit gets the private key when is necessary:
6. In the web.xml we configure the use of Realms:
Note: inspector is the Realm name.
7. The same information on security is configured in our glassfish-web.xml:
8. After of deploy in the payara server, we are going to test it in postman:
{{auth}} is the URL deployed of our authentication project: http://server-ip:8080/fps-auth-inspector for example.
In the next post, we will be seeing the first version of our angular application, the web admin for operators.
Enjoy!
Joe
0 comentarios:
Publicar un comentario