Отключить пароль в выводе журнала отладки для OpenFeign веснойJAVA

Программисты JAVA общаются здесь
Anonymous
Отключить пароль в выводе журнала отладки для OpenFeign весной

Сообщение Anonymous »

У меня есть очень стандартная /базовая настройка FAINER Spring, чтобы сделать запросы в API REST.
Все работает так, как и ожидалось. < /p>
@EnableConfigurationProperties
public class FeignClientConfiguration {

@Bean
@ConfigurationProperties("myapp.gateways.xapi.auth.parameters")
public Map authParameters() {
return new HashMap();
}

@Bean
public RequestInterceptor authInterceptor(final AuthGateway authGateway,
final @Qualifier("AuthParameters") Map authParameters) {
return new AuthInterceptor(authGateway, authParameters);
}
}
< /code>
myapp:
gateways:
xapi:
auth:
token-uri: ${TOKEN_URI}
parameters:
username: ${AUTH_USERNAME}
password: ${AUTH_PASSWORD}
api:
base-uri: ${BASE_URI}
< /code>
@FeignClient(
name = "ApiGateway",
url = "${myapp.gateways.xapi.api.base-uri}",
configuration = FeignClientConfiguration.class
)
public interface ApiGateway {
@PostMapping("/some/path")
Result something(@RequestBody MyBody myBody);
}
< /code>
My log level is set to DEBUG, and in the output I see the password:
DEBUG [http-nio-8085-exec-2] org.springframework.cloud.openfeign.support.SpringEncoder - Writing [{password=2uSxxxx9by, username=apiuser@xapi}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@70ed03e4] d4bdf27f-bb64-4535-9d57-f4697acbb3a2
< /code>
I've tried many suggestions as to how to not log this password.
DEBUG level should remain turned on for the rest of the app.
Does not work:
@Bean
public feign.Logger.Level feignLoggerLevel() {
return feign.Logger.Level.BASIC;
}
< /code>
Does not work, MaskingFeignLogger only comes into play after the password has already been printed
@Bean
public feign.Logger feignLogger() {
return new MaskingFeignLogger();
}

public class MaskingFeignLogger extends feign.Logger {
@Override
protected void log(String configKey, String format, Object... args) {
String message = String.format(format, args);
// Mask password field
message = message.replaceAll("\"password\"\\s*:\\s*\".*?\"", "\"password\":\"*****\"");
// Log the sanitized message
LoggerFactory.getLogger(configKey).debug(message);
}
}

< /code>
Does not work, also comes into play after password was logged:
@Bean
public RequestInterceptor sensitiveDataInterceptor() {
return new SensitiveDataInterceptor();
}

public class SensitiveDataInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate template) {
String body = template.requestBody().asString();
if (body != null) {
String sanitized = body.replaceAll("\"password\"\\s*:\\s*\".*?\"", "\"password\":\"*****\"");
template.body(sanitized);
}
}
}
< /code>
Just to be clear, I do not want to switch log level, but want DEBUG.
Any suggestion appreciated

Подробнее здесь: https://stackoverflow.com/questions/797 ... -in-spring

Вернуться в «JAVA»