Skip to content

Commit 35eb83a

Browse files
committed
Merge branch 'develop' into fb_git950
2 parents 1ce3db1 + 522ebc1 commit 35eb83a

11 files changed

Lines changed: 355 additions & 74 deletions

File tree

api/src/org/labkey/api/admin/AdminUrls.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public interface AdminUrls extends UrlProvider
6868
ActionURL getCspReportToURL();
6969

7070
ActionURL getAllowedExternalRedirectHostsURL();
71+
ActionURL getDeleteEncryptedContentURL();
7172

7273
/**
7374
* Simply adds an "Admin Console" link to nav trail if invoked in the root container. Otherwise, root is unchanged.

api/src/org/labkey/api/data/EncryptedPropertyStore.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ protected PropertyEncryption getPreferredPropertyEncryption()
9191
protected void appendWhereFilter(SQLFragment sql)
9292
{
9393
sql.append("NOT Encryption = ?");
94-
sql.add("None");
94+
sql.add(PropertyEncryption.None.toString());
95+
}
96+
97+
@Override
98+
public String getDescription()
99+
{
100+
return "Encrypted Property Sets";
95101
}
96102

97103
@Override
@@ -103,7 +109,7 @@ public void migrateEncryptedContent(String oldPassPhrase, String keySource, AESC
103109
TableInfo sets = PropertySchema.getInstance().getTableInfoPropertySets();
104110
TableInfo props = PropertySchema.getInstance().getTableInfoProperties();
105111

106-
new TableSelector(sets, Set.of("Set", "Category", "Encryption"), new SimpleFilter(FieldKey.fromParts("Encryption"), "None", CompareType.NEQ), null).forEachMap(map -> {
112+
new TableSelector(sets, Set.of("Set", "Category", "Encryption"), getEncryptedSetFilter(), null).forEachMap(map -> {
107113
int set = (int)map.get("Set");
108114
String encryption = (String)map.get("Encryption");
109115
String propertySetName = "\"" + map.get("Category") + "\" (Set = " + set + ")";
@@ -165,4 +171,34 @@ public void migrateEncryptedContent(String oldPassPhrase, String keySource, AESC
165171
clearCache();
166172
LOG.info(" Migration of encrypted property store values is complete");
167173
}
174+
175+
@Override
176+
public void deleteEncryptedContent()
177+
{
178+
LOG.info("Deleting all encrypted property sets");
179+
TableInfo sets = PropertySchema.getInstance().getTableInfoPropertySets();
180+
new TableSelector(
181+
sets,
182+
Set.of("Set", "Category", "Encryption"),
183+
getEncryptedSetFilter(),
184+
null
185+
).forEachMap(map -> {
186+
int set = (int)map.get("Set");
187+
PropertyManager.deleteSetDirectly(set);
188+
});
189+
}
190+
191+
public long getEncryptedPropertySetCount()
192+
{
193+
return new TableSelector(
194+
PropertySchema.getInstance().getTableInfoPropertySets(),
195+
getEncryptedSetFilter(),
196+
null
197+
).getRowCount();
198+
}
199+
200+
private Filter getEncryptedSetFilter()
201+
{
202+
return new SimpleFilter(FieldKey.fromParts("Encryption"), PropertyEncryption.None.toString(), CompareType.NEQ);
203+
}
168204
}

api/src/org/labkey/api/data/PropertyManager.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,33 @@ public static void deleteSetDirectly(User user, String objectId, String category
628628
new SqlExecutor(SCHEMA.getSchema()).execute(deleteSets);
629629
}
630630

631+
// Note: caller is responsible for clearing caches
632+
public static void deleteSetDirectly(int propertySet)
633+
{
634+
SqlExecutor executor = new SqlExecutor(SCHEMA.getSchema());
635+
var setSelectName = SCHEMA.getTableInfoProperties().getColumn("Set").getSelectIdentifier(); // Keyword in some dialects
636+
637+
try (Transaction t = SCHEMA.getSchema().getScope().ensureTransaction())
638+
{
639+
SQLFragment deleteProps = new SQLFragment("DELETE FROM ")
640+
.append(SCHEMA.getTableInfoProperties())
641+
.append(" WHERE ")
642+
.appendIdentifier(setSelectName)
643+
.append(" = ?")
644+
.add(propertySet);
645+
executor.execute(deleteProps);
646+
647+
SQLFragment deleteSet = new SQLFragment("DELETE FROM ")
648+
.append(SCHEMA.getTableInfoPropertySets())
649+
.append(" WHERE ")
650+
.appendIdentifier(setSelectName)
651+
.append(" = ?")
652+
.add(propertySet);
653+
executor.execute(deleteSet);
654+
t.commit();
655+
}
656+
}
657+
631658
public static class PropertyEntry
632659
{
633660
private int _userId;

api/src/org/labkey/api/reports/report/r/RserveScriptEngine.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,13 @@ private RConnection getConnection(RConnectionHolder rh, ScriptContext context)
569569
if (rconn.needLogin())
570570
{
571571
LOG.debug("Logging in to RServe as '" + _def.getUser() + "'");
572-
rconn.login(_def.getUser(), _def.getPassword());
572+
String password = _def.getPassword();
573+
if (password == null)
574+
{
575+
LOG.warn("RServe password is null! Login will likely fail.");
576+
password = "";
577+
}
578+
rconn.login(_def.getUser(), password);
573579
}
574580

575581
initEnv(rconn, context);

api/src/org/labkey/api/security/AuthenticationManager.java

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -327,41 +327,68 @@ public static void reorderConfigurations(User user, String name, int[] rowIds)
327327
}
328328
}
329329

330-
static final EncryptionMigrationHandler ENCRYPTION_MIGRATION_HANDLER = (oldPassPhrase, keySource, oldConfig) -> {
331-
Algorithm decryptAes = Encryption.getAES128(oldPassPhrase, keySource, oldConfig);
332-
_log.info(" Attempting to migrate encrypted properties in authentication configurations");
333-
TableInfo tinfo = CoreSchema.getInstance().getTableInfoAuthenticationConfigurations();
334-
Map<Integer, String> map = new TableSelector(tinfo, PageFlowUtil.set("RowId", "EncryptedProperties"),
330+
static final EncryptionMigrationHandler ENCRYPTION_MIGRATION_HANDLER = new EncryptionMigrationHandler()
331+
{
332+
@Override
333+
public String getDescription()
334+
{
335+
return "Encrypted Authentication Properties";
336+
}
337+
338+
@Override
339+
public void migrateEncryptedContent(String oldPassPhrase, String keySource, Encryption.AESConfig oldConfig)
340+
{
341+
Algorithm decryptAes = Encryption.getAES128(oldPassPhrase, keySource, oldConfig);
342+
_log.info(" Attempting to migrate encrypted properties in authentication configurations");
343+
TableInfo tinfo = CoreSchema.getInstance().getTableInfoAuthenticationConfigurations();
344+
Map<Integer, String> map = new TableSelector(tinfo, PageFlowUtil.set("RowId", "EncryptedProperties"),
335345
new SimpleFilter(FieldKey.fromParts("EncryptedProperties"), null, CompareType.NONBLANK), null).getValueMap(Integer.class);
336-
Map<String, String> saveMap = new HashMap<>();
346+
Map<String, String> saveMap = new HashMap<>();
337347

338-
map.forEach((key, value) -> {
339-
try
340-
{
341-
_log.info(" Migrating encrypted properties for configuration " + key);
348+
map.forEach((key, value) -> {
342349
try
343350
{
344-
String decryptedValue = decryptAes.decrypt(Base64.decodeBase64(value));
345-
String newEncryptedValue = Base64.encodeBase64String(AES.get().encrypt(decryptedValue));
346-
assert decryptedValue.equals(AES.get().decrypt(Base64.decodeBase64(newEncryptedValue)));
351+
_log.info(" Migrating encrypted properties for configuration {}", key);
352+
try
353+
{
354+
String decryptedValue = decryptAes.decrypt(Base64.decodeBase64(value));
355+
String newEncryptedValue = Base64.encodeBase64String(AES.get().encrypt(decryptedValue));
356+
assert decryptedValue.equals(AES.get().decrypt(Base64.decodeBase64(newEncryptedValue)));
347357

348-
if (newEncryptedValue != null)
358+
if (newEncryptedValue != null)
359+
{
360+
saveMap.put("EncryptedProperties", newEncryptedValue);
361+
Table.update(null, tinfo, saveMap, key);
362+
}
363+
}
364+
catch (DecryptionException e)
349365
{
350-
saveMap.put("EncryptedProperties", newEncryptedValue);
351-
Table.update(null, tinfo, saveMap, key);
366+
_log.info(" Failed to decrypt encrypted properties for configuration {}. It will be skipped.", key);
352367
}
353368
}
354-
catch (DecryptionException e)
369+
catch (Exception e)
355370
{
356-
_log.info(" Failed to decrypt encrypted properties for configuration " + key + ". It will be skipped.");
371+
_log.error("Exception while migrating configuration {}", key, e);
357372
}
358-
}
359-
catch (Exception e)
360-
{
361-
_log.error("Exception while migrating configuration " + key, e);
362-
}
363-
});
364-
_log.info(" Migration of encrypted properties in authentication configurations is complete");
373+
});
374+
_log.info(" Migration of encrypted properties in authentication configurations is complete");
375+
}
376+
377+
@Override
378+
public void deleteEncryptedContent()
379+
{
380+
_log.info("Clearing the core.AuthenticationConfigurations.EncryptedProperties column");
381+
TableInfo tinfo = CoreSchema.getInstance().getTableInfoAuthenticationConfigurations();
382+
new TableSelector(
383+
tinfo,
384+
PageFlowUtil.set("RowId"),
385+
new SimpleFilter(FieldKey.fromParts("EncryptedProperties"), null, CompareType.NONBLANK),
386+
null
387+
).forEach(
388+
Integer.class,
389+
rowId -> Table.update(null, tinfo, PageFlowUtil.map("EncryptedProperties", null), rowId)
390+
);
391+
}
365392
};
366393

367394
// Register a handler so encrypted properties are migrated whenever the encryption key changes

api/src/org/labkey/api/security/ConfigurationSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ public ConfigurationSettings(Map<String, Object> settings)
3636
}
3737
catch (Encryption.DecryptionException e)
3838
{
39-
LOG.warn("Encrypted properties can't be read", e);
39+
LOG.warn("Encrypted properties can't be decrypted", e);
4040
}
4141
}
4242
else
4343
{
44-
LOG.warn("Encrypted properties can't be read: encryption key has not been set in " + AppProps.getInstance().getWebappConfigurationFilename() + "!");
44+
LOG.warn("Encrypted properties can't be read: encryption key has not been set in {}!", AppProps.getInstance().getWebappConfigurationFilename());
4545
}
4646
}
4747

0 commit comments

Comments
 (0)