env var for admin password expected hashed

This commit is contained in:
Benjamin Gamard 2018-01-01 17:14:12 +01:00
parent 0903c03a29
commit 66d331ddb8
2 changed files with 21 additions and 1 deletions

View File

@ -148,6 +148,26 @@ public class UserDao {
return user; 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. * Gets a user by its ID.
* *

View File

@ -79,7 +79,7 @@ public class AppContext {
User adminUser = userDao.getById("admin"); User adminUser = userDao.getById("admin");
if (Constants.DEFAULT_ADMIN_PASSWORD.equals(adminUser.getPassword())) { if (Constants.DEFAULT_ADMIN_PASSWORD.equals(adminUser.getPassword())) {
adminUser.setPassword(envAdminPassword); adminUser.setPassword(envAdminPassword);
userDao.updatePassword(adminUser, null); userDao.updateHashedPassword(adminUser);
} }
} }
} }