Package dasniko.testcontainers.keycloak
Class ExtendableKeycloakContainer<SELF extends ExtendableKeycloakContainer<SELF>>
java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<SELF>
dasniko.testcontainers.keycloak.ExtendableKeycloakContainer<SELF>
- All Implemented Interfaces:
AutoCloseable,org.junit.rules.TestRule,org.testcontainers.containers.Container<SELF>,org.testcontainers.containers.ContainerState,org.testcontainers.containers.traits.LinkableContainer,org.testcontainers.containers.wait.strategy.WaitStrategyTarget,org.testcontainers.lifecycle.Startable
- Direct Known Subclasses:
KeycloakContainer
public abstract class ExtendableKeycloakContainer<SELF extends ExtendableKeycloakContainer<SELF>>
extends org.testcontainers.containers.GenericContainer<SELF>
- Author:
- Niko Köbler, https://www.n-k.de, @dasniko
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.testcontainers.containers.Container
org.testcontainers.containers.Container.ExecResult -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final org.testcontainers.containers.wait.strategy.WaitStrategystatic final StringFields inherited from class org.testcontainers.containers.GenericContainer
CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategyFields inherited from interface org.testcontainers.containers.ContainerState
STATE_HEALTHY -
Constructor Summary
ConstructorsConstructorDescriptionCreate a KeycloakContainer with default image and version tagExtendableKeycloakContainer(String dockerImageName) Create a KeycloakContainer by passing the full docker image name -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidcreateKeycloakExtensionDeployment(String deploymentLocation, String extensionName, String extensionClassFolder) Maps the providedextensionClassFolderas an exploded extension.jar to thedeploymentLocation.voidcreateKeycloakExtensionProvider(String extensionClassFolder) Maps the providedextensionClassFolderas an exploded providers.jar to the Keycloak providers folder.voidintGet the mapped port for remote debugging.intintintorg.keycloak.admin.client.KeycloakReturns the keycloak admin.protected StringresolveExtensionClassLocation(String extensionClassFolder) useMutualTls(String tlsTruststoreFilename, String tlsTruststorePassword, HttpsClientAuth httpsClientAuth) Think about usingwithTrustedCertificates(List)andwithHttpsClientAuth(HttpsClientAuth)instead.useTls()useTlsKeystore(String tlsKeystoreFilename, String tlsKeystorePassword) waitingFor(@NotNull org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy) withAdminPassword(String adminPassword) withAdminUsername(String adminUsername) Disable default bootstrapping of the keycloak admin.withCommand(String cmd) withCommand(String... commandParts) withContextPath(String contextPath) withCustomCommand(String cmd) Enable remote debugging in Keycloak and expose it on a random port.withDebugFixedPort(int hostPort, boolean suspend) Enable remote debugging in Keycloak and expose it on a fixed port.Exposes the default classes locationtarget/classesas an exploded providers.jar.withFeaturesDisabled(String... features) withFeaturesEnabled(String... features) withHttpsClientAuth(HttpsClientAuth httpsClientAuth) Configures the server to require/request client authentication.Will add the "--optimized" flag to Keycloak startup command.withProviderClassesFrom(String... classesLocations) Exposes the given classes locations as an exploded providers.jar.withProviderLibsFrom(List<File> libs) withRamPercentage(int initialRamPercentage, int maxRamPercentage) withRealmImportFile(String importFile) withRealmImportFiles(String... files) withStartupTimeout(Duration startupTimeout) withTrustedCertificates(List<String> tlsTrustedCertificateFilenames) Configure the Keycloak Truststore to communicate through TLS.Methods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, apply, canBeReused, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, failed, finished, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, starting, stop, succeeded, toString, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withTmpFs, withVolumesFrom, withWorkingDirectoryMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindMethods inherited from interface org.testcontainers.containers.ContainerState
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunningMethods inherited from interface org.testcontainers.lifecycle.Startable
close
-
Field Details
-
MASTER_REALM
- See Also:
-
ADMIN_CLI_CLIENT
- See Also:
-
LOG_WAIT_STRATEGY
public static final org.testcontainers.containers.wait.strategy.WaitStrategy LOG_WAIT_STRATEGY
-
-
Constructor Details
-
ExtendableKeycloakContainer
public ExtendableKeycloakContainer()Create a KeycloakContainer with default image and version tag -
ExtendableKeycloakContainer
Create a KeycloakContainer by passing the full docker image name- Parameters:
dockerImageName- Full docker image name, e.g. quay.io/keycloak/keycloak:25.0
-
-
Method Details
-
configure
protected void configure()- Overrides:
configurein classorg.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
-
withCommand
- Specified by:
withCommandin interfaceorg.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>- Overrides:
withCommandin classorg.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
-
withCommand
- Specified by:
withCommandin interfaceorg.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>- Overrides:
withCommandin classorg.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
-
waitingFor
public SELF waitingFor(@NotNull @NotNull org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy) - Specified by:
waitingForin interfaceorg.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>- Overrides:
waitingForin classorg.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
-
withNightly
-
withCustomCommand
-
createKeycloakExtensionProvider
Maps the providedextensionClassFolderas an exploded providers.jar to the Keycloak providers folder.- Parameters:
extensionClassFolder- a path relative to the current classpath root.
-
createKeycloakExtensionDeployment
protected void createKeycloakExtensionDeployment(String deploymentLocation, String extensionName, String extensionClassFolder) Maps the providedextensionClassFolderas an exploded extension.jar to thedeploymentLocation.- Parameters:
deploymentLocation- the target deployments location of the Keycloak server.extensionName- the name suffix of the created extension.extensionClassFolder- a path relative to the current classpath root.
-
resolveExtensionClassLocation
-
withProductionMode
-
withRealmImportFile
-
withRealmImportFiles
-
withAdminUsername
-
withAdminPassword
-
withContextPath
-
withRamPercentage
-
withProviderClassesFrom
Exposes the given classes locations as an exploded providers.jar.- Parameters:
classesLocations- classes locations relative to the current classpath root.
-
withDefaultProviderClasses
Exposes the default classes locationtarget/classesas an exploded providers.jar. -
withProviderLibsFrom
-
withStartupTimeout
- Specified by:
withStartupTimeoutin interfaceorg.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>- Overrides:
withStartupTimeoutin classorg.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
-
useTls
-
useTls
-
useTlsKeystore
-
useMutualTls
public SELF useMutualTls(String tlsTruststoreFilename, String tlsTruststorePassword, HttpsClientAuth httpsClientAuth) Think about usingwithTrustedCertificates(List)andwithHttpsClientAuth(HttpsClientAuth)instead. -
withTrustedCertificates
Configure the Keycloak Truststore to communicate through TLS.- Parameters:
tlsTrustedCertificateFilenames- List of pkcs12 (p12 or pfx file extensions), PEM files, or directories containing those files that will be used as a system truststore.- Returns:
- self
-
withHttpsClientAuth
Configures the server to require/request client authentication.- Parameters:
httpsClientAuth- The http-client-auth mode- Returns:
- self
-
withVerboseOutput
-
withFeaturesEnabled
-
withFeaturesDisabled
-
withDisabledCaching
-
withEnabledMetrics
-
withDebug
Enable remote debugging in Keycloak and expose it on a random port. -
withDebugFixedPort
Enable remote debugging in Keycloak and expose it on a fixed port.- Parameters:
hostPort- The port on the host machinesuspend- Control if Keycloak should wait until a debugger is attached
-
withBootstrapAdminDisabled
Disable default bootstrapping of the keycloak admin. Useful when realms are imported. -
withOptimizedFlag
Will add the "--optimized" flag to Keycloak startup command. It will ignore all build time options, that have been set. For example: KC_HTTPS_CLIENT_AUTH, KC_HTTPS_MANAGEMENT_CLIENT_AUTH -
getKeycloakAdminClient
public org.keycloak.admin.client.Keycloak getKeycloakAdminClient()Returns the keycloak admin. Note that this may not return a functioning admin client if the master realm including users were imported. -
disableLightweightAccessTokenForAdminCliClient
-
getProtocol
-
getAuthServerUrl
-
getMgmtServerUrl
-
getAdminUsername
-
getAdminPassword
-
getHttpPort
public int getHttpPort() -
getHttpsPort
public int getHttpsPort() -
getHttpMgmtPort
public int getHttpMgmtPort() -
getDebugPort
public int getDebugPort()Get the mapped port for remote debugging. Should only be used if debugging has been enabled.- Returns:
- the mapped port or
-1if debugging has not been configured - See Also:
-
getContextPath
-
getStartupTimeout
-
getKeycloakDefaultVersion
-