我想记录给定的经过身份验证的 Web 服务的用户名和密码。
我的 WebSecurityConfigurerAdapter
配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/webservice/path").fullyAuthenticated().and().
httpBasic().and().
csrf().disable();
}
我想要的是获取http请求并记录用户名和密码,如example
所以我想要的是如何在 Spring Boot 中获取 Web 服务的 http 请求并记录凭据,无论用户和通行证是否正确。
最佳答案
考虑在您的应用程序中添加 LoggingFilter。
@Bean
public FilterRegistrationBean loggingFilterRegistration() {
FilterRegistrationBean loggingBean = new FilterRegistrationBean();
loggingBean.setFilter(loggingFilter());
loggingBean.addUrlPatterns("/login");
loggingBean.setName("loggingFilter");
return registration;
}
@Bean
public Filter loggingFilter() {
return new GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
if("POST".equalsIgnoreCase(request.getMethod())){
// Implement Logging logic here
}
}
}
}
关于java - Spring Boot 401身份验证错误的日志用户名/密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43922736/