All Projects → SnuK87 → keycloak-kafka

SnuK87 / keycloak-kafka

Licence: Apache-2.0 license
Keycloak module to produce events to kafka

Programming Languages

java
68154 projects - #9 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to keycloak-kafka

keycloak-sms-authenticator-sns
SMS 2 Factor Authentication for Keycloak via AWS SNS
Stars: ✭ 66 (+17.86%)
Mutual labels:  keycloak
keycloak-mysql-user-federation
Keycloak user federation extension to connect to a MySQL database containing users
Stars: ✭ 17 (-69.64%)
Mutual labels:  keycloak
Supertokens Core
Open source alternative to Auth0 / Firebase Auth / AWS Cognito
Stars: ✭ 2,907 (+5091.07%)
Mutual labels:  keycloak
keyonic-v2
A Keycloak Mobile Implementation using Angular v4 and Ionic v3
Stars: ✭ 23 (-58.93%)
Mutual labels:  keycloak
ProxyInjector
A Kubernetes controller to inject an authentication proxy container to relevant pods - [✩Star] if you're using it!
Stars: ✭ 77 (+37.5%)
Mutual labels:  keycloak
keycloak-sso
custom account management template, keycloak authentication and authorization
Stars: ✭ 41 (-26.79%)
Mutual labels:  keycloak
keycloak-session-restrictor
Simple event-listener for Keycloak which restricts the current user sessions to one (last one wins) only. Demo purposes only!
Stars: ✭ 48 (-14.29%)
Mutual labels:  keycloak
spring-boot-web-application-sample
Real World Spring Boot Web Application Example with tons of ready to use features
Stars: ✭ 143 (+155.36%)
Mutual labels:  keycloak
keycloak-mail-whitelisting
Keycloak extension to whitelist email adresses domain when users register
Stars: ✭ 36 (-35.71%)
Mutual labels:  keycloak
Keycloak
Open Source Identity and Access Management For Modern Applications and Services
Stars: ✭ 10,826 (+19232.14%)
Mutual labels:  keycloak
brauzie
Awesome CLI for fetching JWT tokens for OAuth2.0 clients
Stars: ✭ 14 (-75%)
Mutual labels:  keycloak
gocloaksession
Maintains an active keycloak session using gocloak
Stars: ✭ 15 (-73.21%)
Mutual labels:  keycloak
keycloak-restrict-client-auth
A Keycloak authenticator to restrict authorization on clients
Stars: ✭ 34 (-39.29%)
Mutual labels:  keycloak
react-keycloak-examples
Examples for react-keycloak packages
Stars: ✭ 110 (+96.43%)
Mutual labels:  keycloak
vagrant-codes-in-practice
Vagrant code files similar to the real bare metal environments
Stars: ✭ 22 (-60.71%)
Mutual labels:  keycloak
epiphany
Cloud and on-premises automation for Kubernetes centered industrial grade solutions.
Stars: ✭ 114 (+103.57%)
Mutual labels:  keycloak
Keycloak.Net
C# client for Keycloak 6.x
Stars: ✭ 100 (+78.57%)
Mutual labels:  keycloak
scim-for-keycloak
a third party module that extends keycloak by SCIM functionality
Stars: ✭ 127 (+126.79%)
Mutual labels:  keycloak
spring-boot-keycloak-angular
Securing a Angular frontend and a Spring Boot backend with Keycloak and Spring Security
Stars: ✭ 40 (-28.57%)
Mutual labels:  keycloak
springboot-keycloak-mongodb-testcontainers
Goals: 1) Create a Spring Boot application that manages books; 2) Use Keycloak as authentication and authorization server; 3) Test using Testcontainers; 4) Explore the utilities and annotations that Spring Boot provides when testing applications.
Stars: ✭ 18 (-67.86%)
Mutual labels:  keycloak

Keycloak Kafka Module

Simple module for Keycloak to produce keycloak events to Kafka.

Tested with

Kafka version: 2.12-2.1.x, 2.12-2.4.x, 2.12-2.5.x, 2.13-2.8, 2.13-3.3.x

