Skip to content

germanfica/tut-keycloak-user-storage-spi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Storage SPI Example

This repository provides a maven project to connect to external user in-memory database.

✨ Getting Started 🚀 Download

Getting Started

Follow the below instructions to get started with the source code:

Requirements

Make sure you have the below requirements before starting:

Download

You can get access to the source code by using one of the following ways:

  • ✨ Download Source Code
  • 🔥 Clone the repository locally:
git clone https://github.com/germanfica/user-storage-spi-example.git

Keycloak Server SPI Getting Started

You can use the User Storage SPI to write extensions to Keycloak to connect to external user databases and credential stores. The built-in LDAP and ActiveDirectory support is an implementation of this SPI in action.

If you want to know more, see below the official Keycloak documentation.

Add user federation provider

Let’s add our first provider.

  1. Open the Keycloak Admin Console

  2. Hover the mouse over the dropdown in the top-left corner where it says Master, then click on Myrealm

  3. Click User Federation

  4. Fill in the form with the following values:

    • Add provider: hashmap-user-store

step_1

Done, now let's save the provider. To do this:

  1. Click Save

step_2

That's it, we now have our user federation available.

user-federation

Add default roles to users

If you want you can add default roles.

default-roles

Install maven

Follow the official maven guide below:

pom.xml

 <properties>
     <maven.compiler.release>11</maven.compiler.release>
 </properties>

 <build>
     <pluginManagement>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>3.10.0</version>
             </plugin>
         </plugins>
     </pluginManagement>
 </build>

Maven commands

  • mvn clean
  • mvn clean install

Configuration

Open org.keycloak.storage.UserStorageProviderFactory

com.hexadefence.userstoragespi.HashMapStorageProviderFactory

Maven dependencies

Apache Maven Compiler Plugin

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.10.0</version>
</dependency>

Keycloak Server SPI

<!-- https://mvnrepository.com/artifact/org.keycloak/keycloak-server-spi -->
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-server-spi</artifactId>
    <version>17.0.0</version>
    <scope>provided</scope>
</dependency>

Deploy app in Keycloak Amazon Lightsail server

scp -i YourLightsailDefaultKey.pem "D:\workspace\user-storage-spi-example\target\user-storage-spi.jar" [email protected]:"/home/ubuntu/keycloak-myrealm/standalone/deployments/user-storage-spi.jar"

Credits

Releases

No releases published

Packages

 
 
 

Languages

  • Java 100.0%