Skip to content

Commit

Permalink
load antisami and samefieldasarray settings on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 15, 2024
1 parent 847f051 commit 9b5ea0d
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 189 deletions.
37 changes: 29 additions & 8 deletions core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.osgi.framework.Version;

import lucee.aprint;
import lucee.print;
import lucee.commons.date.TimeZoneConstants;
import lucee.commons.io.CharsetUtil;
import lucee.commons.io.FileUtil;
Expand Down Expand Up @@ -456,6 +455,13 @@ public abstract class ConfigImpl extends ConfigBase implements ConfigPro {
private GatewayMap gatewayEntries;

private AtomicBoolean insideLoggers = new AtomicBoolean(false);

private Resource deployDir;

private Resource antiSamyPolicy;
private Boolean cgiScopeReadonly;

private boolean newVersion;
protected Struct root;

/**
Expand Down Expand Up @@ -538,9 +544,10 @@ public void reloadTimeServerOffset() {
* @param configDir - config directory
* @param configFile - config file
*/
protected ConfigImpl(Resource configDir, Resource configFile) {
protected ConfigImpl(Resource configDir, Resource configFile, boolean newVersion) {
this.configDir = configDir;
this.configFile = configFile;
this.newVersion = newVersion;
}

@Override
Expand Down Expand Up @@ -2813,7 +2820,6 @@ protected void setTriggerComponentDataMember(boolean triggerComponentDataMember)

@Override
public Resource getClientScopeDir() {
print.e("!!!!!!!!!!!!!!!!!!!! getClientScopeDir !!!!!!!!!!!!!!!!");
if (clientScopeDir == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getClientScopeDir")) {
if (clientScopeDir == null) {
Expand Down Expand Up @@ -4095,6 +4101,11 @@ public ORMEngine getORMEngine(PageContext pc) throws PageException {
return engine;
}

@Override
public boolean hasORMEngine() {
return getORMEngineClassDefintion().equals(ConfigWebFactory.DUMMY_ORM_ENGINE);
}

@Override
public ClassDefinition<? extends ORMEngine> getORMEngineClassDefintion() {
if (cdORMEngine == null) {
Expand Down Expand Up @@ -5108,8 +5119,6 @@ public ConfigImpl resetQueueEnable() {
return this;
}

private Boolean cgiScopeReadonly;

@Override
public boolean getCGIScopeReadonly() {
if (cgiScopeReadonly == null) {
Expand Down Expand Up @@ -5137,8 +5146,6 @@ public ConfigImpl resetCGIScopeReadonly() {
return this;
}

private Resource deployDir;

@Override
public Resource getDeployDirectory() {
if (deployDir == null) {
Expand Down Expand Up @@ -5184,7 +5191,21 @@ public ClassDefinition getCacheDefinition(String className) {

@Override
public Resource getAntiSamyPolicy() {
return getConfigDir().getRealResource("security/antisamy-basic.xml");
if (antiSamyPolicy == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getAntiSamyPolicy")) {
if (antiSamyPolicy == null) {

Resource secDir = getConfigDir().getRealResource("security");
antiSamyPolicy = getConfigDir().getRealResource("antisamy-basic.xml");
if (!antiSamyPolicy.exists() || newVersion) {
if (!secDir.exists()) secDir.mkdirs();
ConfigWebFactory.createFileFromResourceEL("/resource/security/antisamy-basic.xml", antiSamyPolicy);
}

}
}
}
return antiSamyPolicy;
}

public GatewayMap getGatewayEntries() {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ public interface ConfigPro extends Config {

public ORMConfiguration getORMConfig();

public boolean hasORMEngine();

public ClassDefinition<? extends ORMEngine> getORMEngineClassDefintion();

public Resource getLibraryDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static ConfigServerImpl newInstance(CFMLEngineImpl engine, Map<String, CF
LogUtil.logGlobal(ThreadLocalPageContext.getConfig(), Log.LEVEL_INFO, ConfigServerFactory.class.getName(),
"has " + (hasConfigOld ? "" : "no ") + "xml server context config [" + configFileOld + "]");
}
ConfigServerImpl config = existing != null ? existing : new ConfigServerImpl(engine, initContextes, contextes, configDir, configFileNew, ui, essentialOnly);
ConfigServerImpl config = existing != null ? existing : new ConfigServerImpl(engine, initContextes, contextes, configDir, configFileNew, ui, essentialOnly, doNew);
ThreadLocalConfigServer.register(config);
// translate to new
if (!hasConfigNew) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/lucee/runtime/config/ConfigServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public final class ConfigServerImpl extends ConfigImpl implements ConfigServer {
* @throws FunctionLibException
*/
protected ConfigServerImpl(CFMLEngineImpl engine, Map<String, CFMLFactory> initContextes, Map<String, CFMLFactory> contextes, Resource configDir, Resource configFile,
UpdateInfo updateInfo, boolean essentialOnly) throws TagLibException, FunctionLibException {
super(configDir, configFile);
UpdateInfo updateInfo, boolean essentialOnly, boolean newVersion) throws TagLibException, FunctionLibException {
super(configDir, configFile, newVersion);
this.coreTLDs = TagLibFactory.loadFromSystem(id);
this.coreFLDs = FunctionLibFactory.loadFromSystem(id);

Expand Down
11 changes: 4 additions & 7 deletions core/src/main/java/lucee/runtime/config/ConfigWebFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public final class ConfigWebFactory extends ConfigFactory {
public static final boolean LOG = true;
private static final int DEFAULT_MAX_CONNECTION = 100;
public static final String DEFAULT_LOCATION = Constants.DEFAULT_UPDATE_URL.toExternalForm();
public static final ClassDefinition DUMMY_ORM_ENGINE = new ClassDefinitionImpl(DummyORMEngine.class);;

public static ConfigWebPro newInstanceSingle(CFMLEngine engine, CFMLFactoryImpl factory, ConfigServerImpl configServer, Resource configDirWeb, ServletConfig servletConfig,
ConfigWebImpl existingToUpdate) throws PageException {
Expand Down Expand Up @@ -1058,11 +1059,7 @@ public static void createContextFiles(Resource configDir, boolean doNew) throws
if (!compDir.exists()) compDir.mkdirs();

// remove old cacerts files, they are now only in the server context
Resource secDir = configDir.getRealResource("security");
Resource f = null;
if (!secDir.exists()) secDir.mkdirs();
f = secDir.getRealResource("antisamy-basic.xml");
if (!f.exists() || doNew) createFileFromResourceEL("/resource/security/antisamy-basic.xml", f);

// lucee-context
f = contextDir.getRealResource("lucee-context.lar");
Expand Down Expand Up @@ -3021,7 +3018,7 @@ public static ClassDefinition loadWS(ConfigImpl config, Struct root, Log log, Cl
}

public static ClassDefinition loadORMClass(ConfigImpl config, Struct root, Log log) {
ClassDefinition cdDefault = new ClassDefinitionImpl(DummyORMEngine.class);

try {
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_ORM);
Struct orm = ConfigWebUtil.getAsStruct("orm", root);
Expand All @@ -3038,15 +3035,15 @@ public static ClassDefinition loadORMClass(ConfigImpl config, Struct root, Log l
}

if (cd == null || !cd.hasClass()) {
cd = cdDefault;
cd = DUMMY_ORM_ENGINE;
}
return cd;
}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log(config, log, t);
}
return cdDefault;
return DUMMY_ORM_ENGINE;
}

public static ORMConfiguration loadORMConfig(ConfigImpl config, Struct root, Log log, ORMConfiguration defaultValue) {
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/lucee/runtime/config/ConfigWebImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2139,4 +2139,9 @@ public CFMLEngine getEngine() {
public boolean getDateCasterClassicStyle() {
return cs.getDateCasterClassicStyle();
}

@Override
public boolean hasORMEngine() {
return cs.hasORMEngine();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ public static Struct call(PageContext pc, boolean suppressFunctions, boolean onl

sct.setEL("invokeImplicitAccessor", Caster.toBoolean(ac.getTriggerComponentDataMember()));
sct.setEL("triggerDataMember", Caster.toBoolean(ac.getTriggerComponentDataMember()));
sct.setEL("sameformfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_FORM)));
sct.setEL("sameurlfieldsasarray", Caster.toBoolean(ac.getSameFieldAsArray(Scope.SCOPE_URL)));
sct.setEL("sameformfieldsasarray", Caster.toBoolean(((ApplicationContextSupport) ac).getSameFieldAsArray(pc, Scope.SCOPE_FORM)));
sct.setEL("sameurlfieldsasarray", Caster.toBoolean(((ApplicationContextSupport) ac).getSameFieldAsArray(pc, Scope.SCOPE_URL)));
sct.setEL("formUrlAsStruct", Caster.toBoolean(acs.getFormUrlAsStruct()));

Object ds = ac.getDefDataSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ private static Struct toStruct(Object obj) throws PageException {
String str = Caster.toString(obj);
int index;
Struct data = new StructImpl(Struct.TYPE_LINKED);
// boolean asArray = pc.getApplicationContext().getSameFieldAsArray(scope);
Key n;
String v;
Object existing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ private static LoggerAndSourceData addLogger(Collection.Key name, int level, Cla
}

// FUTURE add to interface
public abstract Resource getAntiSamyPolicyResource();
public abstract Resource getAntiSamyPolicyResource(PageContext pc);

public abstract void setAntiSamyPolicyResource(Resource res);

Expand Down Expand Up @@ -511,4 +511,6 @@ private static LoggerAndSourceData addLogger(Collection.Key name, int level, Cla
public abstract void setDebugOptions(int option);

public abstract void remDebugOptions(int option);

public abstract boolean getSameFieldAsArray(PageContext pc, int scope);
}
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,11 @@ public void setSameFieldAsArray(PageContext pc, int scope, boolean sameFieldAsAr

@Override
public boolean getSameFieldAsArray(int scope) {
return getSameFieldAsArray(null, scope);
}

@Override
public boolean getSameFieldAsArray(PageContext pc, int scope) {
Boolean b = sameFieldAsArrays.get(scope);
if (b == null) return false;
return b.booleanValue();
Expand Down Expand Up @@ -980,7 +985,7 @@ public void setCGIScopeReadonly(boolean cgiScopeReadonly) {
}

@Override
public Resource getAntiSamyPolicyResource() {
public Resource getAntiSamyPolicyResource(PageContext pc) {
if (antiSamyPolicy == null) return cp.getAntiSamyPolicy();
return antiSamyPolicy;
}
Expand Down
Loading

0 comments on commit 9b5ea0d

Please sign in to comment.