Skip to content

Commit 4bc19a5

Browse files
authored
Merge pull request #8 from SnuK87/jar-with-dependencies
build a jar file with depencies for easier installation
2 parents 35a39bf + 2a80619 commit 4bc19a5

File tree

4 files changed

+57
-108
lines changed

4 files changed

+57
-108
lines changed

Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
FROM jboss/keycloak:9.0.3
2-
3-
ADD ./keycloak-module/keycloak-kafka-1.0.0.jar /opt/jboss/keycloak/modules/system/layers/keycloak/com/github/snuk87/keycloak/keycloak-kafka/main/
4-
ADD ./keycloak-module/module.xml /opt/jboss/keycloak/modules/system/layers/keycloak/com/github/snuk87/keycloak/keycloak-kafka/main/
5-
ADD ./kafka-clients/kafka-clients-2.2.0.jar /opt/jboss/keycloak/modules/system/layers/keycloak/org/apache/kafka/kafka-clients/main/
6-
ADD ./kafka-clients/lz4-java-1.5.0.jar /opt/jboss/keycloak/modules/system/layers/keycloak/org/apache/kafka/kafka-clients/main/
7-
ADD ./kafka-clients/snappy-java-1.1.7.2.jar /opt/jboss/keycloak/modules/system/layers/keycloak/org/apache/kafka/kafka-clients/main/
8-
ADD ./kafka-clients/zstd-jni-1.3.8-1.jar /opt/jboss/keycloak/modules/system/layers/keycloak/org/apache/kafka/kafka-clients/main/
9-
ADD ./kafka-clients/module.xml /opt/jboss/keycloak/modules/system/layers/keycloak/org/apache/kafka/kafka-clients/main/
1+
FROM jboss/keycloak:10.0.1
2+
3+
ADD ./keycloak-kafka-1.0.0-jar-with-dependencies.jar /opt/jboss/keycloak/standalone/deployments/
104

115
ADD kafka-module.cli /opt/jboss/startup-scripts/
126

README.md

