uk.gov.nationalarchives.tdr.keycloak.TdrKeycloakDeployment.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tdr-auth-utils_2.13 Show documentation
Show all versions of tdr-auth-utils_2.13 Show documentation
Helper classes related to Keycloak and authentication for the Transfer Digital Records service
package uk.gov.nationalarchives.tdr.keycloak
import org.keycloak.adapters.{HttpClientBuilder, KeycloakDeployment}
import org.keycloak.adapters.rotation.JWKPublicKeyLocator
import org.keycloak.representations.adapters.config.AdapterConfig
class TdrKeycloakDeployment extends KeycloakDeployment {
}
object TdrKeycloakDeployment {
def apply(authServer: String, realm: String, ttlSeconds: Int): TdrKeycloakDeployment = {
val keycloakDeployment = new TdrKeycloakDeployment()
keycloakDeployment.setClient(new HttpClientBuilder().build())
keycloakDeployment.setPublicKeyCacheTtl(ttlSeconds)
val adaptorConfig = new AdapterConfig()
adaptorConfig.setAuthServerUrl(authServer)
keycloakDeployment.setAuthServerBaseUrl(adaptorConfig)
keycloakDeployment.setRealm(realm)
keycloakDeployment.setPublicKeyLocator(new JWKPublicKeyLocator)
keycloakDeployment
}
}