Skip to content

Commit

Permalink
load login and gateway settings on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 12, 2024
1 parent d5e3416 commit 2709f87
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 57 deletions.
19 changes: 11 additions & 8 deletions core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,10 @@ public abstract class ConfigImpl extends ConfigBase implements ConfigPro {

protected Map<String, AIEngineFactory> aiEngineFactories;

private Map<String, ClassDefinition> cacheDefinitions;

private GatewayMap gatewayEntries;

protected Struct root;

/**
Expand Down Expand Up @@ -3919,10 +3923,6 @@ public Resource getDeployDirectory() {
* DeployHandler.deployExtension(this, ed, getLog("deploy"),true); }
*/

private Map<String, ClassDefinition> cacheDefinitions;

private GatewayMap gatewayEntries;

public void setCacheDefinitions(Map<String, ClassDefinition> caches) {
this.cacheDefinitions = caches;
}
Expand All @@ -3942,11 +3942,14 @@ public Resource getAntiSamyPolicy() {
return getConfigDir().getRealResource("security/antisamy-basic.xml");
}

public void setGatewayEntries(GatewayMap gatewayEntries) {
this.gatewayEntries = gatewayEntries;
}

public GatewayMap getGatewayEntries() {
if (gatewayEntries == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getGatewayEntries")) {
if (gatewayEntries == null) {
gatewayEntries = ConfigWebFactory.loadGatewayEL(this, root, getLog());
}
}
}
return gatewayEntries;
}

Expand Down
39 changes: 24 additions & 15 deletions core/src/main/java/lucee/runtime/config/ConfigServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public final class ConfigServerImpl extends ConfigImpl implements ConfigServer {
private ActionMonitorCollector actionMonitorCollector;

private boolean monitoringEnabled = false;
private int delay = 1;
private boolean captcha = false;
private boolean rememberMe = true;
private int delay = -1;
private Boolean captcha;
private Boolean rememberMe;
// private static ConfigServerImpl instance;

private String[] authKeys;
Expand Down Expand Up @@ -463,30 +463,39 @@ protected void setMonitoringEnabled(boolean monitoringEnabled) {
this.monitoringEnabled = monitoringEnabled;
}

protected void setLoginDelay(int delay) {
this.delay = delay;
}

protected void setLoginCaptcha(boolean captcha) {
this.captcha = captcha;
}

protected void setRememberMe(boolean rememberMe) {
this.rememberMe = rememberMe;
}

@Override
public int getLoginDelay() {
if (delay == -1) {
synchronized (SystemUtil.createToken("ConfigImpl", "getLoginDelay")) {
if (delay == -1) {
delay = Caster.toIntValue(ConfigWebFactory.getAttr(root, "loginDelay"), 1);
}
}
}
return delay;
}

@Override
public boolean getLoginCaptcha() {
if (captcha == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getLoginCaptcha")) {
if (captcha == null) {
captcha = Caster.toBooleanValue(ConfigWebFactory.getAttr(root, "loginCaptcha"), false);
}
}
}
return captcha;
}

@Override
public boolean getRememberMe() {
if (rememberMe == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getRememberMe")) {
if (rememberMe == null) {
rememberMe = Caster.toBooleanValue(ConfigWebFactory.getAttr(root, "loginRememberme"), true);
}
}
}
return rememberMe;
}

Expand Down
39 changes: 7 additions & 32 deletions core/src/main/java/lucee/runtime/config/ConfigWebFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,12 @@ synchronized static void load(ConfigServerImpl config, Struct root, boolean isRe
_loadListener(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded listeners");

_loadGatewayEL(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded gateways");

_loadExeLog(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded exe log");

_loadMonitors(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded monitors");

_loadLogin(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded login");

_loadStartupHook(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded startup hook");
}
Expand Down Expand Up @@ -1788,15 +1782,15 @@ else if (!IOUtil.toString(exeLog, SystemUtil.getCharset()).equals(val)) {
}
}
catch (IOException e) {
e.printStackTrace(config.getErrWriter());
log(config, log, e);
}

if (hasChanged) {
try {
if (config.getClassDirectory().exists()) config.getClassDirectory().remove(true);
}
catch (IOException e) {
e.printStackTrace(config.getErrWriter());
log(config, log, e);
}
}

Expand Down Expand Up @@ -2282,16 +2276,17 @@ private static String getMD5(Struct data, String cacheDef, String parentMD5) {
}
}

private static void _loadGatewayEL(ConfigServerImpl config, Struct root, Log log) {
public static GatewayMap loadGatewayEL(ConfigImpl config, Struct root, Log log) {
try {
_loadGateway(config, root, log);
return loadGateway(config, root, log);
}
catch (Exception e) {
log(config, log, e);
return new GatewayMap();
}
}

private static void _loadGateway(final ConfigServerImpl config, Struct root, Log log) {
public static GatewayMap loadGateway(final ConfigImpl config, Struct root, Log log) {
GatewayMap mapGateways = new GatewayMap();
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_GATEWAY);
GatewayEntry ge;
Expand Down Expand Up @@ -2329,13 +2324,13 @@ private static void _loadGateway(final ConfigServerImpl config, Struct root, Log
log(config, log, t);
}
}
config.setGatewayEntries(mapGateways);
}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log(config, log, t);
}
}
return mapGateways;
}

private static void setDatasource(ConfigImpl config, Map<String, DataSource> datasources, String datasourceName, ClassDefinition cd, String server, String databasename,
Expand Down Expand Up @@ -3494,26 +3489,6 @@ public static void log(Config config, Log log, Throwable e) {
}
}

private static void _loadLogin(ConfigServerImpl config, Struct root, Log log) {
try {
// server context
{
boolean captcha = Caster.toBooleanValue(getAttr(root, "loginCaptcha"), false);
boolean rememberme = Caster.toBooleanValue(getAttr(root, "loginRememberme"), true);

int delay = Caster.toIntValue(getAttr(root, "loginDelay"), 1);
ConfigServerImpl cs = config;
cs.setLoginDelay(delay);
cs.setLoginCaptcha(captcha);
cs.setRememberMe(rememberme);
}
}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log(config, log, t);
}
}

private static void _loadStartupHook(ConfigServerImpl config, Struct root, Log log) {
try {
Array children = ConfigWebUtil.getAsArray("startupHooks", root);
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="7.0.0.10-SNAPSHOT"/>
<property name="version" value="7.0.0.11-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>7.0.0.10-SNAPSHOT</version>
<version>7.0.0.11-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 2709f87

Please sign in to comment.