This repository provides a maven project to connect to external user in-memory database.
✨ Getting Started | 🚀 Download |
---|
Follow the below instructions to get started with the source code:
- Make sure you have all Requirements
- Download Source Code
- Open Project in your favourite Java IDE
- Build the app
- Deploy the .jar file
- Setup your Keycloak Server SPI
- And finally, enjoy it!
Make sure you have the below requirements before starting:
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
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.
Let’s add our first provider.
-
Open the Keycloak Admin Console
-
Hover the mouse over the dropdown in the top-left corner where it says
Master
, then click onMyrealm
-
Click
User Federation
-
Fill in the form with the following values:
- Add provider:
hashmap-user-store
- Add provider:
Done, now let's save the provider. To do this:
- Click
Save
That's it, we now have our user federation available.
If you want you can add default roles.
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>
mvn clean
mvn clean install
Open org.keycloak.storage.UserStorageProviderFactory
com.hexadefence.userstoragespi.HashMapStorageProviderFactory
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>
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"