记录 401 身份验证错误春季启动的用户名/密码



我想记录给定的经过身份验证的Web服务的用户名和密码。

我的WebSecurityConfigurerAdapter配置如下:

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/webservice/path").fullyAuthenticated().and().
        httpBasic().and().
        csrf().disable();
    }

我想要的是获取http请求并记录用户名和密码,如本例所示

所以我想要的是如何在 Spring 启动中获取我的 Web 服务的 HTTP 请求并记录凭据,无论用户和 pass 是否正确。

考虑在应用程序中添加 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
              }
      }
   }
}

最新更新