From 425f96b6444336021fa46c2e20f29c42e652c1f9 Mon Sep 17 00:00:00 2001 From: Alberto Codutti Date: Fri, 17 Jan 2025 17:18:00 +0100 Subject: [PATCH] :bug: [Core] Fixed handling of null KapuaSession on prePersist and preUpdate operation in KapuaEntity Signed-off-by: Alberto Codutti --- .../org/eclipse/kapua/commons/model/AbstractKapuaEntity.java | 4 +++- .../kapua/commons/model/AbstractKapuaUpdatableEntity.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java index bb019afc3d3..cfce94f6c00 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaEntity.java @@ -165,7 +165,9 @@ public void setCreatedBy(KapuaId createdBy) { @PrePersist protected void prePersistsAction() { setId(new KapuaEid(IdGenerator.generate())); - setCreatedBy(KapuaSecurityUtils.getSession().getUserId()); + if (KapuaSecurityUtils.getSession() != null) { + setCreatedBy(KapuaSecurityUtils.getSession().getUserId()); + } setCreatedOn(new Date()); } } diff --git a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java index b24fc034de4..fd0febcdf9f 100644 --- a/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java +++ b/commons/src/main/java/org/eclipse/kapua/commons/model/AbstractKapuaUpdatableEntity.java @@ -212,7 +212,9 @@ protected void prePersistsAction() { */ @PreUpdate protected void preUpdateAction() { - setModifiedBy(KapuaSecurityUtils.getSession().getUserId()); + if (KapuaSecurityUtils.getSession() != null) { + setModifiedBy(KapuaSecurityUtils.getSession().getUserId()); + } setModifiedOn(new Date()); } }