Skip to content

Commit 193b15c

Browse files
committed
HHH-19738 mask out 'jakarta.persistence.jdbc.password'
1 parent 3fc398c commit 193b15c

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public final class Environment implements AvailableSettings {
145145
InputStream stream = ConfigHelper.getResourceAsStream( "/hibernate.properties" );
146146
try {
147147
GLOBAL_PROPERTIES.load(stream);
148-
LOG.propertiesLoaded( ConfigurationHelper.maskOut( GLOBAL_PROPERTIES, PASS ) );
148+
LOG.propertiesLoaded( ConfigurationHelper.maskOut( GLOBAL_PROPERTIES,
149+
PASS, JAKARTA_JDBC_PASSWORD, JPA_JDBC_PASSWORD ) );
149150
}
150151
catch (Exception e) {
151152
LOG.unableToLoadProperties();
@@ -165,8 +166,8 @@ public final class Environment implements AvailableSettings {
165166

166167
try {
167168
Properties systemProperties = System.getProperties();
168-
// Must be thread-safe in case an application changes System properties during Hibernate initialization.
169-
// See HHH-8383.
169+
// Must be thread-safe in case an application changes System properties during Hibernate initialization.
170+
// See HHH-8383.
170171
synchronized (systemProperties) {
171172
GLOBAL_PROPERTIES.putAll(systemProperties);
172173
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,38 @@ public static Map clone(Map<?,?> configurationValues) {
262262

263263

264264
/**
265-
* replace a property by a starred version
265+
* Replace a property by a starred version
266266
*
267267
* @param props properties to check
268268
* @param key property to mask
269269
*
270270
* @return cloned and masked properties
271271
*/
272272
public static Properties maskOut(Properties props, String key) {
273-
Properties clone = ( Properties ) props.clone();
273+
Properties clone = (Properties) props.clone();
274274
if ( clone.get( key ) != null ) {
275275
clone.setProperty( key, "****" );
276276
}
277277
return clone;
278278
}
279279

280-
281-
282-
280+
/**
281+
* Replace properties by starred version
282+
*
283+
* @param props properties to check
284+
* @param keys properties to mask
285+
*
286+
* @return cloned and masked properties
287+
*/
288+
public static Properties maskOut(Properties props, String... keys) {
289+
Properties clone = (Properties) props.clone();
290+
for ( String key : keys ) {
291+
if ( clone.get( key ) != null ) {
292+
clone.setProperty( key, "****" );
293+
}
294+
}
295+
return clone;
296+
}
283297

284298
/**
285299
* Extract a property value by name from the given properties object.

0 commit comments

Comments
 (0)