Skip to content

Commit 016e269

Browse files
committed
HHH-19738 mask out 'jakarta.persistence.jdbc.password'
1 parent 1deccba commit 016e269

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/Environment.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public final class Environment implements AvailableSettings {
144144
try (var stream = getResourceAsStream("/hibernate.properties")) {
145145
try {
146146
GLOBAL_PROPERTIES.load(stream);
147-
LOG.propertiesLoaded( maskOut( GLOBAL_PROPERTIES, PASS ) );
147+
LOG.propertiesLoaded( maskOut( GLOBAL_PROPERTIES,
148+
PASS, JAKARTA_JDBC_PASSWORD, JPA_JDBC_PASSWORD ) );
148149
}
149150
catch (Exception e) {
150151
LOG.unableToLoadProperties();

hibernate-core/src/main/java/org/hibernate/internal/util/config/ConfigurationHelper.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,21 +270,39 @@ else if ( configurationValues instanceof Properties properties ) {
270270
}
271271

272272
/**
273-
* replace a property by a starred version
273+
* Replace a property by a starred version
274274
*
275275
* @param props properties to check
276276
* @param key property to mask
277277
*
278278
* @return cloned and masked properties
279279
*/
280280
public static Properties maskOut(Properties props, String key) {
281-
final Properties clone = (Properties) props.clone();
281+
final var clone = (Properties) props.clone();
282282
if ( clone.get( key ) != null ) {
283283
clone.setProperty( key, "****" );
284284
}
285285
return clone;
286286
}
287287

288+
/**
289+
* Replace properties by starred version
290+
*
291+
* @param props properties to check
292+
* @param keys properties to mask
293+
*
294+
* @return cloned and masked properties
295+
*/
296+
public static Properties maskOut(Properties props, String... keys) {
297+
final var clone = (Properties) props.clone();
298+
for ( String key : keys ) {
299+
if ( clone.get( key ) != null ) {
300+
clone.setProperty( key, "****" );
301+
}
302+
}
303+
return clone;
304+
}
305+
288306
/**
289307
* Extract a property value by name from the given properties object.
290308
* <p>

0 commit comments

Comments
 (0)