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
FieldsModifier and TypeFieldDescriptionstatic final StringThe realm's client for applications: public, and its tokens include Cognos's client in their audience, which Cognos requires.static final org.testcontainers.utility.DockerImageNameThe Keycloak image.static final intKeycloak's HTTP port inside the container.static final StringOverrides the Keycloak image, e.g.static final StringThe container's name on its Docker network.static final StringThe realmcognos-serverbuilds from its test users.Fields 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
ConstructorsConstructorDescriptionKeycloak on the default image (orKEYCLOAK_IMAGE), in development mode.KeycloakContainer(org.testcontainers.utility.DockerImageName image) Keycloak onimage. -
Method Summary
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, withWorkingDirectoryMethods 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
-
DEFAULT_IMAGE
public static final org.testcontainers.utility.DockerImageName DEFAULT_IMAGEThe Keycloak image. -
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_PORTKeycloak's HTTP port inside the container.- See Also:
-
NETWORK_ALIAS
-
REALM
-
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 (orKEYCLOAK_IMAGE), in development mode. -
KeycloakContainer
public KeycloakContainer(org.testcontainers.utility.DockerImageName image) Keycloak onimage.- Parameters:
image- a Keycloak image, version 25 or later
-
-
Method Details
-
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
Keycloak as seen from the host, e.g.http://localhost:54321. Its admin console logs on asadmin/admin.- Returns:
- the URL, without a trailing slash
-
idToken
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 namepassword- the password- Returns:
- the ID token (a JWT)
- Throws:
IllegalStateException- if Keycloak refuses the logon
-