Virtual Checker built with Angular + Firebase + Flutter + JakartaEE + Microprofile + PostgreSQL on Azure - Parte 1

 



Virtual Checker




The example that we are going to develop is about a virtual checker. The objective of this application is to allow the inspection of a car whose owner wishes to purchase vehicle insurance.
  1. 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.
  2. The angular application is the web admin for operators. They assign the supervision of vehicles to their inspectors.
  3. 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.
  4. 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.
  5. This API Backend gets information on legacy systems to have the database of our solution updated to date. 
Architecture


This post shows the integration of different technologies and the ease that today is working with them.

  1. 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.
  2. Our Web Admin will be in Angular. This web will be used by an operator or administrator.
  3. 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.
  4. Our Backend that provides all the APIS for the solution will be built with JakartaEE and Microprofile
  5. Our Authentication/Authorization Server will be another JakartaEE project using Microprofile to work with JWT Tokens and JDBC Realm in Payara Server
  6. The database SQL for the whole solution will be PostgreSQL.
  7. 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



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 null
        constraint usuario_pk
            primary key,
    password         varchar(50) not null,
    activo           char        not null,
    id_ct_rol        char(7)     not null
        constraint fk_usuario_coretable
            references 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








Share:

0 comentarios:

Publicar un comentario