Class KeycloakContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<KeycloakContainer>
io.skipcheck.tm1.testcontainers.KeycloakContainer
All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<KeycloakContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class KeycloakContainer extends org.testcontainers.containers.GenericContainer<KeycloakContainer>
Keycloak in Docker, as the OpenID Connect provider for a CognosContainer's OIDC namespace (CognosContainer.withKeycloak(KeycloakContainer)). Cognos builds a realm in it from its test users when it starts.

Its issuer is its address on the shared Docker network, http://keycloak:8080, whichever way it's reached, so Cognos accepts tokens that tests get through the host-side port (idToken(String, String)). The interactive (browser) logon would need a browser that reaches that network address, so it isn't wrapped here.

  • 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
    The realm's client for applications: public, and its tokens include Cognos's client in their audience, which Cognos requires.
    static final org.testcontainers.utility.DockerImageName
    The Keycloak image.
    static final int
    Keycloak's HTTP port inside the container.
    static final String
    Overrides the Keycloak image, e.g.
    static final String
    The container's name on its Docker network.
    static final String
    The realm cognos-server builds from its test users.

    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
    Keycloak on the default image (or KEYCLOAK_IMAGE), in development mode.
    KeycloakContainer(org.testcontainers.utility.DockerImageName image)
    Keycloak on image.
  • Method Summary

    Modifier and Type
    Method
    Description
    Keycloak as other containers on its network reach it: http://keycloak:8080.
    Keycloak as seen from the host, e.g.
    idToken(String user, String password)
    A user's ID token from the realm's "tm1-app" client, by the password grant: what an application that has logged a user on would hold.

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, configure, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, 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, stop, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectory

    Methods inherited from class 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

    • DEFAULT_IMAGE

      public static final org.testcontainers.utility.DockerImageName DEFAULT_IMAGE
      The Keycloak image.
    • IMAGE

      public static final String IMAGE
      Overrides the Keycloak image, e.g. another version. Read as a system property, then an environment variable.
      See Also:
    • HTTP_PORT

      public static final int HTTP_PORT
      Keycloak's HTTP port inside the container.
      See Also:
    • NETWORK_ALIAS

      public static final String NETWORK_ALIAS
      The container's name on its Docker network.
      See Also:
    • REALM

      public static final String REALM
      The realm cognos-server builds from its test users.
      See Also:
    • APP_CLIENT

      public static final String APP_CLIENT
      The realm's client for applications: public, and its tokens include Cognos's client in their audience, which Cognos requires.
      See Also:
  • Constructor Details

    • KeycloakContainer

      public KeycloakContainer()
      Keycloak on the default image (or KEYCLOAK_IMAGE), in development mode.
    • KeycloakContainer

      public KeycloakContainer(org.testcontainers.utility.DockerImageName image)
      Keycloak on image.
      Parameters:
      image - a Keycloak image, version 25 or later
  • Method Details

    • getNetworkUrl

      public String getNetworkUrl()
      Keycloak as other containers on its network reach it: http://keycloak:8080. Also its issuer's base.
      Returns:
      the in-network URL, without a trailing slash
    • getUrl

      public String getUrl()
      Keycloak as seen from the host, e.g. http://localhost:54321. Its admin console logs on as admin / admin.
      Returns:
      the URL, without a trailing slash
    • idToken

      public String idToken(String user, String password)
      A user's ID token from the realm's "tm1-app" client, by the password grant: what an application that has logged a user on would hold. Cognos logs that user on with it (CognosContainer.passport(String)).
      Parameters:
      user - a test user's name
      password - the password
      Returns:
      the ID token (a JWT)
      Throws:
      IllegalStateException - if Keycloak refuses the logon