Lines changed: 29 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Simple module for [Keycloak](https://www.keycloak.org/) to produce keycloak even
1212

1313
**Tested with**
1414

15-
Kafka version: `2.12-2.1.x`, `2.12-2.4.x`
15+
Kafka version: `2.12-2.1.x`, `2.12-2.4.x`, `2.12-2.5.x`
1616

17-
Keycloak version: `4.8.3`, `6.0.x`, `7.0.0`, `9.0.x`
17+
Keycloak version: `4.8.3`, `6.0.x`, `7.0.0`, `9.0.x`, `10.0.x`
1818

1919
Java version: `11`, `13`
2020

@@ -24,92 +24,16 @@ Java version: `11`, `13`
2424
`mvn clean package`
2525

2626
## Installation
27+
To install the keycloak-kafka module to your keycloak server you have to first configure the module and then deploy the module.
28+
If you deploy the module without configuration your keycloak server will fail to start up with a NullPointerException.
2729

28-
Add a new provider in `standalone.xml` under `<subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">`.
30+
If you want to install the module manually as described in the initial version you can follow this [guide](https://github.com/SnuK87/keycloak-kafka/wiki/Manual-Installation).
2931

30-
```xml
31-
<providers>
32-
<provider>classpath:${jboss.home.dir}/providers/*</provider>
33-
<provider>module:com.github.snuk87.keycloak.keycloak-kafka</provider>
34-
</providers>
35-
```
36-
37-
38-
Create a new folder in `$KEYCLOAK_HOME/modules/system/layers/keycloak/com/github/snuk87/keycloak/keycloak-kafka/main`
39-
40-
Copy `keycloak-kafka-1.0.0.jar` into the `main` folder and create a new file `module.xml` with the following content:
41-
42-
```xml
43-
<?xml version="1.0" ?>
44-
<module xmlns="urn:jboss:module:1.3" name="com.github.snuk87.keycloak.keycloak-kafka">
45-
<resources>
46-
<resource-root path="keycloak-kafka-1.0.0.jar" />
47-
</resources>
48-
<dependencies>
49-
<module name="org.keycloak.keycloak-core"/>
50-
<module name="org.keycloak.keycloak-server-spi"/>
51-
<module name="org.keycloak.keycloak-server-spi-private"/>
52-
<module name="com.fasterxml.jackson.core.jackson-core"/>
53-
<module name="com.fasterxml.jackson.core.jackson-databind"/>
54-
<module name="org.jboss.logging"/>
55-
<module name="org.apache.kafka.kafka-clients"/>
56-
</dependencies>
57-
</module>
58-
```
59-
60-
Create a new folder in `$KEYCLOAK_HOME/modules/system/layers/keycloak/org/apache/kafka/kafka-clients/main`
61-
and create a new file `module.xml`.
62-
63-
```xml
64-
<?xml version="1.0" encoding="UTF-8"?>
65-
<module xmlns="urn:jboss:module:1.0" name="org.apache.kafka.kafka-clients">
66-
<resources>
67-
<resource-root path="kafka-clients-2.2.0.jar"/>
68-
<resource-root path="lz4-java-1.5.0.jar"/>
69-
<resource-root path="snappy-java-1.1.7.2.jar"/>
70-
</resources>
71-
<dependencies>
72-
<module name="org.slf4j"/>
73-
</dependencies>
74-
</module>
75-
```
76-
77-
Download the .jar files listed under `<resources>` from [MVN Repository](https://mvnrepository.com/) and put them into the same folder.
32+
### Module configuration
33+
Download the [CLI script](kafka-module.cli) from this repository and edit the properties to fit your environment. Also make sure that you use the right
34+
server config (line 1). As a default the script will change the `standalone.xml`.
7835

79-
```
80-
.
81-
├── kafka-clients-2.2.0.jar
82-
├── lz4-java-1.5.0.jar
83-
├── module.xml
84-
├── snappy-java-1.1.7.2.jar
85-
└── zstd-jni-1.3.8-1.jar
86-
```
87-
88-
## Configuration
89-
90-
### Enable Events in keycloak
91-
1. Open administration console
92-
2. Choose realm
93-
3. Go to Events
94-
4. Open `Config` tab and add `kafka` to Event Listeners. If you can't choose `kafka` you have to restart the keycloak server first.
95-
96-
97-
### Kafka module
98-
Add the following content to your `standalone.xml`:
99-
100-
```xml
101-
<spi name="eventsListener">
102-
<provider name="kafka" enabled="true">
103-
<properties>
104-
<property name="topicEvents" value="keycloak-events"/>
105-
<property name="clientId" value="keycloak"/>
106-
<property name="bootstrapServers" value="192.168.0.1:9092,192.168.0.2:9092"/>
107-
<property name="events" value="REGISTER,LOGIN,LOGOUT"/>
108-
<property name="topicAdminEvents" value="keycloak-admin-events"/>
109-
</properties>
110-
</provider>
111-
</spi>
112-
```
36+
Currently the following properties are available and should be changed to fit your environemnt:
11337

11438
`topicEvents`: The name of the kafka topic to where the events will be produced to.
11539

@@ -121,21 +45,31 @@ Add the following content to your `standalone.xml`:
12145

12246
`topicAdminEvents`: (Optional) The name of the kafka topic to where the admin events will be produced to.
12347

124-
125-
To automate the configuration of the event listener, it is possible to run the [CLI script](kafka-module.cli) from this repo.
126-
Make sure to edit the properties to fit your environemnt and use the right server config (default is `standalone-ha`)
127-
48+
Run the CLI script using the following command and check the output on the console. You should see some server logs and 6 lines of `{"outcome" => "success"}`.
12849
```bash
129-
$KEYCLOAK_HOME/bin/jboss-cli.sh --file /path/to/kafka-module.cli
50+
$KEYCLOAK_HOME/bin/jboss-cli.sh --file=/path/to/kafka-module.cli
13051
```
13152

132-
## Docker Container
133-
The simplest way to enable the kafka module in a docker container is to create a custom docker image from the keycloak base image and use the CLI script to configure the kafka module.
134-
First all .jar files must be added to the image and placed in their module directory as explained in [Installation](#installation). Then the CLI script must be added and placed in
135-
the `/opt/jboss/startup-scripts/` directory, so the script will be executed automatically on startup.
53+
### Module deployment
54+
Copy the `keycloak-kafka-<version>-jar-with-dependencies.jar` into the $KEYCLOAK_HOME/standalone/deployments folder. Keycloak will automatically
55+
install the module with all dependencies on start up. To verify that the deployment of the module was successful you can check if a new file
56+
with the name `keycloak-kafka-<version>-jar-with-dependencies.jar.deployed` was created in the same folder.
57+
13658

137-
An example can be found in this [Dockerfile](Dockerfile).
59+
## Keycloak Configuration
13860

61+
### Enable Events in keycloak
62+
1. Open administration console
63+
2. Choose realm
64+
3. Go to Events
65+
4. Open `Config` tab and add `kafka` to Event Listeners.
66+
67+
68+
## Docker Container
69+
The simplest way to enable the kafka module in a docker container is to create a custom docker image from the [keycloak base image](https://hub.docker.com/r/jboss/keycloak/).
70+
The `keycloak-kafka-<version>-jar-with-dependencies.jar` must be added to the `/standalone/deployments` folder and the CLI script must be added to the `/opt/jboss/startup-scripts/` folder
71+
as explained in [Installation](#installation). The only difference is that the CLI script will be executed automatically in start up and doesn't have to be executed manually.
72+
An example can be found in this [Dockerfile](Dockerfile).
13973

14074
## Sample Client
14175

kafka-module.cli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
embed-server --server-config=standalone-ha.xml --std-out=echo
1+
embed-server --server-config=standalone.xml --std-out=echo
22

33
if (outcome != success) of /subsystem=keycloak-server/spi=eventsListener:read-resource()
4-
/subsystem=keycloak-server:list-add(name="providers",value="module:com.github.snuk87.keycloak.keycloak-kafka")
54
/subsystem=keycloak-server/spi=eventsListener:add()
65
/subsystem=keycloak-server/spi=eventsListener/provider=kafka:add(enabled=true)
76
/subsystem=keycloak-server/spi=eventsListener/provider=kafka:write-attribute(name=properties.topicEvents,value=keycloak-events)

pom.xml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<properties>
1010
<maven.compiler.source>11</maven.compiler.source>
1111
<maven.compiler.target>11</maven.compiler.target>
12-
<keycloak.version>9.0.3</keycloak.version>
13-
<kafka.version>2.2.0</kafka.version>
12+
<keycloak.version>10.0.1</keycloak.version>
13+
<kafka.version>2.5.0</kafka.version>
1414
</properties>
1515

1616
<dependencies>
@@ -46,4 +46,26 @@
4646
<version>${kafka.version}</version>
4747
</dependency>
4848
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<artifactId>maven-assembly-plugin</artifactId>
54+
<configuration>
55+
<descriptorRefs>
56+
<descriptorRef>jar-with-dependencies</descriptorRef>
57+
</descriptorRefs>
58+
</configuration>
59+
<executions>
60+
<execution>
61+
<id>make-assembly</id>
62+
<phase>package</phase>
63+
<goals>
64+
<goal>single</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
</plugins>
70+
</build>
4971
</project>

0 commit comments

Comments
 (0)