From 7b89bb449d948cb6a473586aea3009830554b3fc Mon Sep 17 00:00:00 2001 From: Benjamin Gamard Date: Tue, 27 Mar 2018 18:58:08 +0200 Subject: [PATCH] set the admin email by env var --- .../com/sismics/docs/core/constant/Constants.java | 10 ++++++++++ .../sismics/docs/core/model/context/AppContext.java | 11 +++++++++++ .../java/com/sismics/util/filter/SecurityFilter.java | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs-core/src/main/java/com/sismics/docs/core/constant/Constants.java b/docs-core/src/main/java/com/sismics/docs/core/constant/Constants.java index 83249389..08f7fd18 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/constant/Constants.java +++ b/docs-core/src/main/java/com/sismics/docs/core/constant/Constants.java @@ -20,6 +20,11 @@ public class Constants { */ public static final String DEFAULT_ADMIN_PASSWORD = "$2a$05$6Ny3TjrW3aVAL1or2SlcR.fhuDgPKp5jp.P9fBXwVNePgeLqb4i3C"; + /** + * Administrator's default email. + */ + public static final String DEFAULT_ADMIN_EMAIL = "admin@localhost"; + /** * RAM Lucene directory storage. */ @@ -73,6 +78,11 @@ public class Constants { */ public static final String ADMIN_PASSWORD_INIT_ENV = "DOCS_ADMIN_PASSWORD_INIT"; + /** + * Initial admin password environment variable. + */ + public static final String ADMIN_EMAIL_INIT_ENV = "DOCS_ADMIN_EMAIL_INIT"; + /** * Expiration time of the password recovery in hours. */ 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 5c92f0c1..3d8ea0c9 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 @@ -94,6 +94,17 @@ public class AppContext { userDao.updateHashedPassword(adminUser); } } + + // Change the admin email if needed + String envAdminEmail = System.getenv(Constants.ADMIN_EMAIL_INIT_ENV); + if (envAdminEmail != null) { + UserDao userDao = new UserDao(); + User adminUser = userDao.getById("admin"); + if (Constants.DEFAULT_ADMIN_EMAIL.equals(adminUser.getEmail())) { + adminUser.setEmail(envAdminEmail); + userDao.update(adminUser, "admin"); + } + } } /** diff --git a/docs-web-common/src/main/java/com/sismics/util/filter/SecurityFilter.java b/docs-web-common/src/main/java/com/sismics/util/filter/SecurityFilter.java index c4bb86a8..3d0b7901 100644 --- a/docs-web-common/src/main/java/com/sismics/util/filter/SecurityFilter.java +++ b/docs-web-common/src/main/java/com/sismics/util/filter/SecurityFilter.java @@ -113,7 +113,7 @@ public abstract class SecurityFilter implements Filter { } @Override - public void init(FilterConfig filterConfig) throws ServletException { + public void init(FilterConfig filterConfig) { // NOP }