Class KeycloakContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<KeycloakContainer>
org.apache.polaris.test.keycloak.KeycloakContainer
All Implemented Interfaces:
AutoCloseable, KeycloakAccess, 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> implements KeycloakAccess
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    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

    Fields inherited from interface org.apache.polaris.test.keycloak.KeycloakAccess

    PRINCIPAL_NAME_CLAIM
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Assigns a role to a user in Keycloak.
    void
    createRole(String roleName)
    Creates a new role in Keycloak with the specified name.
    void
    createServiceAccount(String clientId, String clientSecret)
    Creates a new service account in Keycloak with the specified client ID and client secret.
    void
    createUser(String name, String password)
    Creates a new user in Keycloak.
    void
    Deletes a role in Keycloak with the specified name.
    void
    Deletes a service account in Keycloak with the specified client ID.
    void
    Deletes a user in Keycloak with the specified name.
    Returns the URL of the Keycloak issuer.
    Obtains an access token from the Keycloak server.
    Returns the URL of the Keycloak token endpoint.
    void
     
    void
     

    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, 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 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.apache.polaris.test.keycloak.KeycloakAccess

    getTokenPath

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Constructor Details

    • KeycloakContainer

      public KeycloakContainer()
  • Method Details

    • start

      public void start()
      Specified by:
      start in interface org.testcontainers.lifecycle.Startable
      Overrides:
      start in class org.testcontainers.containers.GenericContainer<KeycloakContainer>
    • stop

      public void stop()
      Specified by:
      stop in interface org.testcontainers.lifecycle.Startable
      Overrides:
      stop in class org.testcontainers.containers.GenericContainer<KeycloakContainer>
    • getIssuerUrl

      public URI getIssuerUrl()
      Description copied from interface: KeycloakAccess
      Returns the URL of the Keycloak issuer. This is typically https://<keycloak-server>/realms/<realm-name>.
      Specified by:
      getIssuerUrl in interface KeycloakAccess
    • getTokenEndpoint

      public URI getTokenEndpoint()
      Description copied from interface: KeycloakAccess
      Returns the URL of the Keycloak token endpoint. This is typically https://<keycloak-server>/realms/<realm-name>/protocol/openid-connect/token.
      Specified by:
      getTokenEndpoint in interface KeycloakAccess
    • createRole

      public void createRole(String roleName)
      Description copied from interface: KeycloakAccess
      Creates a new role in Keycloak with the specified name.
      Specified by:
      createRole in interface KeycloakAccess
    • createUser

      public void createUser(String name, String password)
      Description copied from interface: KeycloakAccess
      Creates a new user in Keycloak.
      Specified by:
      createUser in interface KeycloakAccess
    • assignRoleToUser

      public void assignRoleToUser(String role, String user)
      Description copied from interface: KeycloakAccess
      Assigns a role to a user in Keycloak. Both the role and the user must exist.
      Specified by:
      assignRoleToUser in interface KeycloakAccess
    • createServiceAccount

      public void createServiceAccount(String clientId, String clientSecret)
      Description copied from interface: KeycloakAccess
      Creates a new service account in Keycloak with the specified client ID and client secret.
      Specified by:
      createServiceAccount in interface KeycloakAccess
    • deleteRole

      public void deleteRole(String name)
      Description copied from interface: KeycloakAccess
      Deletes a role in Keycloak with the specified name.
      Specified by:
      deleteRole in interface KeycloakAccess
    • deleteUser

      public void deleteUser(String name)
      Description copied from interface: KeycloakAccess
      Deletes a user in Keycloak with the specified name.
      Specified by:
      deleteUser in interface KeycloakAccess
    • deleteServiceAccount

      public void deleteServiceAccount(String clientId)
      Description copied from interface: KeycloakAccess
      Deletes a service account in Keycloak with the specified client ID.
      Specified by:
      deleteServiceAccount in interface KeycloakAccess
    • getToken

      public String getToken(Map<String,String> params)
      Description copied from interface: KeycloakAccess
      Obtains an access token from the Keycloak server. The passed map becomes the POST request body and should contain the grant type and all required parameters.
      Specified by:
      getToken in interface KeycloakAccess