Class KeycloakContainer

java.lang.Object
org.testcontainers.containers.FailureDetectingExternalResource
org.testcontainers.containers.GenericContainer<KeycloakContainer>
dasniko.testcontainers.keycloak.ExtendableKeycloakContainer<KeycloakContainer>
org.apache.polaris.test.commons.keycloak.KeycloakContainer
All Implemented Interfaces:
AutoCloseable, KeycloakAccess, org.junit.rules.TestRule, 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 dasniko.testcontainers.keycloak.ExtendableKeycloakContainer<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 dasniko.testcontainers.keycloak.ExtendableKeycloakContainer

    ADMIN_CLI_CLIENT, LOG_WAIT_STRATEGY, MASTER_REALM

    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.commons.keycloak.KeycloakAccess

    PRINCIPAL_NAME_CLAIM, USER_PASSWORD
  • 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
    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.
    Returns the URL of the Keycloak token endpoint.
    void
     
    void
     

    Methods inherited from class dasniko.testcontainers.keycloak.ExtendableKeycloakContainer

    configure, createKeycloakExtensionDeployment, createKeycloakExtensionProvider, disableLightweightAccessTokenForAdminCliClient, getAdminPassword, getAdminUsername, getAuthServerUrl, getContextPath, getDebugPort, getHttpMgmtPort, getHttpPort, getHttpsPort, getKeycloakAdminClient, getKeycloakDefaultVersion, getMgmtServerUrl, getProtocol, getStartupTimeout, resolveExtensionClassLocation, useMutualTls, useTls, useTls, useTlsKeystore, waitingFor, withAdminPassword, withAdminUsername, withBootstrapAdminDisabled, withCommand, withCommand, withContextPath, withCustomCommand, withDebug, withDebugFixedPort, withDefaultProviderClasses, withDisabledCaching, withEnabledMetrics, withFeaturesDisabled, withFeaturesEnabled, withHttpsClientAuth, withNightly, withOptimizedFlag, withProductionMode, withProviderClassesFrom, withProviderLibsFrom, withRamPercentage, withRealmImportFile, withRealmImportFiles, withStartupTimeout, withTrustedCertificates, withVerboseOutput

    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, starting, 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.apache.polaris.test.commons.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. The role should not have the PRINCIPAL_ROLE: prefix.
      Specified by:
      createRole in interface KeycloakAccess
    • createUser

      public void createUser(String name)
      Description copied from interface: KeycloakAccess
      Creates a new user in Keycloak. The password is always "s3cr3t"
      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. The role should not have the PRINCIPAL_ROLE: prefix. 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. The role should not have the PRINCIPAL_ROLE: prefix.
      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