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

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final org.testcontainers.containers.wait.strategy.WaitStrategy
     
    static final String
     

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a KeycloakContainer with default image and version tag
    Create a KeycloakContainer by passing the full docker image name
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
    createKeycloakExtensionDeployment(String deploymentLocation, String extensionName, String extensionClassFolder)
    Maps the provided extensionClassFolder as an exploded extension.jar to the deploymentLocation.
    void
    Maps the provided extensionClassFolder as an exploded providers.jar to the Keycloak providers folder.
    void
     
     
     
     
     
    int
    Get the mapped port for remote debugging.
    int
     
    int
     
    int
     
    org.keycloak.admin.client.Keycloak
     
     
     
     
     
    protected String
    resolveExtensionClassLocation(String extensionClassFolder)
     
    useMutualTls(String tlsTruststoreFilename, String tlsTruststorePassword, HttpsClientAuth httpsClientAuth)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Will be removed soon!
     
    useTls(String tlsCertificateFilename, String tlsCertificateKeyFilename)
     
    useTlsKeystore(String tlsKeystoreFilename, String tlsKeystorePassword)
     
    waitingFor(@NotNull org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy)
     
    withAdminPassword(String adminPassword)
     
    withAdminUsername(String adminUsername)
     
     
    withCommand(String... commandParts)
     
    withContextPath(String contextPath)
     
     
    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 location target/classes as an exploded providers.jar.
     
     
     
     
    Configures the server to require/request client authentication.
     
    withProviderClassesFrom(String... classesLocations)
    Exposes the given classes locations as an exploded providers.jar.
     
    withRamPercentage(int initialRamPercentage, int maxRamPercentage)
     
     
     
    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, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods 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, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Field Details

    • MASTER_REALM

      public static final String MASTER_REALM
      See Also:
    • ADMIN_CLI_CLIENT

      public static final String 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

      public ExtendableKeycloakContainer(String dockerImageName)
      Create a KeycloakContainer by passing the full docker image name
      Parameters:
      dockerImageName - Full docker image name, e.g. quay.io/keycloak/keycloak:26.0
  • Method Details

    • configure

      protected void configure()
      Overrides:
      configure in class org.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
    • withCommand

      public SELF withCommand(String cmd)
      Specified by:
      withCommand in interface org.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>
      Overrides:
      withCommand in class org.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
    • withCommand

      public SELF withCommand(String... commandParts)
      Specified by:
      withCommand in interface org.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>
      Overrides:
      withCommand in class org.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
    • waitingFor

      public SELF waitingFor(@NotNull @NotNull org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy)
      Specified by:
      waitingFor in interface org.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>
      Overrides:
      waitingFor in class org.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
    • withCustomCommand

      public SELF withCustomCommand(String cmd)
    • createKeycloakExtensionProvider

      public void createKeycloakExtensionProvider(String extensionClassFolder)
      Maps the provided extensionClassFolder as 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 provided extensionClassFolder as an exploded extension.jar to the deploymentLocation.
      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

      protected String resolveExtensionClassLocation(String extensionClassFolder)
    • withProductionMode

      public SELF withProductionMode()
    • withRealmImportFile

      public SELF withRealmImportFile(String importFile)
    • withRealmImportFiles

      public SELF withRealmImportFiles(String... files)
    • withAdminUsername

      public SELF withAdminUsername(String adminUsername)
    • withAdminPassword

      public SELF withAdminPassword(String adminPassword)
    • withContextPath

      public SELF withContextPath(String contextPath)
    • withRamPercentage

      public SELF withRamPercentage(int initialRamPercentage, int maxRamPercentage)
    • withProviderClassesFrom

      public SELF withProviderClassesFrom(String... classesLocations)
      Exposes the given classes locations as an exploded providers.jar.
      Parameters:
      classesLocations - classes locations relative to the current classpath root.
    • withDefaultProviderClasses

      public SELF withDefaultProviderClasses()
      Exposes the default classes location target/classes as an exploded providers.jar.
    • withProviderLibsFrom

      public SELF withProviderLibsFrom(List<File> libs)
    • withStartupTimeout

      public SELF withStartupTimeout(Duration startupTimeout)
      Specified by:
      withStartupTimeout in interface org.testcontainers.containers.Container<SELF extends ExtendableKeycloakContainer<SELF>>
      Overrides:
      withStartupTimeout in class org.testcontainers.containers.GenericContainer<SELF extends ExtendableKeycloakContainer<SELF>>
    • useTls

      public SELF useTls()
    • useTls

      public SELF useTls(String tlsCertificateFilename, String tlsCertificateKeyFilename)
    • useTlsKeystore

      public SELF useTlsKeystore(String tlsKeystoreFilename, String tlsKeystorePassword)
    • useMutualTls

      @Deprecated(forRemoval=true) public SELF useMutualTls(String tlsTruststoreFilename, String tlsTruststorePassword, HttpsClientAuth httpsClientAuth)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • withTrustedCertificates

      public SELF withTrustedCertificates(List<String> tlsTrustedCertificateFilenames)
      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

      public SELF withHttpsClientAuth(HttpsClientAuth httpsClientAuth)
      Configures the server to require/request client authentication.
      Parameters:
      httpsClientAuth - The http-client-auth mode
      Returns:
      self
    • withVerboseOutput

      public SELF withVerboseOutput()
    • withFeaturesEnabled

      public SELF withFeaturesEnabled(String... features)
    • withFeaturesDisabled

      public SELF withFeaturesDisabled(String... features)
    • withDisabledCaching

      public SELF withDisabledCaching()
    • withEnabledMetrics

      public SELF withEnabledMetrics()
    • withDebug

      public SELF withDebug()
      Enable remote debugging in Keycloak and expose it on a random port.
    • withDebugFixedPort

      public SELF withDebugFixedPort(int hostPort, boolean suspend)
      Enable remote debugging in Keycloak and expose it on a fixed port.
      Parameters:
      hostPort - The port on the host machine
      suspend - Control if Keycloak should wait until a debugger is attached
    • getKeycloakAdminClient

      public org.keycloak.admin.client.Keycloak getKeycloakAdminClient()
    • disableLightweightAccessTokenForAdminCliClient

      public void disableLightweightAccessTokenForAdminCliClient(String realm)
    • getProtocol

      public String getProtocol()
    • getAuthServerUrl

      public String getAuthServerUrl()
    • getMgmtServerUrl

      public String getMgmtServerUrl()
    • getAdminUsername

      public String getAdminUsername()
    • getAdminPassword

      public String 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 -1 if debugging has not been configured
      See Also:
    • getContextPath

      public String getContextPath()
    • getStartupTimeout

      public Duration getStartupTimeout()
    • getKeycloakDefaultVersion

      public String getKeycloakDefaultVersion()