-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPropertiesLog.java
49 lines (40 loc) · 1.91 KB
/
PropertiesLog.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package fr.insee.pogues.config;
import java.util.Arrays;
import java.util.Objects;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
public class PropertiesLog {
private static final Logger log = Logger.getLogger(PropertiesLog.class.getName());
private final Environment environment;
public PropertiesLog(Environment environment) {
Objects.requireNonNull(environment);
this.environment=environment;
log.info("===============================================================================================");
log.info(" Properties values ");
log.info("===============================================================================================");
((AbstractEnvironment) environment).getPropertySources().stream()
.map(propertySource -> {
if (propertySource instanceof EnumerablePropertySource){
return ((EnumerablePropertySource<?>)propertySource).getPropertyNames();
}else{
log.warning(propertySource+ " is not EnumerablePropertySource : listing impossible");
return new String[] {};
}
}
)
.flatMap(Arrays::stream)
.distinct()
.forEach(key->log.info(key+" = "+printValueWithoutPassword(key)));
}
private String printValueWithoutPassword(String key) {
if (StringUtils.containsAny(key, "password", "pwd", "keycloak.key", "jeton", "secret")) {
return "******";
}
return environment.getProperty(key);
}
}