1
1
/*******************************************************************************
2
- * Copyright (c) 2012, 2023 IBM Corporation and others.
2
+ * Copyright (c) 2012, 2025 IBM Corporation and others.
3
3
* All rights reserved. This program and the accompanying materials
4
4
* are made available under the terms of the Eclipse Public License 2.0
5
5
* which accompanies this distribution, and is available at
24
24
import java .util .List ;
25
25
import java .util .Map ;
26
26
import java .util .Properties ;
27
+ import java .util .StringJoiner ;
27
28
import java .util .concurrent .ExecutorService ;
28
29
import java .util .concurrent .locks .ReentrantReadWriteLock ;
29
30
import java .util .concurrent .locks .ReentrantReadWriteLock .ReadLock ;
@@ -237,14 +238,15 @@ private void loadConfig(Map<String, Object> props) {
237
238
*/
238
239
private void debugLTPAConfig () {
239
240
if (TraceComponent .isAnyTracingEnabled () && tc .isDebugEnabled ()) {
240
- Tr .debug (tc , "primaryKeyImportFile: " + primaryKeyImportFile );
241
- //Tr.debug(tc, "primaryKeyPassword: " + primaryKeyPassword);
242
- Tr .debug (tc , "keyTokenExpiration: " + keyTokenExpiration );
243
- Tr .debug (tc , "monitorInterval: " + monitorInterval );
244
- Tr .debug (tc , "authFilterRef: " + authFilterRef );
245
- Tr .debug (tc , "monitorValidationKeysDir: " + monitorValidationKeysDir );
246
- Tr .debug (tc , "updateTrigger: " + updateTrigger );
247
- Tr .debug (tc , "validationKeys: " + (validationKeys == null ? "Null" : maskKeysPasswords (validationKeys )));
241
+ StringJoiner sj = new StringJoiner (", " , "debugLTPAConfig[" , "]" );
242
+ sj .add ("primaryKeyImportFile: " + primaryKeyImportFile );
243
+ sj .add ("keyTokenExpiration: " + keyTokenExpiration );
244
+ sj .add ("monitorInterval: " + monitorInterval );
245
+ sj .add ("authFilterRef: " + authFilterRef );
246
+ sj .add ("monitorValidationKeysDir: " + monitorValidationKeysDir );
247
+ sj .add ("updateTrigger: " + updateTrigger );
248
+ sj .add ("validationKeys: " + (validationKeys == null ? "Null" : maskKeysPasswords (validationKeys )));
249
+ Tr .debug (tc , sj .toString ());
248
250
}
249
251
}
250
252
@@ -319,8 +321,15 @@ private List<Properties> getNonConfiguredValidationKeys() {
319
321
return validationKeysInDirectory ;
320
322
}
321
323
324
+ /*
325
+ * Use the canonical path when comparing primaryKeyImportFile to fullFileName because fullFileName is
326
+ * derived primaryKeyImportDir which is a canonical path. If we don't compare with a canonical path then the
327
+ * comparison fails on windows when '/' are used in server.xml instead of '\'.
328
+ */
329
+ String canonicalPrimaryKeyImportFile = getCanonicalPathWithDefault (primaryKeyImportFile , primaryKeyImportFile );
330
+
322
331
// Skip the primary LTPA keys file or validationKeys file configured in the valicationKeys element
323
- if (primaryKeyImportFile .equals (fullFileName ) || isConfiguredValidationKeys (fullFileName )) {
332
+ if (canonicalPrimaryKeyImportFile .equals (fullFileName ) || isConfiguredValidationKeys (fullFileName )) {
324
333
continue ;
325
334
}
326
335
@@ -339,6 +348,24 @@ private List<Properties> getNonConfiguredValidationKeys() {
339
348
return validationKeysInDirectory ;
340
349
}
341
350
351
+ /**
352
+ * @param defaultValue
353
+ * @param pathToResolve
354
+ * @return
355
+ */
356
+ private String getCanonicalPathWithDefault (String pathToResolve , String defaultValue ) {
357
+ String canonicalPrimaryKeyImportFile ;
358
+ try {
359
+ canonicalPrimaryKeyImportFile = new File (pathToResolve ).getCanonicalPath ();
360
+
361
+ } catch (IOException ioe ) {
362
+ Tr .debug (tc , "Could not resolve canonical path to " + pathToResolve +
363
+ ", returning default '" + defaultValue + "'. Failure info: " + ioe .getMessage ());
364
+ canonicalPrimaryKeyImportFile = defaultValue ;
365
+ }
366
+ return canonicalPrimaryKeyImportFile ;
367
+ }
368
+
342
369
/**
343
370
* @param fn
344
371
* @return
@@ -367,7 +394,6 @@ private void resolveActualPrimaryKeysFileLocation() {
367
394
368
395
if (monitorValidationKeysDir || isValidationKeysFileConfigured ) {
369
396
try {
370
- // primaryKeyImportFile has already been resolved when the server loads the config, this includes variable and .. being resolved.
371
397
// primaryKeyImportDir is required to be set to load any validation keys.
372
398
primaryKeyImportDir = new File (primaryKeyImportFile ).getCanonicalFile ().getParent () + File .separator ;
373
399
Tr .debug (tc , "primaryKeyImportDir: " + primaryKeyImportDir );
0 commit comments