set the admin email by env var

This commit is contained in:
Benjamin Gamard 2018-03-27 18:58:08 +02:00
parent 4aca4ad495
commit 7b89bb449d
3 changed files with 22 additions and 1 deletions

View File

@ -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.
*/

View File

@ -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");
}
}
}
/**

View File

@ -113,7 +113,7 @@ public abstract class SecurityFilter implements Filter {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
public void init(FilterConfig filterConfig) {
// NOP
}