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 a9274e41..9777151e 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 @@ -68,6 +68,11 @@ public class Constants { */ public static final String GLOBAL_QUOTA_ENV = "DOCS_GLOBAL_QUOTA"; + /** + * Initial admin password environment variable. + */ + public static final String ADMIN_PASSWORD_INIT_ENV = "DOCS_ADMIN_PASSWORD_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 b869eee6..ab3f536d 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 @@ -3,10 +3,13 @@ package com.sismics.docs.core.model.context; import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; import com.sismics.docs.core.constant.ConfigType; +import com.sismics.docs.core.constant.Constants; import com.sismics.docs.core.dao.jpa.ConfigDao; +import com.sismics.docs.core.dao.jpa.UserDao; import com.sismics.docs.core.listener.async.*; import com.sismics.docs.core.listener.sync.DeadEventListener; import com.sismics.docs.core.model.jpa.Config; +import com.sismics.docs.core.model.jpa.User; import com.sismics.docs.core.service.IndexingService; import com.sismics.docs.core.util.PdfUtil; import com.sismics.util.EnvironmentUtil; @@ -66,7 +69,19 @@ public class AppContext { indexingService = new IndexingService(luceneStorageConfig != null ? luceneStorageConfig.getValue() : null); indexingService.startAsync(); + // Register fonts PdfUtil.registerFonts(); + + // Change the admin password if needed + String envAdminPassword = System.getenv(Constants.ADMIN_PASSWORD_INIT_ENV); + if (envAdminPassword != null) { + UserDao userDao = new UserDao(); + User adminUser = userDao.getById("admin"); + if (Constants.DEFAULT_ADMIN_PASSWORD.equals(adminUser.getPassword())) { + adminUser.setPassword(envAdminPassword); + userDao.updatePassword(adminUser, null); + } + } } /** diff --git a/docs-core/src/main/java/com/sismics/docs/core/util/PdfUtil.java b/docs-core/src/main/java/com/sismics/docs/core/util/PdfUtil.java index 71a4eaaf..1f3a79e6 100644 --- a/docs-core/src/main/java/com/sismics/docs/core/util/PdfUtil.java +++ b/docs-core/src/main/java/com/sismics/docs/core/util/PdfUtil.java @@ -320,6 +320,7 @@ public class PdfUtil { ByteStreams.copy(is, os); } FontFactory.register(file.toAbsolutePath().toString(), "LiberationMono-Regular"); + FontFactory.registerDirectories(); } catch (IOException e) { log.error("Error loading font", e); } diff --git a/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java b/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java index f54b843c..04587f31 100644 --- a/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java +++ b/docs-web-common/src/main/java/com/sismics/util/filter/RequestContextFilter.java @@ -1,32 +1,24 @@ package com.sismics.util.filter; -import java.io.IOException; -import java.text.MessageFormat; - -import javax.persistence.EntityManager; -import javax.persistence.EntityTransaction; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.HttpHeaders; - -import com.lowagie.text.FontFactory; -import org.apache.log4j.Level; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.RollingFileAppender; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.sismics.docs.core.model.context.AppContext; import com.sismics.docs.core.util.DirectoryUtil; import com.sismics.docs.core.util.TransactionUtil; import com.sismics.util.EnvironmentUtil; import com.sismics.util.context.ThreadLocalContext; import com.sismics.util.jpa.EMF; +import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.RollingFileAppender; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.EntityTransaction; +import javax.servlet.*; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.core.HttpHeaders; +import java.io.IOException; +import java.text.MessageFormat; /** * Filter used to process a couple things in the request context. @@ -73,9 +65,6 @@ public class RequestContextFilter implements Filter { AppContext.getInstance(); } }); - - // Register fonts - FontFactory.registerDirectories(); } @Override