embedded-keycloak-spring

Spring integration module of Embedded Keycloak for Java

Лицензия

Лицензия

MIT
Категории

Категории

KeY Данные Data Formats Formal Verification Grizzly Сеть Networking Keycloak Безопасность
Группа

Группа

pl.grizzlysoftware
Идентификатор

Идентификатор

embedded-keycloak-spring
Последняя версия

Последняя версия

1.0.1
Дата

Дата

Тип

Тип

pom.sha512
Описание

Описание

embedded-keycloak-spring
Spring integration module of Embedded Keycloak for Java
Ссылка на сайт

Ссылка на сайт

https://github.com/grizzlysoftware/embedded-keycloak
Организация-разработчик

Организация-разработчик

Grizzly Software
Система контроля версий

Система контроля версий

https://github.com/grizzlysoftware/embedded-keycloak

Скачать embedded-keycloak-spring

Зависимости

compile (15)

Идентификатор библиотеки Тип Версия
org.springframework.boot : spring-boot-starter-security jar 2.1.9.RELEASE
org.springframework.boot : spring-boot-starter-web jar 2.1.9.RELEASE
org.springframework.boot : spring-boot-devtools jar 2.1.9.RELEASE
org.springframework.boot : spring-boot-configuration-processor jar 2.1.9.RELEASE
org.springframework.boot : spring-boot-starter-jdbc jar 2.1.9.RELEASE
com.fasterxml.jackson.core : jackson-core jar 2.9.9
com.fasterxml.jackson.core : jackson-annotations jar 2.9.9
com.fasterxml.jackson.core : jackson-databind jar 2.9.9.3
org.jboss.resteasy : resteasy-servlet-initializer jar 3.6.2.Final
org.jboss.resteasy : resteasy-jackson2-provider jar 3.6.2.Final
org.jboss.resteasy : resteasy-jaxb-provider jar 3.6.3.Final
org.infinispan : infinispan-core jar 9.4.8.Final
com.h2database : h2 jar 1.4.199
org.freemarker : freemarker jar 2.3.29
org.slf4j : slf4j-api jar 1.7.28

runtime (1)

Идентификатор библиотеки Тип Версия
pl.grizzlysoftware : embedded-keycloak-core jar 1.0.0

Модули Проекта

Данный проект не имеет модулей.

Java Embedded Keycloak library

Original idea comes from thomasdarimont

Core Usage

You have to run the EmbeddedKeycloakApplication class in a resteasy's servlet context (this is Keycloak's limitation)

Configuration

Embedded keycloak server can be configured in some ways. There are few limitations that cannot be easily overcome.

Configuration consists of 3 files:

  • keycloak.properties
  • keycloak-realm-conf.json
  • keycloak-server.conf

Above configuration files may be overriden by adding your versions to classpath. Description below.

Custom configuration

keep in mind that changing this file might not affect your Keycloak's configuration in order to do so, please remove Keycloak's embedded database files

Custom keycloak-server.conf

I exported this file from standalone Keycloak. I wouldn't recommend touching it unless you know what are you doing since you will modify Keycloak's intenstinals ;)

Custom keycloak-realm-conf.json

Please refer to Keycloak's documentation for more details, however, this file is quite intuitive for reading and understanding.

Custom keycloak.properties configuration

This file could be used to configure service context, admin user, default realm etc.

Setting Embedded Keycloak's context path

keycloak.embedded.server.context-path=/auth

Setting Keycloak server basic configuration file

keycloak.embedded.server.configuration.path=keycloak-server.conf

Setting default realm

keycloak.embedded.realm.default.name=master

Setting Keycloak's realm configuration file

keycloak.embedded.realm.configuration.path=keycloak-realm-conf.json

Setting behaviour when Keycloak during startup finds existing configuration

keycloak.embedded.realm.configuration.strategy=OVERWRITE_EXISTING

available strategies = [IGNORE_EXISTING, OVERWRITE_EXISTING] from org.keycloak.exportimport.Strategy

Settings Keycloak's default admin user credentials

keycloak.embedded.security.admin.username=admin keycloak.embedded.security.admin.password=admin

Setting Keycloak's datasource

keycloak.embedded.datasource.url=jdbc:h2:./data/keycloak;DB_CLOSE_ON_EXIT=FALSE keycloak.embedded.datasource.username=sa keycloak.embedded.datasource.password=

Spring integration

Usage

Just annotate one of your configuration classes with: @EnableEmbeddedKeycloakAutoConfiguration and that's it! If you are still confused check out example project in this repository: embedded-keycloak-spring-example

Use it!

Gradle

compile group: 'pl.grizzlysoftware', name: 'embedded-keycloak-spring', version: '1.0.1'
compile 'pl.grizzlysoftware:embedded-keycloak-spring:1.0.1'

Maven

<dependency>
    <groupId>pl.grizzlysoftware</groupId>
    <artifactId>embedded-keycloak-spring</artifactId>
    <version>1.0.1</version>
</dependency>

Troubleshooting

I haven't found any troubles in running it with spring tests except one(as for today - 14.11.2019). Keycloak resolves datasource via JNDI so in order to provide our own datasource we have to mock it. The thing is that attempt to mock it second time causes error. I haven't got time to investigate it. However simple check whether the JNDI context factory does not solve the problem - Keycloak does not work as expected. Above situation may be caused when Spring Configuration is modified during tests execution - i.e. by overriding some beans. Then spring instantiates configuration again because it doesn't match one that was instantiated before. it is fixed as of embedded-keycloak-spring v1.0.1

Версии библиотеки

Версия
1.0.1
1.0.0