feat: BAC-39 Authentication (#114)
Reviewed-on: #114 Co-authored-by: Janis <janis.e.20@gmx.de> Co-committed-by: Janis <janis.e.20@gmx.de>
This commit is contained in:
@@ -3,14 +3,16 @@ package logic.user.impl
|
||||
import com.typesafe.config.Config
|
||||
import logic.user.UserManager
|
||||
import model.users.User
|
||||
import services.OpenIDUserInfo
|
||||
import util.UserHash
|
||||
|
||||
import javax.inject.{Inject, Singleton}
|
||||
import scala.collection.mutable
|
||||
|
||||
@Singleton
|
||||
class StubUserManager @Inject()(val config: Config) extends UserManager {
|
||||
class StubUserManager @Inject()(config: Config) extends UserManager {
|
||||
|
||||
private val user: Map[String, User] = Map(
|
||||
private val user: mutable.Map[String, User] = mutable.Map(
|
||||
"Janis" -> User(
|
||||
internalId = 1L,
|
||||
id = java.util.UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
|
||||
@@ -19,8 +21,8 @@ class StubUserManager @Inject()(val config: Config) extends UserManager {
|
||||
),
|
||||
"Leon" -> User(
|
||||
internalId = 2L,
|
||||
id = java.util.UUID.fromString("223e4567-e89b-12d3-a456-426614174000"),
|
||||
name = "Leon",
|
||||
id = java.util.UUID.randomUUID(),
|
||||
name = "Jakob",
|
||||
passwordHash = UserHash.hashPW("password123")
|
||||
),
|
||||
"Jakob" -> User(
|
||||
@@ -32,7 +34,26 @@ class StubUserManager @Inject()(val config: Config) extends UserManager {
|
||||
)
|
||||
|
||||
override def addUser(name: String, password: String): Boolean = {
|
||||
throw new NotImplementedError("StubUserManager.addUser is not implemented")
|
||||
val newUser = User(
|
||||
internalId = user.size.toLong + 1,
|
||||
id = java.util.UUID.randomUUID(),
|
||||
name = name,
|
||||
passwordHash = UserHash.hashPW(password)
|
||||
)
|
||||
user(name) = newUser
|
||||
true
|
||||
}
|
||||
|
||||
override def addOpenIDUser(name: String, userInfo: OpenIDUserInfo): Boolean = {
|
||||
// For stub implementation, just add a user without password
|
||||
val newUser = User(
|
||||
internalId = user.size.toLong + 1,
|
||||
id = java.util.UUID.randomUUID(),
|
||||
name = name,
|
||||
passwordHash = "" // No password for OpenID users
|
||||
)
|
||||
user(name) = newUser
|
||||
true
|
||||
}
|
||||
|
||||
override def authenticate(name: String, password: String): Option[User] = {
|
||||
@@ -42,6 +63,13 @@ class StubUserManager @Inject()(val config: Config) extends UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
override def authenticateOpenID(provider: String, providerId: String): Option[User] = {
|
||||
user.values.find { u =>
|
||||
// In a real implementation, this would check stored OpenID provider info
|
||||
u.name.startsWith(s"${provider}_") && u.name.contains(providerId)
|
||||
}
|
||||
}
|
||||
|
||||
override def userExists(name: String): Option[User] = {
|
||||
user.get(name)
|
||||
}
|
||||
@@ -51,7 +79,6 @@ class StubUserManager @Inject()(val config: Config) extends UserManager {
|
||||
}
|
||||
|
||||
override def removeUser(name: String): Boolean = {
|
||||
throw new NotImplementedError("StubUserManager.removeUser is not implemented")
|
||||
user.remove(name).isDefined
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user