Steps to Install Keycloak Standalone Server
Prerequisites
Install Java
Install java (java-8-openjdk) in all the machines in the cluster and setup the JAVA_HOME environment variable for the same.
sudo yum install java-1.8.0-openjdk-develGet your Java installation path.
update-alternatives --display javaEdit ~/bashrc.sh:
Export JAVA_HOME={path-tojava} with your actual java installation path. For example on a Debian with open-jdk-8:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jreDownload & install keycloak
Download and unzip Keycloak
sudo wget "https://downloads.jboss.org/keycloak/6.0.1/keycloak-6.0.1.tar.gz"
sudo tar xzf keycloak-6.0.1.tar.gzInstall a database supported by keycloak
We have installed postgres as the database for keycloak; you can use any database supported by Keycloak.
Documentation for Keycloak Database Setup is available here.
Install Postgres in your VM. Guide to install PostgreSQL is available here.
Within the …​/modules/ directory of your Keycloak distribution, you need to create a directory structure to hold your module definition. The convention is use the Java package name of the JDBC driver for the name of the directory structure. For PostgreSQL, create the directory org/postgresql/main. Copy your database driver JAR into this directory and create an empty module.xml file within it too.
Module Directory

After you have done this, open up the module.xml file and create the following XML:
Module XML
The module name should match the directory structure of your module. So, org/postgresql maps to org.postgresql. The resource-root path attribute should specify the JAR filename of the driver. The rest are just the normal dependencies that any JDBC driver JAR would have.
Create a service to start Keycloak
Enable SSL for Keycloak server
To enable SSL we need a certificate which here in example we will use Lets encrypt.
Follow the steps in this link to create a certificate for your domain.
We will create a keystore in which we will store certificate chain and private key and give them an alias
Configure standalone xml
Go to
{{keycloak folder}}/standalone/configurationOpen
Standalone.xmland make following changesAdd a driver for postgres(Or your database)
Change the datasource properties
Register the datasource While registering change the schema name if you want.
Change network configuration
Inet address for both public and management profile to access it remotely
Default ports from
8080 -> 80and8443 -> 443to not give ports at time of accessing Keycloak
Adding a SSL certificate to Keycloak Here we will give the keystore we created to keycloak
Add keycloak admin user
Add Keycload admin user from keycloak bin directory run
Keycloak server start
Configure keycloak
Create a new Realm (eg. mosip).
Create clients for every module (i.e. ida, pre-registration, registration-processor, registration-client, auth, resident, mosip-client).
Enable authorization and service account for every client and provide valid redirect uri. These clients will be used by all modules to get client tokens.

Configure User Federation
For this example we will be configuring LDAP as user federation
Go to "User Federation".
Create a new User Federation for LDAP.
Make Edit Mode Writable.
Configure field based on your LDAP(There are many vendors for ldap you can connect to any ldap vendor based on configurations).
Go to Mappers and Create mappers for each field you want keycloak to take from LDAP.



Sync Users and Roles from LDAP .
Create INDIVIDUAL, RESIDENT Role from Keycloak in Realm Roles
Assign Roles from LDAP and Keycloak to All Clients
Access token expiration action
SSL enable at keycloak

Update of configuration for keycloak
Global configuration
Kernel configuration
Pre-registration configuration
Registration processor configuration
ID authentication configuration
Registration client configuration
Resident services configuration
Last updated
Was this helpful?