Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66edab8ffe | ||
| 9ca1813f06 | |||
|
|
0572af6ea2 | ||
| 9fa1e5e071 | |||
|
|
d34f0d16cc | ||
| 476db28821 | |||
|
|
18c347b6ad | ||
| 4aa8709eb5 | |||
|
|
3766241dad | ||
| 009b2b1ad9 |
25
CHANGELOG.md
25
CHANGELOG.md
@@ -363,3 +363,28 @@
|
|||||||
### Features
|
### Features
|
||||||
|
|
||||||
* Update Hibernate connection provider and database configuration ([71a549b](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/71a549b7f059e748f7691bb9a27e2861b61c6f6f))
|
* Update Hibernate connection provider and database configuration ([71a549b](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/71a549b7f059e748f7691bb9a27e2861b61c6f6f))
|
||||||
|
## (2026-01-20)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add HikariCP specific configuration to db.conf ([009b2b1](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/009b2b1ad9180f58a0b1434354f8a467b4e452ca))
|
||||||
|
## (2026-01-20)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add HikariCP specific configuration to db.conf ([4aa8709](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/4aa8709eb593b03254efc616b6b04c23b23ab6ab))
|
||||||
|
## (2026-01-20)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Enhance EntityManagerProvider to use Play configuration for database settings ([476db28](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/476db288216ed2c1013fe3ddb9b82472254e352b))
|
||||||
|
## (2026-01-20)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Disable default JPA and Hibernate modules and enhance EntityManagerProvider for HikariCP integration ([9fa1e5e](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/9fa1e5e07122aebd0391d47c3513013243a72a0f))
|
||||||
|
## (2026-01-20)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add logging for user management operations in HibernateUserManager ([9ca1813](https://git.janis-eccarius.de/KnockOutWhist/KnockOutWhist-Web/commit/9ca1813f06539cffeb573d0e00571e4f2d5144f1))
|
||||||
|
|||||||
@@ -1,14 +1,33 @@
|
|||||||
package di
|
package di
|
||||||
|
|
||||||
import com.google.inject.Provider
|
import com.google.inject.{Inject, Provider}
|
||||||
import com.google.inject.Inject
|
|
||||||
import jakarta.inject.Singleton
|
import jakarta.inject.Singleton
|
||||||
import jakarta.persistence.{EntityManager, EntityManagerFactory, Persistence}
|
import jakarta.persistence.{EntityManager, EntityManagerFactory, Persistence}
|
||||||
|
import play.api.Configuration
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class EntityManagerProvider @Inject()() extends Provider[EntityManager] {
|
class EntityManagerProvider @Inject()(config: Configuration) extends Provider[EntityManager] {
|
||||||
|
|
||||||
private val emf: EntityManagerFactory = Persistence.createEntityManagerFactory("defaultPersistenceUnit")
|
private val emf: EntityManagerFactory = {
|
||||||
|
val dbConfig = config.get[Configuration]("db.default")
|
||||||
|
val props = new java.util.HashMap[String, Object]()
|
||||||
|
|
||||||
|
// Map Play configuration to Jakarta Persistence properties
|
||||||
|
props.put("jakarta.persistence.jdbc.driver", dbConfig.get[String]("driver"))
|
||||||
|
props.put("jakarta.persistence.jdbc.url", dbConfig.get[String]("url"))
|
||||||
|
props.put("jakarta.persistence.jdbc.user", dbConfig.get[String]("username"))
|
||||||
|
props.put("jakarta.persistence.jdbc.password", dbConfig.get[String]("password"))
|
||||||
|
|
||||||
|
// Also pass HikariCP settings if present
|
||||||
|
dbConfig.getOptional[Configuration]("hikaricp").foreach { hikariConfig =>
|
||||||
|
hikariConfig.keys.foreach { key =>
|
||||||
|
val value = hikariConfig.underlying.getValue(key).unwrapped()
|
||||||
|
props.put(s"hibernate.hikari.$key", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Persistence.createEntityManagerFactory("defaultPersistenceUnit", props)
|
||||||
|
}
|
||||||
|
|
||||||
override def get(): EntityManager = {
|
override def get(): EntityManager = {
|
||||||
emf.createEntityManager()
|
emf.createEntityManager()
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import jakarta.inject.Inject
|
|||||||
import jakarta.persistence.EntityManager
|
import jakarta.persistence.EntityManager
|
||||||
import logic.user.UserManager
|
import logic.user.UserManager
|
||||||
import model.users.{User, UserEntity}
|
import model.users.{User, UserEntity}
|
||||||
|
import play.api.Logger
|
||||||
import services.OpenIDUserInfo
|
import services.OpenIDUserInfo
|
||||||
import util.UserHash
|
import util.UserHash
|
||||||
|
|
||||||
@@ -14,6 +15,8 @@ import scala.jdk.CollectionConverters.*
|
|||||||
@Singleton
|
@Singleton
|
||||||
class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends UserManager {
|
class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends UserManager {
|
||||||
|
|
||||||
|
private val logger = Logger(getClass.getName)
|
||||||
|
|
||||||
override def addUser(name: String, password: String): Boolean = {
|
override def addUser(name: String, password: String): Boolean = {
|
||||||
try {
|
try {
|
||||||
// Check if user already exists
|
// Check if user already exists
|
||||||
@@ -22,6 +25,7 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
.getResultList
|
.getResultList
|
||||||
|
|
||||||
if (!existing.isEmpty) {
|
if (!existing.isEmpty) {
|
||||||
|
logger.warn(s"User $name already exists")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,9 +39,13 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
|
|
||||||
em.persist(userEntity)
|
em.persist(userEntity)
|
||||||
em.flush()
|
em.flush()
|
||||||
|
|
||||||
true
|
true
|
||||||
} catch {
|
} catch {
|
||||||
case _: Exception => false
|
case e: Exception => {
|
||||||
|
logger.error(s"Error adding user $name", e)
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +57,7 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
.getResultList
|
.getResultList
|
||||||
|
|
||||||
if (!existing.isEmpty) {
|
if (!existing.isEmpty) {
|
||||||
|
logger.warn(s"User $name already exists")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +71,7 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
.getResultList
|
.getResultList
|
||||||
|
|
||||||
if (!existingOpenID.isEmpty) {
|
if (!existingOpenID.isEmpty) {
|
||||||
|
logger.warn(s"OpenID user ${userInfo.provider}_${userInfo.id} already exists")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +82,10 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
em.flush()
|
em.flush()
|
||||||
true
|
true
|
||||||
} catch {
|
} catch {
|
||||||
case _: Exception => false
|
case e: Exception => {
|
||||||
|
logger.error(s"Error adding OpenID user ${userInfo.provider}_${userInfo.id}", e)
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +106,10 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case _: Exception => None
|
case e: Exception => {
|
||||||
|
logger.error(s"Error authenticating user $name", e)
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +129,10 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
Some(users.get(0).toUser)
|
Some(users.get(0).toUser)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case _: Exception => None
|
case e: Exception => {
|
||||||
|
logger.error(s"Error authenticating OpenID user ${provider}_$providerId", e)
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +148,10 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
Some(users.get(0).toUser)
|
Some(users.get(0).toUser)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case _: Exception => None
|
case e: Exception => {
|
||||||
|
logger.error(s"Error checking if user $name exists", e)
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +159,10 @@ class HibernateUserManager @Inject()(em: EntityManager, config: Config) extends
|
|||||||
try {
|
try {
|
||||||
Option(em.find(classOf[UserEntity], id)).map(_.toUser)
|
Option(em.find(classOf[UserEntity], id)).map(_.toUser)
|
||||||
} catch {
|
} catch {
|
||||||
case _: Exception => None
|
case e: Exception => {
|
||||||
|
logger.error(s"Error checking if user with ID $id exists", e)
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,12 +9,6 @@
|
|||||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Database connection settings -->
|
|
||||||
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver"/>
|
|
||||||
<property name="jakarta.persistence.jdbc.url" value="${DATABASE_URL}"/>
|
|
||||||
<property name="jakarta.persistence.jdbc.user" value="${DB_USER}"/>
|
|
||||||
<property name="jakarta.persistence.jdbc.password" value="${DB_PASSWORD}"/>
|
|
||||||
|
|
||||||
<!-- Hibernate specific settings -->
|
<!-- Hibernate specific settings -->
|
||||||
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
|
||||||
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
<property name="hibernate.hbm2ddl.auto" value="update"/>
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
play.filters.disabled += play.filters.csrf.CSRFFilter
|
play.filters.disabled += play.filters.csrf.CSRFFilter
|
||||||
play.filters.disabled += play.filters.hosts.AllowedHostsFilter
|
play.filters.disabled += play.filters.hosts.AllowedHostsFilter
|
||||||
|
|
||||||
|
# Disable default JPA and Hibernate modules to use custom EntityManagerProvider
|
||||||
|
play.modules.disabled += "play.db.jpa.JPAModule"
|
||||||
|
|
||||||
play.http.secret.key="QCY?tAnfk?aZ?iwrNwnxIlR6CTf:G3gf:90Latabg@5241AB`R5W:1uDFN];Ik@n"
|
play.http.secret.key="QCY?tAnfk?aZ?iwrNwnxIlR6CTf:G3gf:90Latabg@5241AB`R5W:1uDFN];Ik@n"
|
||||||
play.http.secret.key=${?APPLICATION_SECRET}
|
play.http.secret.key=${?APPLICATION_SECRET}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
|
|
||||||
# Database configuration - PostgreSQL with environment variables
|
# Database configuration - PostgreSQL with environment variables
|
||||||
db.default.driver=org.postgresql.Driver
|
db.default.driver="org.postgresql.Driver"
|
||||||
db.default.jdbcUrl=${?DATABASE_URL}
|
db.default.url="jdbc:postgresql://localhost:5432/knockoutwhist"
|
||||||
|
db.default.url=${?DATABASE_URL}
|
||||||
|
db.default.username="kw_user"
|
||||||
db.default.username=${?DB_USER}
|
db.default.username=${?DB_USER}
|
||||||
|
db.default.password="postgres"
|
||||||
db.default.password=${?DB_PASSWORD}
|
db.default.password=${?DB_PASSWORD}
|
||||||
|
|
||||||
|
# HikariCP specific configuration
|
||||||
|
db.default.hikaricp.driverClassName="org.postgresql.Driver"
|
||||||
|
db.default.hikaricp.jdbcUrl="jdbc:postgresql://localhost:5432/knockoutwhist"
|
||||||
|
db.default.hikaricp.jdbcUrl=${?DATABASE_URL}
|
||||||
|
db.default.hikaricp.username="kw_user"
|
||||||
|
db.default.hikaricp.username=${?DB_USER}
|
||||||
|
db.default.hikaricp.password="postgres"
|
||||||
|
db.default.hikaricp.password=${?DB_PASSWORD}
|
||||||
|
|
||||||
# JPA/Hibernate configuration
|
# JPA/Hibernate configuration
|
||||||
jpa.default=defaultPersistenceUnit
|
jpa.default=defaultPersistenceUnit
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
MAJOR=4
|
MAJOR=4
|
||||||
MINOR=34
|
MINOR=39
|
||||||
PATCH=0
|
PATCH=0
|
||||||
|
|||||||
Reference in New Issue
Block a user