From 66d331ddb8b2bd657e1b2c63ac056ef1d3af73f2 Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Mon, 1 Jan 2018 17:14:12 +0100 Subject: [PATCH] env var for admin password expected hashed --- .../sismics/docs/core/dao/jpa/UserDao.java | 20 +++++++++++++++++++ .../docs/core/model/context/AppContext.java | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java index 87166a59..974a6afe 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java +++ b/docs-core/src/main/java/com/sismics/docs/core/dao/jpa/UserDao.java @@ -148,6 +148,26 @@ public class UserDao { return user; } + /** + * Update the hashed password silently. + * + * @param user User to update + * @return Updated user + */ + public User updateHashedPassword(User user) { + EntityManager em = ThreadLocalContext.get().getEntityManager(); + + // Get the user + Query q = em.createQuery("select u from User u where u.id = :id and u.deleteDate is null"); + q.setParameter("id", user.getId()); + User userFromDb = (User) q.getSingleResult(); + + // Update the user + userFromDb.setPassword(user.getPassword()); + + return user; + } + /** * Gets a user by its ID. * diff --git a/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java b/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java index ab3f536d..d20f4f34 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java +++ b/docs-core/src/main/java/com/sismics/docs/core/model/context/AppContext.java @@ -79,7 +79,7 @@ public class AppContext { User adminUser = userDao.getById("admin"); if (Constants.DEFAULT_ADMIN_PASSWORD.equals(adminUser.getPassword())) { adminUser.setPassword(envAdminPassword); - userDao.updatePassword(adminUser, null); + userDao.updateHashedPassword(adminUser); } } }