This project demonstrates the ability to use Postgres as user storage provider of Keycloak.
The following software is required to work build it locally:
- Git 2.2.1 or later
- Docker Engine or Docker Desktop 1.9 or later
- Maven 3.8.5 or later
- Java 17 or later
See the links above for installation instructions on your platform. You can verify the versions are installed and running:
$ git --version
$ curl -V
$ mvn -version
$ docker --version
$ java --version
Postgres - database for which we want to store User Federation.
Keycloak - KC container with custom certificate, for use over https
. The container is described in Dockerfile.
Before you build the SPI provider you must add the information about the database. This information is specified in the file persistence.xml
⚠️ Replace the URIjdbc:postgresql://localhost:5432/keycloak
with your database address.
⚠️ I recommend using your own database, cause not all systems will have a database atlocalhost
available to thedocker
container.
To deploy the container use the script :
$ sh/pg
The script deploys the container locally.
It uses port : 5432.
The scripts in the container create a keycloak
database.
In the database create a table users
:
create table users
(
id uuid not null primary key,
username varchar(255),
password varchar(255)
)
Add mock user to the table.
KC is deployed in a custom container.
To deploy the KC container, I created a Dockerfile file in which :
- I create a certificate for
https
access - I add a provider
kc-pg-provider
Run the script :
$ sh/run
This script will build the SPI provider.
Deploys the KC container, adds the SPI provider and restarts the container to apply the changes.
After launching, go to https://localhost:8443 in your browser. To log in to KC, use admin credentials :
user : admin
pass : admin
Click the User federation tab .
The provider kc-pg-provider
is in list of providers.