Keycloak version: 19.0.x

Java version: 11, 17

Check out this older version to run the module on a Wildfly server

Build

You can simply use Maven to build the jar file. Thanks to the assembly plugin the build process will create a fat jar that includes all dependencies and makes the deployment quite easy. Just use the following command to build the jar file.

mvn clean package

Installation

First you need to build or download the keycloak-kafka module.

To install the module to your keycloak server you have to configure the module and deploy it. If you deploy the module without configuration, your keycloak server will fail to start throwing a NullPointerException.

If you want to install the module manually as described in the initial version you can follow this guide.

Module Configuration

The following properties can be set via environment variables (e.g. ${KAFKA_TOPIC}) or as parameters when starting keycloak (e.g. --spi-events-listener-kafka-topic-events).

  • topicEvents (env KAFKA_TOPIC): The name of the kafka topic to where the events will be produced to.

  • clientId (env KAFKA_CLIENT_ID): The client.id used to identify the client in kafka.

  • bootstrapServer (env KAFKA_BOOTSTRAP_SERVERS): A comma separated list of available brokers.

  • events (env KAFKA_EVENTS): The events that will be send to kafka.

  • topicAdminEvents (env KAFKA_ADMIN_TOPIC): (Optional) The name of the kafka topic to where the admin events will be produced to. No events will be produced when this property isn't set.

A list of available events can be found here

Kafka client configuration

It's also possible to configure the kafka client by adding parameters to the keycloak start command. This makes it possible to connect this module to a kafka broker that requires SSL/TLS connections. For example to change the timeout of how long the producer will block the thread to 10 seconds you just have to pass the following parameter to the start command.

./kc.sh start --spi-events-listener-kafka-max-block-ms 10000

A full list of available configurations can be found in the official kafka docs.

Kafka client using secure connection

As mentioned above the kafka client can be configured by passing parameters to the start command. To make kafka open a SSL/TLS secured connection you can add the following parameters:

./kc.sh start \
  --spi-events-listener-kafka-security-protocol SSL \
  --spi-events-listener-kafka-ssl-truststore-location kafka.client.truststore.jks \
  --spi-events-listener-kafka-ssl-truststore-password test1234

Module Deployment

Copy the keycloak-kafka-<version>-jar-with-dependencies.jar into the $KEYCLOAK_HOME/providers folder. Keycloak will automatically install the module with all it's dependencies on start up.

Keycloak Configuration

Enable Events in keycloak

  1. Open administration console
  2. Choose realm
  3. Go to Events
  4. Open Config tab and add kafka to Event Listeners.

Admin console config

Docker Container

The simplest way to enable the kafka module in a docker container is to create a custom docker image from the keycloak base image. A simple example can be found in the Dockerfile. When you build this image on your local machine by using docker build . -t keycloak-kafka, you can test everything by running the docker-compose file on your local machine. This just provides a simple example to show how it's working. Please consider to read this documentation and create your own Dockerfile.

Sample Client

The following snippet shows a minimal Spring Boot Kafka client to consume keycloak events. Additional properties can be added to the KeycloakEvent class.

@SpringBootApplication
@Log4j2
public class KafkaConsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(KafkaConsumerApplication.class, args);
	}

	@KafkaListener(topics = "keycloak-events", groupId = "event-consumer")
	public void handleKeycloakEvent(KeycloakEvent event) {
		log.info("Consumed event: " + event);
	}

	@KafkaListener(topics = "keycloak-admin-events", groupId = "event-consumer")
	public void handleKeycloakAdminEvent(KeycloakAdminEvent event) {
		log.info("Consumed admin event: " + event);
	}

	@Bean
	public StringJsonMessageConverter jsonConverter() {
		return new StringJsonMessageConverter();
	}
}

@Data
class KeycloakEvent {
	private String userId;
	private String type;
}

@Data
class KeycloakAdminEvent {
	private String realmId;
	private String operationType;
}

Contribution

Any kind of contributions are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].