Skip to content

Commit

Permalink
add global users support
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Dec 16, 2024
1 parent 16c54e3 commit 21c3b0c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion otoroshi/app/next/plugins/auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ class SimpleBasicAuth extends NgAccessValidator {

override def access(ctx: NgAccessContext)(implicit env: Env, ec: ExecutionContext): Future[NgAccess] = {
val config = ctx.cachedConfig(internalName)(SimpleBasicAuthConfig.format.reads).getOrElse(SimpleBasicAuthConfig())
val globalUsers = env.datastores.globalConfigDataStore.latest().plugins.config.select("simple_basic_auth_global_users").asOpt[Map[String, String]].getOrElse(Map.empty)
val authorization: String = ctx.request.headers.get("Authorization")
.filter(_.startsWith("Basic "))
.map(_.replace("Basic ", ""))
Expand All @@ -709,7 +710,7 @@ class SimpleBasicAuth extends NgAccessValidator {
if (authorization.contains(":") && parts.length > 1) {
val username = parts.head
val password = parts.tail.mkString(":")
config.users.get(username) match {
(config.users ++ globalUsers).get(username) match {
case Some(pwd) if password == pwd => NgAccess.NgAllowed.vfuture
case Some(pwd) if BCrypt.checkpw(password, pwd) => NgAccess.NgAllowed.vfuture
case _ => {
Expand Down

0 comments on commit 21c3b0c

Please sign in to comment.