All Projects → dasniko → Testcontainers Keycloak

dasniko / Testcontainers Keycloak

Licence: mit
A Testcontainer implementation for Keycloak SSO.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Testcontainers Keycloak

Authelia
The Single Sign-On Multi-Factor portal for web apps
Stars: ✭ 11,094 (+17793.55%)
Mutual labels:  sso
Hello Sso Jwt Resource
Single Sign On (SSO) Example with JSON Web Token (JWT), Spring Boot
Stars: ✭ 10 (-83.87%)
Mutual labels:  sso
Nodejs Sso Example
🌰 一个基于 Node.js 实现的单点登录实例。
Stars: ✭ 40 (-35.48%)
Mutual labels:  sso
Fw Cloud Framework
基于springcloud全家桶开发分布式框架(支持oauth2认证授权、SSO登录、统一下单、微信公众号服务、Shardingdbc分库分表、常见服务监控、链路监控、异步日志、redis缓存等功能),实现基于Vue全家桶等前后端分离项目工程
Stars: ✭ 717 (+1056.45%)
Mutual labels:  sso
Jso
Easy to use OAuth 2.0 javascript library for use in your javascript application.
Stars: ✭ 830 (+1238.71%)
Mutual labels:  sso
React Samlify
🔐Sample samlify application with React, TypeScript and Webpack
Stars: ✭ 31 (-50%)
Mutual labels:  sso
Spring Boot Security Saml Sample
SBS3 — A sample SAML 2.0 Service Provider built on Spring Boot.
Stars: ✭ 469 (+656.45%)
Mutual labels:  sso
Cas Sso Samples
CAS单点登录案例。整合了CAS OAuth2、Apache Shiro、Spring Security等
Stars: ✭ 60 (-3.23%)
Mutual labels:  sso
Zato
ESB, SOA, REST, APIs and Cloud Integrations in Python
Stars: ✭ 889 (+1333.87%)
Mutual labels:  sso
Dutsso
快速登录大连理工大学统一身份认证系统(SSO)的Python模块,可轻松实现成绩提醒、抢课、玉兰卡信息、个人信息查询等功能。
Stars: ✭ 32 (-48.39%)
Mutual labels:  sso
Phpcas
Apereo PHP CAS Client
Stars: ✭ 729 (+1075.81%)
Mutual labels:  sso
Sso
cas单点登录系统,其中包括cas认证服务,配置中心,监控平台,服务管理的高可用项目
Stars: ✭ 797 (+1185.48%)
Mutual labels:  sso
App
The SimpleLogin back-end
Stars: ✭ 958 (+1445.16%)
Mutual labels:  sso
Jpproject.identityserver4.adminui
🔧 ASP.NET Core 3 & Angular 8 Administration Panel for 💞IdentityServer4 and ASP.NET Core Identity
Stars: ✭ 717 (+1056.45%)
Mutual labels:  sso
Auth0 Drupal
Auth0 Drupal Plugin - Single Sign On, Social Login, SAML and AD/LDAP Integration, User Management, Community Driven, Open Source
Stars: ✭ 42 (-32.26%)
Mutual labels:  sso
Taoshop
开源电子商务项目,SpringBoot+Dubbo技术栈实现微服务,实现一款分布式集群的电商系统. 项目releases链接:https://github.com/u014427391/taoshop/releases (开发中...)
Stars: ✭ 491 (+691.94%)
Mutual labels:  sso
Cas Configserver Overlay
Generic CAS Spring Cloud Configuration Server WAR overlay
Stars: ✭ 28 (-54.84%)
Mutual labels:  sso
Php
PHP 文章集锦,浮点数搞定度运算、签名验证、单点登录、安全防御、缓存技术、RPC、Composer ...
Stars: ✭ 61 (-1.61%)
Mutual labels:  sso
Docker Swarm Cookbook
A large collection of recipes for a complete, self-hosted Docker Swarm stack including Traefik v2 and SSO/Auth
Stars: ✭ 49 (-20.97%)
Mutual labels:  sso
Jbone
jbone基于Spring Cloud框架开发,旨在为中小企业提供稳定的微服务解决方案,为开发人员提供基础开发骨架,jbone包含微服务中所有常用组件,例如注册中心、服务管理、服务监控、JVM监控、内存分析、调用链跟踪、API网关等等。业务功能包括系统权限的统一管理、单点登录、CMS、电商平台、工作流平台、支付平台等等。
Stars: ✭ 961 (+1450%)
Mutual labels:  sso

Keycloak Testcontainer

A Testcontainers implementation for Keycloak SSO.

Maven Central

How to use

The @Container annotation used here in the readme is from the JUnit 5 support of Testcontainers. Please refer to the Testcontainers documentation for more information.

Simply spin up a default Keycloak instance:

@Container
private KeycloakContainer keycloak = new KeycloakContainer();

Use another Keycloak Docker image/version than used in this Testcontainer:

@Container
private KeycloakContainer keycloak = new KeycloakContainer("jboss/keycloak:12.0.1");

Power up a Keycloak instance with an existing realm JSON config file (from classpath):

