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
  • 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:25.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>>
    • withNightly

      public SELF withNightly()
    • 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

      public SELF useMutualTls(String tlsTruststoreFilename, String tlsTruststorePassword, HttpsClientAuth httpsClientAuth)
    • 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
    • withBootstrapAdminDisabled

      public SELF withBootstrapAdminDisabled()
      Disable default bootstrapping of the keycloak admin. Useful when realms are imported.
    • withOptimizedFlag

      public SELF 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

      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()