initial admin password by env variable

This commit is contained in:
Benjamin Gamard 2017-12-11 10:17:08 +01:00
parent dc28ebfa50
commit 2ca5b04de2
4 changed files with 34 additions and 24 deletions

View File

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

View File

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

View File

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

View File

@ -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