Keycloak YB

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Getting Started standalone: https://www.keycloak.

org/getting-started/getting-started-zip

Getting started domain mode:


https://www.keycloak.org/docs/latest/server_installation/index.html#_domain-mode

Relational Database setup:


https://www.keycloak.org/docs/latest/server_installation/index.html#_database

RDBMS Setup Checklist


These are the steps you will need to perform to get an RDBMS configured for Keycloak.

1. Locate and download a JDBC driver for your database


2. Package the driver JAR into a module and install this module into the server
3. Declare the JDBC driver in the configuration profile of the server
4. Modify the datasource configuration to use your database’s JDBC driver

5. Modify the datasource configuration to define


the connection parameters to your database

Steps:
1. Download Keycloak

$ wget
https://downloads.jboss.org/keycloak/11.0.2/keycloak-11.0.2.zip

2. Download the Postgres JDBC driver

$ wget https://jdbc.postgresql.org/download/postgresql-42.2.16.jar

- Need clarification on the version of JDBC driver supported, looks like


postgresql-9.4.1212.jar is the default supported
- Probably we’ll need to update the hibernate version as well
3. Install postgres JDBC driver in keycloak installation folder

Create a directory org/postgresql/main

$ mkdir -R
~/keycloak-11.0.2/modules/system/layers/keycloak/org/postgresql/main/

$ cp postgresql-42.2.16.jar
~/keycloak-11.0.2/modules/system/layers/keycloak/org/postgresql/main/

4. Create module.xml file in directory org/postgresql/main

$ vi module.xml

<?xml version="1.0" ?>


<module xmlns="urn:jboss:module:1.3" name="org.postgresql">

<resources>
<resource-root path="postgresql-42.2.16.jar"/>
</resources>

<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>

5. Update datasource configurations

Declare and Load JDBC driver for mode in which keycloak will be started

Standalone Mode

Edit standalone.xml and add an entry for postgresql datasource

$ vi keycloak-11.0.2/standalone/configuration/standalone.xml

<subsystem xmlns="urn:jboss:domain:datasources:5.0">
<datasources>
...
<drivers>
<driver name="postgresql" module="org.postgresql">

<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-
class>
</driver>
<driver name="h2" module="com.h2database.h2">

<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class
>
</driver>
</drivers>
</datasources>
</subsystem>

Update the Datasource configurations to use YugabyteDB cluster

<!-- <datasource
jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS"
enabled="true" use-java-context="true"
statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfl
y.statistics-enabled:false}}">

<connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER
=TRUE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
<pool>
<max-pool-size>100</max-pool-size>
</pool>
</datasource> -->
<datasource
jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS"
enabled="true" use-java-context="true"
statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfl
y.statistics-enabled:false}}">

<connection-url>jdbc:postgresql://127.0.0.1:5433/yugabyte</connection
-url>
<driver>postgresql</driver>
<security>
<user-name>yugabyte</user-name>
<password>password</password>
</security>
<pool>
<max-pool-size>20</max-pool-size>
</pool>
</datasource>

6. Start Keycloak Server

$ bin/standlone.sh

You might also like