@Container
private KeycloakContainer keycloak = new KeycloakContainer()
    .withRealmImportFile("test-realm.json");

Use different admin credentials than the defaut internal (admin/admin) ones:

@Container
private KeycloakContainer keycloak = new KeycloakContainer()
    .withAdminUsername("myKeycloakAdminUser")
    .withAdminPassword("tops3cr3t");

You can obtain several properties form the Keycloak container:

String authServerUrl = keycloak.getAuthServerUrl();
String adminUsername = keycloak.getAdminUsername();
String adminPassword = keycloak.getAdminPassword();

with these properties, you can create a org.keycloak.admin.client.Keycloak (Keycloak admin client, 3rd party dependency from Keycloak project) object to connect to the container and do optional further configuration:

Keycloak keycloakAdminClient = KeycloakBuilder.builder()
    .serverUrl(keycloak.getAuthServerUrl())
    .realm("master")
    .clientId("admin-cli")
    .username(keycloak.getAdminUsername())
    .password(keycloak.getAdminPassword())
    .build();

See also KeycloakContainerTest class.

TLS (SSL) Usage

You have several options to use HTTPS/TLS secured communication with your Keycloak Testcontainer.

Default Support

Plain Keycloak comes with a default Java KeyStore (JKS) with an auto-generated, self-signed certificate on first use. You can use this TLS secured connection, although your testcontainer doesn't know of anything TLS-related and returns the HTTP-only url with getAuthServerUrl(). In this case, you have to build the auth-server-url on your own, e.g. like this:

String authServerUrl = "https://localhost:" + keycloak.getHttpsPort() + "/auth";

See also KeycloakContainerHttpsTest.shouldStartKeycloakWithDefaultTlsSupport.

Built-in TLS Cert and Key

This Keycloak Testcontainer comes with built-in TLS certificate (tls.crt), key (tls.key) and Java KeyStore (tls.jks) files, located in the resources folder. You can use this configuration by only configuring your testcontainer like this:

@Container
private KeycloakContainer keycloak = new KeycloakContainer().useTls();

The password for the provided Java KeyStore file is changeit. See also KeycloakContainerHttpsTest.shouldStartKeycloakWithProvidedTlsCertAndKey.

The method getAuthServerUrl() will then return the HTTPS url.

Custom TLS Cert and Key

Of course you can also provide your own certificate and key file for usage in this Testcontainer:

@Container
private KeycloakContainer keycloak = new KeycloakContainer()
    .useTls("your_custom.crt", "your_custom.key");

See also KeycloakContainerHttpsTest.shouldStartKeycloakWithCustomTlsCertAndKey.

The method getAuthServerUrl() will also return the HTTPS url.

Testing Custom Extensions

To ease extension testing, you can tell the Keycloak Testcontainer to detect extensions in a given classpath folder. This allows to test extensions directly in the same module without a packaging step.

If you have your Keycloak extension code in the src/main/java folder, then the resulting classes will be generated to the target/classes folder. To test your extensions you just need to tell KeycloakContainer to consider extensions from the target/classes folder.

Keycloak Testcontainer will then dynamically generate an exploded "jar file" with the extension code that is then picked up by Keycloak.

private KeycloakContainer keycloak = new KeycloakContainer()
    .withExtensionClassesFrom("target/classes");

Setup

The release versions of this project are available at Maven Central. Simply put the dependency coordinates to your pom.xml (or something similar, if you use e.g. Gradle or something else):

<dependency>
  <groupId>com.github.dasniko</groupId>
  <artifactId>testcontainers-keycloak</artifactId>
  <version>VERSION</version>
  <scope>test</scope>
</dependency>

Usage in your application framework tests

This info is not specific to the Keycloak Testcontainer, but using Testcontainers generally.

I mention it here, as I see people asking again and again on how to use it in their test setup, when they think they need to specify a fixed port in their properties or YAML files...
You don't have to!
But you have to read the Testcontainers docs and the docs of your application framework on testing resources!!

Spring (Boot)

Dynamic context configuration with context initializers is your friend. In particular, look for @ContextConfiguration and ApplicationContextInitializer<ConfigurableApplicationContext>:

Quarkus

Read the docs about the Quarkus Test Resources and use @QuarkusTestResource with QuarkusTestResourceLifecycleManager

Others

Consult the docs of your application framework testing capabilities on how to dynamically configure your stack for testing!

Testcontainers & Keycloak version compatiblity

Testcontainers-Keycloak Testcontainers Keycloak
1.2.0 1.12.3 8.0.1
1.3.0 1.12.3 8.0.1
1.3.1 1.13.0 9.0.2
1.3.3 1.13.0 10.0.2
1.4.0 1.13.0 11.0.2
1.5.0 1.15.1 12.0.1
1.6.0 1.15.1 12.0.1

There might also be other possible version configurations which will work.

See also the Releases page for version and feature update notes.

Credits

Many thanks to the creators and maintainers of Testcontainers. You do an awesome job!

Same goes to the whole Keycloak team!

Kudos to @thomasdarimont for some inspiration for this project.

License

MIT License

Copyright (c) 2019-2020 Niko Köbler

See LICENSE file for details.

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].