org.http4k.contract.security.BasicAuthSecurity.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4k-contract Show documentation
Show all versions of http4k-contract Show documentation
http4k typesafe HTTP contracts and OpenApi support
package org.http4k.contract.security
import org.http4k.core.Credentials
import org.http4k.core.Filter
import org.http4k.filter.ServerFilters
import org.http4k.lens.RequestContextLens
class BasicAuthSecurity private constructor(override val filter: Filter, val name: String = "basicAuth") : Security {
/**
* Checks the presence of basic auth credentials. Filter returns 401 if auth fails.
*/
constructor(realm: String, credentials: Credentials, name: String = "basicAuth") : this(ServerFilters.BasicAuth(realm, credentials), name)
constructor(realm: String, credentials: (Credentials) -> Boolean) : this(ServerFilters.BasicAuth(realm, credentials))
companion object {
/**
* Population of a RequestContext with custom principal object
*/
operator fun invoke(realm: String, key: RequestContextLens, lookup: (Credentials) -> T?, name: String = "basicAuth") =
BasicAuthSecurity(ServerFilters.BasicAuth(realm, key, lookup), name)
}
}